package com.ecep.contract.vm;

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

import com.ecep.contract.CustomerFileType;
import com.ecep.contract.vo.CompanyCustomerFileVo;

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

@Data
@EqualsAndHashCode(callSuper = false)
@ToString
public class CompanyCustomerFileViewModel extends IdentityViewModel<CompanyCustomerFileVo> {

    public static CompanyCustomerFileViewModel from(CompanyCustomerFileVo companyCustomerFile) {
        CompanyCustomerFileViewModel model = new CompanyCustomerFileViewModel();
        model.update(companyCustomerFile);
        return model;
    }

    /**
     * CompanyCustomer
     */
    @ToString.Exclude
    private SimpleObjectProperty<Integer> customer = new SimpleObjectProperty<>();
    /**
     * 类型
     */
    private SimpleObjectProperty<CustomerFileType> type = new SimpleObjectProperty<>();

    private SimpleStringProperty filePath = new SimpleStringProperty();

    private SimpleStringProperty editFilePath = new SimpleStringProperty();

    private SimpleObjectProperty<LocalDate> signDate = new SimpleObjectProperty<>();

    @ToString.Exclude
    private SimpleBooleanProperty valid = new SimpleBooleanProperty(this, "valid", false);

    @Override
    protected void updateFrom(CompanyCustomerFileVo v) {
        super.updateFrom(v);
        getCustomer().set(v.getCustomer());
        getType().set(v.getType());
        getFilePath().set(v.getFilePath());
        getEditFilePath().set(v.getEditFilePath());

        getSignDate().set(v.getSignDate());
        getValid().set(v.isValid());
    }

    @Override
    public boolean copyTo(CompanyCustomerFileVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(customer.get(), v.getCustomer())) {
            v.setCustomer(customer.get());
            modified = true;
        }
        if (!Objects.equals(type.get(), v.getType())) {
            v.setType(type.get());
            modified = true;
        }

        if (!Objects.equals(filePath.get(), v.getFilePath())) {
            v.setFilePath(filePath.get());
            modified = true;
        }
        if (!Objects.equals(editFilePath.get(), v.getEditFilePath())) {
            v.setEditFilePath(editFilePath.get());
            modified = true;
        }
        if (!Objects.equals(signDate.get(), v.getSignDate())) {
            v.setSignDate(signDate.get());
            modified = true;
        }
        if (!Objects.equals(valid.get(), v.isValid())) {
            v.setValid(valid.get());
            modified = true;
        }
        return modified;
    }
}
