package com.ecep.contract.vm;

import com.ecep.contract.model.BaseEnumEntity;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Objects;

@Data
@EqualsAndHashCode(callSuper = true)
public class EnumViewModel<K extends Enum<?>, T extends BaseEnumEntity<K>> extends IdentityViewModel<T> {
    private SimpleObjectProperty<K> type = new SimpleObjectProperty<>();
    private SimpleStringProperty lang = new SimpleStringProperty();
    private SimpleStringProperty value = new SimpleStringProperty();

    @Override
    protected void updateFrom(T v) {
        super.updateFrom(v);
        type.set(v.getType());
        lang.set(v.getLang());
        value.set(v.getValue());
    }

    @Override
    public boolean copyTo(T v) {
        boolean ret = super.copyTo(v);
        if (!Objects.equals(v.getType(), type.get())) {
            v.setType(type.get());
            ret = true;
        }
        if (!Objects.equals(v.getLang(), lang.get())) {
            v.setLang(lang.get());
            ret = true;
        }
        if (!Objects.equals(v.getValue(), value.get())) {
            v.setValue(value.get());
            ret = true;
        }
        return ret;
    }
}
