package com.ecep.contract.vm;

import java.time.LocalDate;
import java.util.Objects;

import com.ecep.contract.vo.CompanyBankAccountVo;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyBankAccountViewModel extends IdentityViewModel<CompanyBankAccountVo>
        implements CompanyBasedViewModel {
    private SimpleIntegerProperty id = new SimpleIntegerProperty();

    private SimpleObjectProperty<Integer> companyId = new SimpleObjectProperty<>();
    private SimpleObjectProperty<Integer> bankId = new SimpleObjectProperty<>();

    private SimpleStringProperty openingBank = new SimpleStringProperty();
    private SimpleStringProperty account = new SimpleStringProperty();

    private SimpleObjectProperty<LocalDate> created = new SimpleObjectProperty<>();

    private SimpleIntegerProperty version = new SimpleIntegerProperty();

    @Override
    protected void updateFrom(CompanyBankAccountVo v) {
        getId().set(v.getId());
        companyId.set(v.getCompanyId());
        bankId.set(v.getBankId());
        getOpeningBank().set(v.getOpeningBank());
        getAccount().set(v.getAccount());
    }

    @Override
    public boolean copyTo(CompanyBankAccountVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(id.get(), v.getId())) {
            v.setId(id.get());
            modified = true;
        }
        if (!Objects.equals(companyId.get(), v.getCompanyId())) {
            v.setCompanyId(companyId.get());
            modified = true;
        }
        if (!Objects.equals(bankId.get(), v.getBankId())) {
            v.setBankId(bankId.get());
            modified = true;
        }
        if (!Objects.equals(openingBank.get(), v.getOpeningBank())) {
            v.setOpeningBank(openingBank.get());
            modified = true;
        }
        if (!Objects.equals(account.get(), v.getAccount())) {
            v.setAccount(account.get());
            modified = true;
        }
        return modified;
    }

    public static CompanyBankAccountViewModel from(CompanyBankAccountVo v) {
        CompanyBankAccountViewModel vm = new CompanyBankAccountViewModel();
        vm.updateFrom(v);
        return vm;
    }
}
