package com.ecep.contract.vm;

import com.ecep.contract.vo.CompanyExtendInfoVo;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Objects;

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

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

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

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