package be.iminds.ilabt.jfed.ui.javafx.probe_gui.command_arguments;

import be.iminds.ilabt.jfed.lowlevel.api.AbstractFederationApi2;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * ChApi2FieldsArgumentChooser
 */
public class ChApi2FieldsArgumentChooser extends MapStringToStringArgumentChooser implements ChApiTypeDependantArgumentChooser {
    private final AbstractFederationApi2 api;
    private String objectName;

    public ChApi2FieldsArgumentChooser(AbstractFederationApi2 api, String objectName) {
        super(api.getMinimumFieldsMap(objectName), "Field", "Value");
        this.api = api;
        this.objectName = objectName;
    }

    @Override
    public void setObjectType(String newObjectName) {
        if (newObjectName == null || objectName.equals(newObjectName))
            return;

        this.objectName = newObjectName;

        Map<String, String> newFieldsMap = api.getMinimumFieldsMap(objectName);

        argument.clear();
        if (newFieldsMap != null)
            argument.addAll(newFieldsMap.entrySet().stream().map(e -> new MyEntry(e.getKey(), e.getValue())).collect(Collectors.toList()));
//           table.setItems(this.argument);
    }
}
