package com.ecep.contract.vm;

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

import com.ecep.contract.model.ProjectIndustry;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class ProjectIndustryViewModel extends IdentityViewModel<ProjectIndustry> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleObjectProperty<LocalDate> created = new SimpleObjectProperty<>();

    public static ProjectIndustryViewModel from(ProjectIndustry v) {
        ProjectIndustryViewModel model = new ProjectIndustryViewModel();
        model.update(v);
        return model;
    }

    @Override
    protected void updateFrom(ProjectIndustry v) {
        super.updateFrom(v);
        getName().set(v.getName());
        getCode().set(v.getCode());
        getDescription().set(v.getDescription());
    }

    @Override
    public boolean copyTo(ProjectIndustry 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(getDescription().get(), v.getDescription())) {
            v.setDescription(getDescription().get());
            modified = true;
        }

        return modified;
    }
}
