package com.ecep.contract.vm;

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

import com.ecep.contract.vo.CompanyVendorEntityVo;

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

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

    private SimpleObjectProperty<Integer> catalogId = new SimpleObjectProperty<>();
    private SimpleObjectProperty<Integer> creatorId = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> developDate = new SimpleObjectProperty<>();
    private SimpleObjectProperty<Integer> modifierId = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDate> modifyDate = new SimpleObjectProperty<>();

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

    @Override
    protected void updateFrom(CompanyVendorEntityVo v) {
        super.updateFrom(v);
        if (v.getVendorId() != null) {
            vendorId.set(v.getVendorId());
        }
        name.set(v.getName());
        abbName.set(v.getAbbName());
        code.set(v.getCode());
        if (v.getCatalogId() != null) {
            catalogId.set(v.getCatalogId());
        }
        if (v.getCreatorId() != null) {
            creatorId.set(v.getCreatorId());
        }
        developDate.set(v.getDevelopDate());
        if (v.getModifierId() != null) {
            modifierId.set(v.getModifierId());
        }
        modifyDate.set(v.getModifyDate());
        updatedDate.set(v.getUpdatedDate());
        fetchedTime.set(v.getFetchedTime());
    }

    @Override
    public boolean copyTo(CompanyVendorEntityVo v) {
        boolean modified = super.copyTo(v);
        if (vendorId.get() != 0) {
            v.setVendorId(vendorId.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 (catalogId.get() != 0) {
            v.setCatalogId(catalogId.get());
            modified = true;
        }
        if (creatorId.get() != 0) {
            v.setCreatorId(creatorId.get());
            modified = true;
        }
        if (developDate.get() != null) {
            v.setDevelopDate(developDate.get());
            modified = true;
        }
        if (modifierId.get() != 0) {
            v.setModifierId(modifierId.get());
            modified = true;
        }
        if (modifyDate.get() != null) {
            v.setModifyDate(modifyDate.get());
            modified = true;
        }
        if (updatedDate.get() != null) {
            v.setUpdatedDate(updatedDate.get());
            modified = true;
        }
        if (fetchedTime.get() != null) {
            v.setFetchedTime(fetchedTime.get());
            modified = true;
        }

        return modified;
    }

}
