package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.ContractFileType;
import com.ecep.contract.model.ProjectSaleTypeRequireFileType;
import com.ecep.contract.vo.ProjectSaleTypeRequireFileTypeVo;

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

/**
 *
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ProjectSaleTypeRequireFileTypeViewModel extends IdentityViewModel<ProjectSaleTypeRequireFileTypeVo> {
    /**
     * 销售类型,ProjectSaleType
     */
    private SimpleObjectProperty<Integer> saleType = new SimpleObjectProperty<>();
    private SimpleObjectProperty<ContractFileType> fileType = new SimpleObjectProperty<>();

    public static ProjectSaleTypeRequireFileTypeViewModel from(ProjectSaleTypeRequireFileTypeVo entity) {
        ProjectSaleTypeRequireFileTypeViewModel vm = new ProjectSaleTypeRequireFileTypeViewModel();
        vm.updateFrom(entity);
        return vm;
    }

    @Override
    protected void updateFrom(ProjectSaleTypeRequireFileTypeVo v) {
        super.updateFrom(v);
        getSaleType().set(v.getSaleTypeId());
        getFileType().set(v.getFileType());
    }

    @Override
    public boolean copyTo(ProjectSaleTypeRequireFileTypeVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getSaleType().get(), v.getSaleTypeId())) {
            v.setSaleTypeId(getSaleType().get());
            modified = true;
        }
        if (!Objects.equals(getFileType().get(), v.getFileType())) {
            v.setFileType(getFileType().get());
            modified = true;
        }
        return modified;
    }
}
