package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.model.Company;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.ContractBidVendor;
import com.ecep.contract.model.ContractFile;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class ContractBidVendorViewModel extends IdentityViewModel<ContractBidVendor> {
    /**
     * 关联的合同
     */
    private SimpleObjectProperty<Contract> contract = new SimpleObjectProperty<>();
    /**
     * 关联的企业
     */
    private SimpleObjectProperty<Company> company = new SimpleObjectProperty<>();
    /**
     *
     */
    private SimpleObjectProperty<ContractFile> quotationSheet = new SimpleObjectProperty<>();


    @Override
    protected void updateFrom(ContractBidVendor v) {
        super.updateFrom(v);
        getContract().set(v.getContract());
        getCompany().set(v.getCompany());
        getQuotationSheet().set(v.getQuotationSheet());
    }

    @Override
    public boolean copyTo(ContractBidVendor v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(contract.get(), v.getContract())) {
            v.setContract(contract.get());
            modified = true;
        }
        if (!Objects.equals(company.get(), v.getCompany())) {
            v.setCompany(company.get());
            modified = true;
        }
        if (!Objects.equals(quotationSheet.get(), v.getQuotationSheet())) {
            v.setQuotationSheet(quotationSheet.get());
            modified = true;
        }

        return modified;
    }

    public static ContractBidVendorViewModel from(ContractBidVendor contractBidVendor) {
        ContractBidVendorViewModel viewModel = new ContractBidVendorViewModel();
//        viewModel.updateFrom(contractBidVendor);
        viewModel.update(contractBidVendor);
        return viewModel;
    }
}
