package com.ecep.contract.vm;

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

import com.ecep.contract.model.ProjectSaleType;

import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class ProjectSaleTypeViewModel extends IdentityViewModel<ProjectSaleType> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty path = new SimpleStringProperty();
    private SimpleBooleanProperty storeByYear = new SimpleBooleanProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    /**
     * 符合重大项目的合同金额条件
     */
    private SimpleDoubleProperty criticalProjectLimit = new SimpleDoubleProperty();
    /**
     * 是否启用重大项目决策（三重一大）
     */
    private SimpleBooleanProperty criticalProjectDecision = new SimpleBooleanProperty();
    private SimpleBooleanProperty active = new SimpleBooleanProperty();
    private SimpleObjectProperty<LocalDate> created = new SimpleObjectProperty<>();

    public static ProjectSaleTypeViewModel from(ProjectSaleType v) {
        ProjectSaleTypeViewModel model = new ProjectSaleTypeViewModel();
        model.update(v);
        return model;
    }

    @Override
    protected void updateFrom(ProjectSaleType v) {
        super.updateFrom(v);
        getName().set(v.getName());
        getCode().set(v.getCode());
        getPath().set(v.getPath());
        getStoreByYear().set(v.isStoreByYear());
        getDescription().set(v.getDescription());
        getCriticalProjectLimit().set(v.getCriticalProjectLimit());
        getCriticalProjectDecision().set(v.isCriticalProjectDecision());
        getActive().set(v.isActive());
    }

    @Override
    public boolean copyTo(ProjectSaleType v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getName().get(), v.getName())) {
            v.setName(getName().get());
            modified = true;
        }
        if (!Objects.equals(getCode().get(), v.getCode())) {
            v.setCode(getCode().get());
            modified = true;
        }
        if (!Objects.equals(getPath().get(), v.getPath())) {
            v.setPath(getPath().get());
            modified = true;
        }
        if (!Objects.equals(getStoreByYear().get(), v.isStoreByYear())) {
            v.setStoreByYear(getStoreByYear().get());
            modified = true;
        }
        if (!Objects.equals(getDescription().get(), v.getDescription())) {
            v.setDescription(getDescription().get());
            modified = true;
        }
        if (!Objects.equals(getCriticalProjectLimit().get(), v.getCriticalProjectLimit())) {
            v.setCriticalProjectLimit(getCriticalProjectLimit().get());
            modified = true;
        }
        if (!Objects.equals(getCriticalProjectDecision().get(), v.isCriticalProjectDecision())) {
            v.setCriticalProjectDecision(getCriticalProjectDecision().get());
            modified = true;
        }
        if (!Objects.equals(getActive().get(), v.isActive())) {
            v.setActive(getActive().get());
            modified = true;
        }

        return modified;
    }
}
