package com.ecep.contract.vm;

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

import com.ecep.contract.CompanyVendorFileType;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.CompanyVendorFile;

import javafx.beans.property.SimpleBooleanProperty;
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 CompanyVendorFileViewModel extends IdentityViewModel<CompanyVendorFile> {
    @ToString.Exclude
    private SimpleObjectProperty<CompanyVendor> vendor = new SimpleObjectProperty<>();

    private SimpleObjectProperty<CompanyVendorFileType> type = new SimpleObjectProperty<>();

    private SimpleStringProperty filePath = new SimpleStringProperty();

    private SimpleStringProperty editFilePath = new SimpleStringProperty();

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

    @ToString.Exclude
    private SimpleBooleanProperty valid = new SimpleBooleanProperty(this, "valid", false);


    @Override
    protected void updateFrom(CompanyVendorFile v) {
        super.updateFrom(v);
        getVendor().set(v.getVendor());
        getType().set(v.getType());
        getFilePath().set(v.getFilePath());
        getEditFilePath().set(v.getEditFilePath());

        getSignDate().set(v.getSignDate());
        getValid().set(v.isValid());
    }

    @Override
    public boolean copyTo(CompanyVendorFile v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getVendor().get(), v.getVendor())) {
            v.setVendor(getVendor().get());
            modified = true;
        }
        if (!Objects.equals(getType().get(), v.getType())) {
            v.setType(getType().get());
            modified = true;
        }

        if (!Objects.equals(getFilePath().get(), v.getFilePath())) {
            v.setFilePath(getFilePath().get());
            modified = true;
        }
        if (!Objects.equals(getEditFilePath().get(), v.getEditFilePath())) {
            v.setEditFilePath(getEditFilePath().get());
            modified = true;
        }
        if (!Objects.equals(getSignDate().get(), v.getSignDate())) {
            v.setSignDate(getSignDate().get());
            modified = true;
        }
        if (!Objects.equals(getValid().get(), v.isValid())) {
            modified = true;
        }
        return modified;
    }

    public static CompanyVendorFileViewModel from(CompanyVendorFile companyVendorFile) {
        CompanyVendorFileViewModel model = new CompanyVendorFileViewModel();
        model.update(companyVendorFile);
        return model;
    }
}
