package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyCustomerEvaluationFormFileViewModel extends IdentityViewModel<CompanyCustomerEvaluationFormFileVo> {
    
    private SimpleIntegerProperty customerFile = new SimpleIntegerProperty();
    private SimpleStringProperty catalog = new SimpleStringProperty();
    private SimpleStringProperty level = new SimpleStringProperty();
    private SimpleIntegerProperty creditLevel = new SimpleIntegerProperty(0);
    private SimpleIntegerProperty score1 = new SimpleIntegerProperty(0);
    private SimpleIntegerProperty score2 = new SimpleIntegerProperty(0);
    private SimpleIntegerProperty score3 = new SimpleIntegerProperty(0);
    private SimpleIntegerProperty score4 = new SimpleIntegerProperty(0);
    private SimpleIntegerProperty score5 = new SimpleIntegerProperty(0);
    private SimpleIntegerProperty scoreTemplateVersion = new SimpleIntegerProperty(1);

    private SimpleStringProperty filePath = new SimpleStringProperty();
    
    public static CompanyCustomerEvaluationFormFileViewModel from(CompanyCustomerEvaluationFormFileVo vo) {
        CompanyCustomerEvaluationFormFileViewModel viewModel = new CompanyCustomerEvaluationFormFileViewModel();
        viewModel.update(vo);
        return viewModel;
    }
    
    @Override
    protected void updateFrom(CompanyCustomerEvaluationFormFileVo vo) {
        super.updateFrom(vo);
        if (vo.getCustomerFile() != null) {
            customerFile.set(vo.getCustomerFile());
        }
        if (vo.getCatalog() != null) {
            catalog.set(vo.getCatalog());
        }
        if (vo.getLevel() != null) {
            level.set(vo.getLevel());
        }
        if (vo.getCreditLevel() != null) {
            creditLevel.set(vo.getCreditLevel());
        }
        if (vo.getScore1() != null) {
            score1.set(vo.getScore1());
        }
        if (vo.getScore2() != null) {
            score2.set(vo.getScore2());
        }
        if (vo.getScore3() != null) {
            score3.set(vo.getScore3());
        }
        if (vo.getScore4() != null) {
            score4.set(vo.getScore4());
        }
        if (vo.getScore5() != null) {
            score5.set(vo.getScore5());
        }
        if (vo.getScoreTemplateVersion() != null) {
            scoreTemplateVersion.set(vo.getScoreTemplateVersion());
        }
    }
    
    @Override
    public boolean copyTo(CompanyCustomerEvaluationFormFileVo vo) {
        boolean changed = super.copyTo(vo);
        if (!Objects.equals(customerFile.get(), vo.getCustomerFile())) {
            vo.setCustomerFile(customerFile.get());
            changed = true;
        }
        if (!Objects.equals(catalog.get(), vo.getCatalog())) {
            vo.setCatalog(catalog.get());
            changed = true;
        }
        if (!Objects.equals(level.get(), vo.getLevel())) {
            vo.setLevel(level.get());
            changed = true;
        }
        if (!Objects.equals(creditLevel.get(), vo.getCreditLevel())) {
            vo.setCreditLevel(creditLevel.get());
            changed = true;
        }
        if (!Objects.equals(score1.get(), vo.getScore1())) {
            vo.setScore1(score1.get());
            changed = true;
        }
        if (!Objects.equals(score2.get(), vo.getScore2())) {
            vo.setScore2(score2.get());
            changed = true;
        }
        if (!Objects.equals(score3.get(), vo.getScore3())) {
            vo.setScore3(score3.get());
            changed = true;
        }
        if (!Objects.equals(score4.get(), vo.getScore4())) {
            vo.setScore4(score4.get());
            changed = true;
        }
        if (!Objects.equals(score5.get(), vo.getScore5())) {
            vo.setScore5(score5.get());
            changed = true;
        }
        if (!Objects.equals(scoreTemplateVersion.get(), vo.getScoreTemplateVersion())) {
            vo.setScoreTemplateVersion(scoreTemplateVersion.get());
            changed = true;
        }
        return changed;
    }
}
