package com.ecep.contract.vm;

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

import com.ecep.contract.model.CompanyOldName;

import javafx.beans.property.SimpleBooleanProperty;
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 CompanyOldNameViewModel extends IdentityViewModel<CompanyOldName> {
    private SimpleIntegerProperty id = new SimpleIntegerProperty();
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty path = new SimpleStringProperty();



    private SimpleObjectProperty<LocalDate> beginDate = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> endDate = new SimpleObjectProperty<>();

    private SimpleBooleanProperty ambiguity = new SimpleBooleanProperty();
    private SimpleIntegerProperty version = new SimpleIntegerProperty();
    private SimpleStringProperty memo = new SimpleStringProperty();


    public static CompanyOldNameViewModel from(CompanyOldName name) {
        CompanyOldNameViewModel model = new CompanyOldNameViewModel();
        model.update(name);
        return model;
    }

    public void updateFrom(CompanyOldName oldName) {
        id.set(oldName.getId());
        name.set(oldName.getName());
        path.set(oldName.getPath());
        memo.set(oldName.getMemo());
        beginDate.set(oldName.getBeginDate());
        endDate.set(oldName.getEndDate());
        ambiguity.set(oldName.getAmbiguity());
        version.set(oldName.getVersion());

    }

    public boolean copyTo(CompanyOldName c) {
        boolean modified = super.copyTo(c);
        if (!Objects.equals(id.get(), c.getId())) {
            c.setId(id.get());
            modified = true;
        }
        if (!Objects.equals(name.get(), c.getName())) {
            c.setName(name.get());
            modified = true;
        }
        if (!Objects.equals(path.get(), c.getPath())) {
            c.setPath(path.get());
            modified = true;
        }
        if (!Objects.equals(memo.get(), c.getMemo())) {
            c.setMemo(memo.get());
            modified = true;
        }
        if (!Objects.equals(beginDate.get(), c.getBeginDate())) {
            c.setBeginDate(beginDate.get());
            modified = true;
        }
        if (!Objects.equals(endDate.get(), c.getEndDate())) {
            c.setEndDate(endDate.get());
            modified = true;
        }
        if (!Objects.equals(ambiguity.get(), c.getAmbiguity())) {
            c.setAmbiguity(ambiguity.get());
            modified = true;
        }
        return modified;
    }
}
