package com.ecep.contract.vm;

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

import com.ecep.contract.BlackReasonType;
import com.ecep.contract.model.CompanyBlackReason;

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

@Data
@EqualsAndHashCode(callSuper = false)
@ToString
public class CompanyBlackReasonViewModel extends IdentityViewModel<CompanyBlackReason> {
    private SimpleIntegerProperty id = new SimpleIntegerProperty();
    private SimpleObjectProperty<BlackReasonType> type = new SimpleObjectProperty<>();

    private SimpleStringProperty applyName = new SimpleStringProperty();
    private SimpleStringProperty blackReason = new SimpleStringProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleStringProperty key = new SimpleStringProperty();

    private SimpleObjectProperty<LocalDate> applyDate = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> updateTime = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> createTime = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> includeDate = new SimpleObjectProperty<>();


    public static CompanyBlackReasonViewModel from(CompanyBlackReason reason) {
        CompanyBlackReasonViewModel model = new CompanyBlackReasonViewModel();
        model.update(reason);
        return model;
    }

    @Override
    protected void updateFrom(CompanyBlackReason v) {
        getId().set(v.getId());
        getType().set(v.getType());
        getApplyName().set(v.getApplyName());
        getBlackReason().set(v.getBlackReason());
        getDescription().set(v.getDescription());
        getKey().set(v.getKey());
        getApplyDate().set(v.getApplyDate());
        getUpdateTime().set(v.getUpdateTime());
        getCreateTime().set(v.getCreateTime());
        getIncludeDate().set(v.getIncludeDate());
    }

    @Override
    public boolean copyTo(CompanyBlackReason v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(id.get(), v.getId())) {
            v.setId(id.get());
            modified = true;
        }
        if (!Objects.equals(type.get(), v.getType())) {
            v.setType(type.get());
            modified = true;
        }
        if (!Objects.equals(applyName.get(), v.getApplyName())) {
            v.setApplyName(applyName.get());
            modified = true;
        }
        if (!Objects.equals(blackReason.get(), v.getBlackReason())) {
            v.setBlackReason(blackReason.get());
            modified = true;
        }
        if (!Objects.equals(description.get(), v.getDescription())) {
            v.setDescription(description.get());
            modified = true;
        }
        if (!Objects.equals(key.get(), v.getKey())) {
            v.setKey(key.get());
            modified = true;
        }
        if (!Objects.equals(applyDate.get(), v.getApplyDate())) {
            v.setApplyDate(applyDate.get());
            modified = true;
        }
        if (!Objects.equals(updateTime.get(), v.getUpdateTime())) {
            v.setUpdateTime(updateTime.get());
            modified = true;
        }
        if (!Objects.equals(createTime.get(), v.getCreateTime())) {
            v.setCreateTime(createTime.get());
            modified = true;
        }
        if (!Objects.equals(includeDate.get(), v.getIncludeDate())) {
            v.setIncludeDate(includeDate.get());
            modified = true;
        }

        return modified;
    }

}
