package com.ecep.contract.vm;

import java.time.LocalDate;
import java.time.LocalDateTime;

import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.CompanyVendorEntity;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.VendorCatalog;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyVendorEntityViewModel extends IdentityViewModel<CompanyVendorEntity> {
    private SimpleObjectProperty<CompanyVendor> vendor = new SimpleObjectProperty<>();
    private SimpleObjectProperty<String> name = new SimpleObjectProperty<>();
    private SimpleObjectProperty<String> abbName = new SimpleObjectProperty<>();
    private SimpleObjectProperty<String> code = new SimpleObjectProperty<>();

    private SimpleObjectProperty<VendorCatalog> catalog = new SimpleObjectProperty<>();
    private SimpleObjectProperty<Employee> creator = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> developDate = new SimpleObjectProperty<>();
    private SimpleObjectProperty<Employee> modifier = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> modifyDate = new SimpleObjectProperty<>();

    private SimpleObjectProperty<LocalDate> updatedDate = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDateTime> fetchedTime = new SimpleObjectProperty<>();

    @Override
    protected void updateFrom(CompanyVendorEntity v) {
        super.updateFrom(v);
        vendor.set(v.getVendor());
        name.set(v.getName());
        abbName.set(v.getAbbName());
        code.set(v.getCode());
        catalog.set(v.getCatalog());
        creator.set(v.getCreator());
        developDate.set(v.getDevelopDate());
        modifier.set(v.getModifier());
        modifyDate.set(v.getModifyDate());
        updatedDate.set(v.getUpdatedDate());
        fetchedTime.set(v.getFetchedTime());
    }

    @Override
    public boolean copyTo(CompanyVendorEntity v) {
        boolean modified = super.copyTo(v);
        if (vendor.get() != null) {
            v.setVendor(vendor.get());
            modified = true;
        }
        if (name.get() != null) {
            v.setName(name.get());
            modified = true;
        }
        if (abbName.get() != null) {
            v.setAbbName(abbName.get());
            modified = true;
        }
        if (code.get() != null) {
            v.setCode(code.get());
            modified = true;
        }
        if (catalog.get() != null) {
            v.setCatalog(catalog.get());
            modified = true;
        }
        if (creator.get() != null) {
            v.setCreator(creator.get());
            modified = true;
        }
        if (developDate.get() != null) {
            v.setDevelopDate(developDate.get());
            modified = true;
        }
        if (modifier.get() != null) {
            v.setModifier(modifier.get());
            modified = true;
        }

        return modified;
    }

}
