package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.model.Bank;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class BankViewModel extends IdentityViewModel<Bank> {
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty name = new SimpleStringProperty();


    public static BankViewModel from(Bank v) {
        BankViewModel vm = new BankViewModel();
        vm.update(v);
        return vm;
    }


    @Override
    protected void updateFrom(Bank v) {
        super.updateFrom(v);
        getCode().set(v.getCode());
        getName().set(v.getName());
    }

    @Override
    public boolean copyTo(Bank v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getCode().get(), v.getCode())) {
            v.setCode(getCode().get());
            modified = true;
        }
        if (!Objects.equals(getName().get(), v.getName())) {
            v.setName(getName().get());
            modified = true;
        }
        return modified;
    }
}
