package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.VendorType;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.CompanyVendorApprovedItem;
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 CompanyVendorApprovedItemViewModel extends IdentityViewModel<CompanyVendorApprovedItem> {
    public static CompanyVendorApprovedItemViewModel from(CompanyVendorApprovedItem item) {
        CompanyVendorApprovedItemViewModel model = new CompanyVendorApprovedItemViewModel();
        model.update(item);
        return model;
    }


    private SimpleObjectProperty<CompanyVendorApprovedList> list = new SimpleObjectProperty<>();
    private SimpleStringProperty vendorName = new SimpleStringProperty();
    private SimpleObjectProperty<CompanyVendor> vendor = new SimpleObjectProperty<>();
    private SimpleObjectProperty<VendorType> type = new SimpleObjectProperty<>();
    private SimpleStringProperty description = new SimpleStringProperty();


    @Override
    protected void updateFrom(CompanyVendorApprovedItem v) {
        super.updateFrom(v);
        getVendorName().set(v.getVendorName());
        getList().set(v.getList());
        getVendor().set(v.getVendor());
        getType().set(v.getType());
        getDescription().set(v.getDescription());
    }

    @Override
    public boolean copyTo(CompanyVendorApprovedItem v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(vendorName.get(), v.getVendorName())) {
            v.setVendorName(vendorName.get());
            modified = true;
        }
        if (!Objects.equals(list.get(), v.getList())) {
            v.setList(list.get());
            modified = true;
        }
        if (!Objects.equals(vendor.get(), v.getVendor())) {
            v.setVendor(vendor.get());
            modified = true;
        }
        if (!Objects.equals(type.get(), v.getType())) {
            v.setType(type.get());
            modified = true;
        }
        if (!Objects.equals(description.get(), v.getDescription())) {
            v.setDescription(description.get());
            modified = true;
        }
        return modified;
    }
}
