package com.ecep.contract.vm;

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

import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.CompanyVendorEntity;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.VendorCatalog;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class VendorEntityViewModel extends IdentityViewModel<CompanyVendorEntity> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty abbName = new SimpleStringProperty();
    private SimpleStringProperty code = new SimpleStringProperty();
    /**
     * 分组
     */
    private SimpleObjectProperty<VendorCatalog> catalog = new SimpleObjectProperty<>();
    /**
     * 关联的企业
     */
    private SimpleObjectProperty<CompanyVendor> vendor = new SimpleObjectProperty<>();
    /**
     * 发展日期
     */
    private SimpleObjectProperty<LocalDate> developDate = new SimpleObjectProperty<>();
    private SimpleObjectProperty<Employee> creator = new SimpleObjectProperty<>();
    private SimpleObjectProperty<Employee> modifier = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> modifyDate = new SimpleObjectProperty<>();
    /**
     * 从U8系统同步时间
     */
    private SimpleObjectProperty<LocalDate> updatedDate = new SimpleObjectProperty<>();



    public static VendorEntityViewModel from(CompanyVendorEntity cc) {
        VendorEntityViewModel model = new VendorEntityViewModel();
        model.update(cc);
        return model;
    }

    @Override
    protected void updateFrom(CompanyVendorEntity v) {
        super.updateFrom(v);
        getName().set(v.getName());
        getAbbName().set(v.getAbbName());
        getCode().set(v.getCode());
        getCatalog().set(v.getCatalog());
        getVendor().set(v.getVendor());
        getDevelopDate().set(v.getDevelopDate());
        getCreator().set(v.getCreator());
        getModifier().set(v.getModifier());
        getModifyDate().set(v.getModifyDate());
        getUpdatedDate().set(v.getUpdatedDate());
    }

    @Override
    public boolean copyTo(CompanyVendorEntity v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(name.get(), v.getName())) {
            v.setName(name.get());
            modified = true;
        }
        if (!Objects.equals(abbName.get(), v.getAbbName())) {
            v.setAbbName(abbName.get());
            modified = true;
        }
        if (!Objects.equals(code.get(), v.getCode())) {
            v.setCode(code.get());
            modified = true;
        }
        if (!Objects.equals(catalog.get(), v.getCatalog())) {
            v.setCatalog(catalog.get());
            modified = true;
        }
        if (!Objects.equals(vendor.get(), v.getVendor())) {
            v.setVendor(vendor.get());
            modified = true;
        }
        if (!Objects.equals(developDate.get(), v.getDevelopDate())) {
            v.setDevelopDate(developDate.get());
            modified = true;
        }
        if (!Objects.equals(creator.get(), v.getCreator())) {
            v.setCreator(creator.get());
            modified = true;
        }
        if (!Objects.equals(modifier.get(), v.getModifier())) {
            v.setModifier(modifier.get());
            modified = true;
        }
        if (!Objects.equals(modifyDate.get(), v.getModifyDate())) {
            v.setModifyDate(modifyDate.get());
            modified = true;
        }
        if (!Objects.equals(updatedDate.get(), v.getUpdatedDate())) {
            v.setUpdatedDate(updatedDate.get());
            modified = true;
        }
        return modified;
    }
}
