package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.vo.ContractBidVendorVo;

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 ContractBidVendorViewModel extends IdentityViewModel<ContractBidVendorVo> {
    private SimpleIntegerProperty contractId = new SimpleIntegerProperty();
    private SimpleObjectProperty<Integer> companyId = new SimpleObjectProperty<>();
    /**
     * 报价单文件ID, ContractFile
     */
    private SimpleObjectProperty<Integer> quotationSheetFileId = new SimpleObjectProperty<>();
    private SimpleStringProperty quotationSheetFileName = new SimpleStringProperty();

    public static ContractBidVendorViewModel from(ContractBidVendorVo v) {
        ContractBidVendorViewModel vm = new ContractBidVendorViewModel();
        vm.update(v);
        return vm;
    }

    @Override
    protected void updateFrom(ContractBidVendorVo v) {
        super.updateFrom(v);
        getContractId().set(v.getContractId() != null ? v.getContractId() : 0);
        getCompanyId().set(v.getCompanyId() != null ? v.getCompanyId() : 0);
        getQuotationSheetFileId().set(v.getQuotationSheetFileId() != null ? v.getQuotationSheetFileId() : 0);
    }

    @Override
    public boolean copyTo(ContractBidVendorVo v) {
        boolean modified = super.copyTo(v);
        if (getContractId().get() != v.getContractId()) {
            v.setContractId(getContractId().get() != 0 ? getContractId().get() : null);
            modified = true;
        }
        if (getCompanyId().get() != v.getCompanyId()) {
            v.setCompanyId(getCompanyId().get() != 0 ? getCompanyId().get() : null);
            modified = true;
        }
        if (getQuotationSheetFileId().get() != v.getQuotationSheetFileId()) {
            v.setQuotationSheetFileId(getQuotationSheetFileId().get() != 0 ? getQuotationSheetFileId().get() : null);
            modified = true;
        }
        return modified;
    }
}
