package com.ecep.contract.vm;

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

import com.ecep.contract.model.CompanyVendorApprovedFile;
import com.ecep.contract.model.CompanyVendorApprovedList;

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 CompanyVendorApprovedFileViewModel extends IdentityViewModel<CompanyVendorApprovedFile> {

    public static CompanyVendorApprovedFileViewModel from(CompanyVendorApprovedFile companyVendorApprovedItemFile) {
        CompanyVendorApprovedFileViewModel viewModel = new CompanyVendorApprovedFileViewModel();
        viewModel.update(companyVendorApprovedItemFile);
        return viewModel;
    }

    @ToString.Exclude
    private SimpleObjectProperty<CompanyVendorApprovedList> list = new SimpleObjectProperty<>();

    private SimpleStringProperty fileName = new SimpleStringProperty();

    private SimpleObjectProperty<LocalDate> signDate = new SimpleObjectProperty<>();

    private SimpleStringProperty description = new SimpleStringProperty();

    @Override
    protected void updateFrom(CompanyVendorApprovedFile v) {
        super.updateFrom(v);
        getList().set(v.getList());
        getFileName().set(v.getFileName());
        getSignDate().set(v.getSignDate());
        getDescription().set(v.getDescription());
    }

    @Override
    public boolean copyTo(CompanyVendorApprovedFile v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(list.get(), v.getList())) {
            v.setList(list.get());
            modified = true;
        }
        if (!Objects.equals(fileName.get(), v.getFileName())) {
            v.setFileName(fileName.get());
            modified = true;
        }
        if (!Objects.equals(signDate.get(), v.getSignDate())) {
            v.setSignDate(signDate.get());
            modified = true;
        }
        if (!Objects.equals(description.get(), v.getDescription())) {
            v.setDescription(description.get());
            modified = true;
        }
        return modified;
    }
}
