package com.ecep.contract.vm;

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

import com.ecep.contract.vo.CloudRkVo;

import javafx.beans.property.SimpleBooleanProperty;
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 CloudRkViewModel extends IdentityViewModel<CloudRkVo> {
    /**
     * 云端Id
     */
    private SimpleStringProperty cloudId = new SimpleStringProperty();
    /**
     * 更新间隔天数
     */
    private SimpleIntegerProperty updateDays = new SimpleIntegerProperty();
    /**
     * 自动更新
     */
    private SimpleBooleanProperty autoUpdate = new SimpleBooleanProperty();
    /**
     * 相关方资信评价等级
     */
    private SimpleStringProperty rank = new SimpleStringProperty();
    /**
     * 相关方资信评价等级描述
     */
    private SimpleStringProperty rankDescription = new SimpleStringProperty();
    /**
     * 客户资信评价等级
     */
    private SimpleStringProperty customerGrade = new SimpleStringProperty();
    /**
     * 客户资信评价等级描述
     */
    private SimpleStringProperty customerDescription = new SimpleStringProperty();
    /**
     * 客户资信评价等级描述
     */
    private SimpleIntegerProperty customerScore = new SimpleIntegerProperty();
    /**
     * 供应商资信评价等级
     */
    private SimpleStringProperty vendorGrade = new SimpleStringProperty();
    /**
     * 供应商资信评价等级描述
     */
    private SimpleStringProperty vendorDescription = new SimpleStringProperty();
    /**
     * 供应商资信评价等级描述
     */
    private SimpleIntegerProperty vendorScore = new SimpleIntegerProperty();
    /**
     * 描述
     */
    private SimpleStringProperty description = new SimpleStringProperty();
    /**
     * 公司, Company
     */
    private SimpleObjectProperty<Integer> company = new SimpleObjectProperty<>();
    /**
     * 最后更新日期
     */
    private SimpleObjectProperty<LocalDateTime> latestUpdate = new SimpleObjectProperty<>();
    /**
     * 企业更新日期
     */
    private SimpleObjectProperty<LocalDateTime> cloudEntUpdate = new SimpleObjectProperty<>();
    /**
     * 黑名单更新日期
     */
    private SimpleObjectProperty<LocalDateTime> cloudBlackListUpdated = new SimpleObjectProperty<>();
    /**
     * 云端最新更新时间
     */
    private SimpleObjectProperty<LocalDateTime> cloudLatest = new SimpleObjectProperty<>();
    /**
     * Version
     */
    private SimpleIntegerProperty version = new SimpleIntegerProperty();

    /**
     * 从Vo创建ViewModel
     */
    public static CloudRkViewModel from(CloudRkVo v) {
        CloudRkViewModel vm = new CloudRkViewModel();
        vm.updateFrom(v);
        return vm;
    }

    @Override
    protected void updateFrom(CloudRkVo v) {
        super.updateFrom(v);
        cloudId.set(v.getCloudId());
        updateDays.set(v.getUpdateDays());
        autoUpdate.set(v.isAutoUpdate());
        description.set(v.getDescription());
        rank.set(v.getRank());
        rankDescription.set(v.getRankDescription());
        customerGrade.set(v.getCustomerGrade());
        customerDescription.set(v.getCustomerDescription());
        customerScore.set(v.getCustomerScore());
        vendorGrade.set(v.getVendorGrade());
        vendorDescription.set(v.getVendorDescription());
        vendorScore.set(v.getVendorScore());
        company.set(v.getCompanyId());
        latestUpdate.set(v.getLatestUpdate());
        cloudEntUpdate.set(v.getCloudEntUpdate());
        cloudBlackListUpdated.set(v.getCloudBlackListUpdated());
        cloudLatest.set(v.getCloudLatest());
        version.set(v.getVersion());
    }

    @Override
    public boolean copyTo(CloudRkVo v) {
        boolean result = super.copyTo(v);
        if (!Objects.equals(v.getCloudId(), cloudId.get())) {
            v.setCloudId(cloudId.get());
            result = true;
        }
        if (!Objects.equals(v.getUpdateDays(), updateDays.get())) {
            v.setUpdateDays(updateDays.get());
            result = true;
        }
        if (!Objects.equals(v.isAutoUpdate(), autoUpdate.get())) {
            v.setAutoUpdate(autoUpdate.get());
            result = true;
        }
        if (!Objects.equals(v.getDescription(), description.get())) {
            v.setDescription(description.get());
            result = true;
        }
        if (!Objects.equals(v.getRank(), rank.get())) {
            v.setRank(rank.get());
            result = true;
        }
        if (!Objects.equals(v.getRankDescription(), rankDescription.get())) {
            v.setRankDescription(rankDescription.get());
            result = true;
        }
        if (!Objects.equals(v.getCustomerGrade(), customerGrade.get())) {
            v.setCustomerGrade(customerGrade.get());
            result = true;
        }
        if (!Objects.equals(v.getCustomerDescription(), customerDescription.get())) {
            v.setCustomerDescription(customerDescription.get());
            result = true;
        }
        if (!Objects.equals(v.getCustomerScore(), customerScore.get())) {
            v.setCustomerScore(customerScore.get());
            result = true;
        }
        if (!Objects.equals(v.getVendorGrade(), vendorGrade.get())) {
            v.setVendorGrade(vendorGrade.get());
            result = true;
        }
        if (!Objects.equals(v.getVendorDescription(), vendorDescription.get())) {
            v.setVendorDescription(vendorDescription.get());
            result = true;
        }
        if (!Objects.equals(v.getVendorScore(), vendorScore.get())) {
            v.setVendorScore(vendorScore.get());
            result = true;
        }
        if (!Objects.equals(v.getCompanyId(), company.get())) {
            v.setCompanyId(company.get());
            result = true;
        }
        if (!Objects.equals(v.getLatestUpdate(), latestUpdate.get())) {
            v.setLatestUpdate(latestUpdate.get());
            result = true;
        }
        if (!Objects.equals(v.getCloudEntUpdate(), cloudEntUpdate.get())) {
            v.setCloudEntUpdate(cloudEntUpdate.get());
            result = true;
        }
        if (!Objects.equals(v.getCloudBlackListUpdated(), cloudBlackListUpdated.get())) {
            v.setCloudBlackListUpdated(cloudBlackListUpdated.get());
            result = true;
        }
        if (!Objects.equals(v.getCloudLatest(), cloudLatest.get())) {
            v.setCloudLatest(cloudLatest.get());
            result = true;
        }
        if (!Objects.equals(v.getVersion(), version.get())) {
            v.setVersion(version.get());
            result = true;
        }
        return result;
    }
}
