package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.model.VendorGroup;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class VendorGroupViewModel extends IdentityViewModel<VendorGroup> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleBooleanProperty active = new SimpleBooleanProperty();
    private SimpleBooleanProperty priceComparison = new SimpleBooleanProperty();
    /**
     * 中选的供应商是否可以免除报价表
     */
    private SimpleBooleanProperty requireQuotationSheetForBid = new SimpleBooleanProperty();
    /**
     * 是否可以提前预采购
     */
    private SimpleBooleanProperty canPrePurchase = new SimpleBooleanProperty();

    public static VendorGroupViewModel from(VendorGroup v) {
        VendorGroupViewModel vm = new VendorGroupViewModel();
        vm.updateFrom(v);
        return vm;
    }

    @Override
    protected void updateFrom(VendorGroup v) {
        super.updateFrom(v);
        getName().set(v.getName());
        getCode().set(v.getCode());
        getDescription().set(v.getDescription());
        getActive().set(v.isActive());
        getPriceComparison().set(v.isPriceComparison());
        getRequireQuotationSheetForBid().set(v.isRequireQuotationSheetForBid());
        getCanPrePurchase().set(v.isCanPrePurchase());
    }

    @Override
    public boolean copyTo(VendorGroup v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getName().get(), v.getName())) {
            v.setName(getName().get());
            modified = true;
        }
        if (!Objects.equals(getCode().get(), v.getCode())) {
            v.setCode(getCode().get());
            modified = true;
        }
        if (!Objects.equals(getDescription().get(), v.getDescription())) {
            v.setDescription(getDescription().get());
            modified = true;
        }
        if (!Objects.equals(getActive().get(), v.isActive())) {
            v.setActive(getActive().get());
            modified = true;
        }
        if (!Objects.equals(getPriceComparison().get(), v.isPriceComparison())) {
            v.setPriceComparison(getPriceComparison().get());
            modified = true;
        }
        if (!Objects.equals(getRequireQuotationSheetForBid().get(), v.isRequireQuotationSheetForBid())) {
            v.setRequireQuotationSheetForBid(getRequireQuotationSheetForBid().get());
            modified = true;
        }
        if (!Objects.equals(getCanPrePurchase().get(), v.isCanPrePurchase())) {
            v.setCanPrePurchase(getCanPrePurchase().get());
            modified = true;
        }

        return modified;
    }

}
