package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.ContractFileType;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.model.ProjectSaleTypeRequireFileType;

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

/**
 *
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ProjectSaleTypeRequireFileTypeViewModel extends IdentityViewModel<ProjectSaleTypeRequireFileType> {
    private SimpleObjectProperty<ProjectSaleType> saleType = new SimpleObjectProperty<>();
    private SimpleObjectProperty<ContractFileType> fileType = new SimpleObjectProperty<>();

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

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

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