package com.ecep.contract.vm;

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

import com.ecep.contract.vo.CompanyCustomerVo;

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 CompanyCustomerViewModel extends IdentityViewModel<CompanyCustomerVo> {
    private SimpleStringProperty state = new SimpleStringProperty();
    /**
     * 关联的企业,Company
     */
    private SimpleObjectProperty<Integer> company = new SimpleObjectProperty<>();

    private SimpleObjectProperty<Integer> catalog = new SimpleObjectProperty<>();
    /**
     * 发展日期
     */
    private SimpleObjectProperty<LocalDate> developDate = new SimpleObjectProperty<>();
    /**
     * 文件夹
     */
    private SimpleStringProperty path = new SimpleStringProperty();
    /**
     * 关联联系人,CompanyContact
     */
    private SimpleObjectProperty<Integer> contact = new SimpleObjectProperty<>();

    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleObjectProperty<LocalDateTime> created = new SimpleObjectProperty<>();
    private SimpleIntegerProperty version = new SimpleIntegerProperty();

    public static CompanyCustomerViewModel from(CompanyCustomerVo cc) {
        CompanyCustomerViewModel model = new CompanyCustomerViewModel();
        model.update(cc);
        return model;
    }

    public void updateFrom(CompanyCustomerVo c) {
        super.updateFrom(c);
        getCompany().set(c.getCompanyId());
        getCatalog().set(c.getCatalogId());
        getDevelopDate().set(c.getDevelopDate());
        getContact().set(c.getContactId());
        getPath().set(c.getPath());
        getDescription().set(c.getDescription());
        getCreated().set(c.getCreated());
        version.set(c.getVersion());
    }

    public boolean copyTo(CompanyCustomerVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(company.get(), v.getCompanyId())) {
            v.setCompanyId(company.get());
            modified = true;
        }
        if (!Objects.equals(catalog.get(), v.getCatalogId())) {
            v.setCatalogId(catalog.get());
            modified = true;
        }
        if (!Objects.equals(contact.get(), v.getContactId())) {
            v.setContactId(contact.get());
            modified = true;
        }
        if (!Objects.equals(developDate.get(), v.getDevelopDate())) {
            v.setDevelopDate(developDate.get());
            modified = true;
        }
        if (!Objects.equals(path.get(), v.getPath())) {
            v.setPath(path.get());
            modified = true;
        }
        if (!Objects.equals(description.get(), v.getDescription())) {
            v.setDescription(description.get());
            modified = true;
        }

        if (!Objects.equals(created.get(), v.getCreated())) {
            v.setCreated(created.get());
            modified = true;
        }

        return modified;
    }
}
