package com.ecep.contract.vm;

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

import com.ecep.contract.vo.CompanyVendorApprovedFileVo;

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<CompanyVendorApprovedFileVo> {

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

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

    private SimpleStringProperty fileName = new SimpleStringProperty();

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

    private SimpleStringProperty description = new SimpleStringProperty();

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

    @Override
    public boolean copyTo(CompanyVendorApprovedFileVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(list.get(), v.getListId())) {
            v.setListId(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;
    }
}
