package com.ecep.contract.vm;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Objects;

import com.ecep.contract.vo.CloudTycVo;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class CloudTycInfoViewModel extends IdentityViewModel<CloudTycVo> {
    /**
     * 公司, Company
     */
    private SimpleObjectProperty<Integer> company = new SimpleObjectProperty<>();
    /**
     * 云端Id
     */
    private SimpleStringProperty cloudId = new SimpleStringProperty();
    /**
     * 天眼查得分
     */
    private SimpleIntegerProperty score = new SimpleIntegerProperty();
    private SimpleObjectProperty<LocalDateTime> cloudLatest = new SimpleObjectProperty<>();
    /**
     * 最后更新日期
     */
    private SimpleObjectProperty<LocalDateTime> latestUpdate = new SimpleObjectProperty<>();
    /**
     * Version
     */
    private SimpleIntegerProperty version = new SimpleIntegerProperty();

    @Override
    protected void updateFrom(CloudTycVo info) {
        super.updateFrom(info);
        score.set(info.getScore());
        cloudId.set(info.getCloudId());
        company.set(info.getCompanyId());
        if (info.getCloudLatest() != null) {
            cloudLatest.set(info.getCloudLatest());
        } else {
            cloudLatest.set(null);
        }
        latestUpdate.set(info.getLatestUpdate());
        version.set(info.getVersion());
    }

    @Override
    public boolean copyTo(CloudTycVo info) {
        boolean modified = super.copyTo(info);
        if (!Objects.equals(info.getCompanyId(), getCompany().get())) {
            info.setCompanyId(getCompany().get());
            modified = true;
        }
        if (!Objects.equals(info.getCloudId(), cloudId.get())) {
            info.setCloudId(cloudId.get());
            modified = true;
        }

        if (!Objects.equals(info.getScore(), getScore().get())) {
            info.setScore(getScore().get());
            modified = true;
        }

        if (!Objects.equals(info.getCloudLatest(), cloudLatest.get())) {
            info.setCloudLatest(cloudLatest.get());
            modified = true;
        }
        if (!Objects.equals(info.getLatestUpdate(), latestUpdate.get())) {
            info.setLatestUpdate(latestUpdate.get());
            modified = true;
        }
        if (!Objects.equals(info.getVersion(), version.get())) {
            info.setVersion(version.get());
            modified = true;
        }

        return modified;
    }

    public static CloudTycInfoViewModel from(CloudTycVo cc) {
        CloudTycInfoViewModel model = new CloudTycInfoViewModel();
        model.update(cc);
        return model;
    }
}
