package com.ecep.contract.vm;

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

import com.ecep.contract.model.CompanyVendorApprovedList;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyVendorApprovedListViewModel
        extends IdentityViewModel<CompanyVendorApprovedList> {
    private SimpleStringProperty title = new SimpleStringProperty();
    private SimpleObjectProperty<LocalDate> publishDate = new SimpleObjectProperty<>();
    private SimpleStringProperty path = new SimpleStringProperty();
    private SimpleStringProperty description = new SimpleStringProperty();

    public static CompanyVendorApprovedListViewModel from(CompanyVendorApprovedList list) {
        CompanyVendorApprovedListViewModel model = new CompanyVendorApprovedListViewModel();
        model.update(list);
        return model;
    }

    @Override
    protected void updateFrom(CompanyVendorApprovedList v) {
        super.updateFrom(v);
        getTitle().set(v.getTitle());
        getPublishDate().set(v.getPublishDate());
        getPath().set(v.getPath());
        getDescription().set(v.getDescription());
    }

    @Override
    public boolean copyTo(CompanyVendorApprovedList v) {
        boolean modified = super.copyTo(v);

        if (!Objects.equals(title.get(), v.getTitle())) {
            v.setTitle(title.get());
            modified = true;
        }
        if (!Objects.equals(publishDate.get(), v.getPublishDate())) {
            v.setPublishDate(publishDate.get());
            modified = true;
        }
        if (!Objects.equals(path.get(), v.getPath())) {
            v.setPath(path.get());
            modified = true;
        }
        if (!Objects.equals(description.get(), v.getDescription())) {
            v.setDescription(description.get());
            modified = true;
        }
        return modified;
    }
}
