package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.vo.BankVo;

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

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


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


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

    @Override
    public boolean copyTo(BankVo 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;
    }
}
