package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.VendorType;
import com.ecep.contract.vo.VendorApprovedItemVo;

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<VendorApprovedItemVo> {
    public static CompanyVendorApprovedItemViewModel from(VendorApprovedItemVo item) {
        CompanyVendorApprovedItemViewModel model = new CompanyVendorApprovedItemViewModel();
        model.update(item);
        return model;
    }

    /**
     * CompanyVendorApprovedListVo
     */
    private SimpleObjectProperty<Integer> list = new SimpleObjectProperty<>();
    private SimpleStringProperty vendorName = new SimpleStringProperty();
    private SimpleObjectProperty<Integer> vendor = new SimpleObjectProperty<>();
    private SimpleObjectProperty<VendorType> type = new SimpleObjectProperty<>();
    private SimpleStringProperty description = new SimpleStringProperty();

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

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