package com.ecep.contract.vm;

import java.util.Objects;

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

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

@Data
@EqualsAndHashCode(callSuper = false)
public class VendorCatalogViewModel extends IdentityViewModel<VendorCatalogVo> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleObjectProperty<VendorType> type = new SimpleObjectProperty<>();
    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleBooleanProperty active = new SimpleBooleanProperty();

    @Override
    protected void updateFrom(VendorCatalogVo v) {
        super.updateFrom(v);
        name.set(v.getName());
        code.set(v.getCode());
        type.set(v.getType());
        description.set(v.getDescription());
    }

    @Override
    public boolean copyTo(VendorCatalogVo v) {
        boolean ret = super.copyTo(v);
        if (!Objects.equals(v.getName(), name.get())) {
            v.setName(name.get());
        }
        if (!Objects.equals(v.getCode(), code.get())) {
            v.setCode(code.get());
        }
        if (!Objects.equals(v.getType(), type.get())) {
            v.setType(type.get());
        }
        if (!Objects.equals(v.getDescription(), description.get())) {
            v.setDescription(description.get());
        }
        return ret;
    }

}
