package com.ecep.contract.vm;

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

import com.ecep.contract.CompanyFileType;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyFile;

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

/**
 * View Model for {@link CompanyFile}
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyFileViewModel extends IdentityViewModel<CompanyFile> {
    SimpleObjectProperty<Company> company = new SimpleObjectProperty<>();
    SimpleObjectProperty<CompanyFileType> type = new SimpleObjectProperty<>();
    SimpleObjectProperty<LocalDate> applyDate = new SimpleObjectProperty<>();
    SimpleObjectProperty<LocalDate> expiringDate = new SimpleObjectProperty<>();
    SimpleStringProperty filePath = new SimpleStringProperty();


    @Override
    protected void updateFrom(CompanyFile v) {
        super.updateFrom(v);
        company.set(v.getCompany());
        type.set(v.getType());
        applyDate.set(v.getApplyDate());
        expiringDate.set(v.getExpiringDate());
        filePath.set(v.getFilePath());
    }

    public boolean copyTo(CompanyFile v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(company.get(), v.getCompany())) {
            v.setCompany(company.get());
            modified = true;
        }

        if (!Objects.equals(type.get(), v.getType())) {
            v.setType(type.get());
            modified = true;
        }

        if (!Objects.equals(applyDate.get(), v.getApplyDate())) {
            v.setApplyDate(applyDate.get());
            modified = true;
        }
        if (!Objects.equals(expiringDate.get(), v.getExpiringDate())) {
            v.setExpiringDate(expiringDate.get());
            modified = true;
        }
        if (!Objects.equals(filePath.get(), v.getFilePath())) {
            v.setFilePath(filePath.get());
            modified = true;
        }
        return modified;
    }

    public static CompanyFileViewModel from(CompanyFile file) {
        CompanyFileViewModel model = new CompanyFileViewModel();
        model.update(file);
        return model;
    }
}