package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyExtendInfo;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyExtendInfoViewModel extends IdentityViewModel<CompanyExtendInfo> {
    /**
     * 关联的公司
     */
    private SimpleObjectProperty<Company> company = new SimpleObjectProperty<>();
    /**
     * 是否禁用核验
     */
    private SimpleBooleanProperty disableVerify = new SimpleBooleanProperty();
    private SimpleIntegerProperty version = new SimpleIntegerProperty();

    public static CompanyExtendInfoViewModel from(CompanyExtendInfo v) {
        CompanyExtendInfoViewModel vm = new CompanyExtendInfoViewModel();
        vm.updateFrom(v);
        return vm;
    }

    @Override
    protected void updateFrom(CompanyExtendInfo v) {
        super.updateFrom(v);
        getCompany().set(v.getCompany());
        getDisableVerify().set(v.isDisableVerify());
        getVersion().set(v.getVersion());
    }

    @Override
    public boolean copyTo(CompanyExtendInfo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(company.get(), v.getCompany())) {
            v.setCompany(company.get());
            modified = true;
        }
        if (!Objects.equals(disableVerify.get(), v.isDisableVerify())) {
            v.setDisableVerify(disableVerify.get());
            modified = true;
        }
        return modified;
    }
}
