package com.ecep.contract.vm;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;

import com.ecep.contract.model.CustomerSatisfactionSurvey;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.Project;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class CustomerSatisfactionSurveyViewModel extends IdentityViewModel<CustomerSatisfactionSurvey> implements ProjectBasedViewModel {
    /**
     * 关联的项目
     */
    private SimpleObjectProperty<Project> project = new SimpleObjectProperty<>();

    private SimpleStringProperty code = new SimpleStringProperty();

    private SimpleObjectProperty<LocalDate> date = new SimpleObjectProperty<>();

    private SimpleIntegerProperty totalScore = new SimpleIntegerProperty();
    private SimpleStringProperty data = new SimpleStringProperty();
    private SimpleObjectProperty<Employee> applicant = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDateTime> applyTime = new SimpleObjectProperty<>();
    /**
     * 说明、注释
     */
    private SimpleStringProperty description = new SimpleStringProperty();

    @Override
    protected void updateFrom(CustomerSatisfactionSurvey v) {
        super.updateFrom(v);
        getProject().set(v.getProject());
        getCode().set(v.getCode());
        getDate().set(v.getDate());
        getTotalScore().set(v.getTotalScore());
        getData().set(v.getData());
        getApplicant().set(v.getApplicant());
        getApplyTime().set(v.getApplyTime());
        getDescription().set(v.getDescription());
    }

    @Override
    public boolean copyTo(CustomerSatisfactionSurvey v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getProject().get(), v.getProject())) {
            v.setProject(getProject().get());
            modified = true;
        }
        if (!Objects.equals(getCode().get(), v.getCode())) {
            v.setCode(getCode().get());
            modified = true;
        }
        if (!Objects.equals(getDate().get(), v.getDate())) {
            v.setDate(getDate().get());
            modified = true;
        }
        if (!Objects.equals(getTotalScore().get(), v.getTotalScore())) {
            v.setTotalScore(getTotalScore().get());
            modified = true;
        }
        if (!Objects.equals(getData().get(), v.getData())) {
            v.setData(getData().get());
            modified = true;
        }
        if (!Objects.equals(getApplicant().get(), v.getApplicant())) {
            v.setApplicant(getApplicant().get());
            modified = true;
        }
        if (!Objects.equals(getApplyTime().get(), v.getApplyTime())) {
            v.setApplyTime(getApplyTime().get());
            modified = true;
        }
        if (!Objects.equals(getDescription().get(), v.getDescription())) {
            v.setDescription(getDescription().get());
            modified = true;
        }
        return modified;
    }
}
