package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.model.Function;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionViewModel extends IdentityViewModel<Function> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty key = new SimpleStringProperty();
    private SimpleStringProperty controller = new SimpleStringProperty();
    private SimpleStringProperty icon = new SimpleStringProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleBooleanProperty active = new SimpleBooleanProperty();

    public static FunctionViewModel from(Function v) {
        FunctionViewModel model = new FunctionViewModel();
        model.update(v);
        return model;
    }


    @Override
    protected void updateFrom(Function v) {
        super.updateFrom(v);
        getName().set(v.getName());
        getKey().set(v.getKey());
        getController().set(v.getController());
        getIcon().set(v.getIcon());
        getDescription().set(v.getDescription());
        getActive().set(v.isActive());
    }

    @Override
    public boolean copyTo(Function v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(name.get(), v.getName())) {
            v.setName(name.get());
            modified = true;
        }
        if (!Objects.equals(key.get(), v.getKey())) {
            v.setKey(key.get());
            modified = true;
        }
        if (!Objects.equals(controller.get(), v.getController())) {
            v.setController(controller.get());
            modified = true;
        }
        if (!Objects.equals(icon.get(), v.getIcon())) {
            v.setIcon(icon.get());
            modified = true;
        }
        if (!Objects.equals(description.get(), v.getDescription())) {
            v.setDescription(description.get());
            modified = true;
        }
        if (active.get() != v.isActive()) {
            v.setActive(active.get());
            modified = true;
        }
        return modified;
    }
}
