package ru.kirillius.cooler.controller.CLI;

import ru.kirillius.cooler.controller.API.ActionType;
import ru.kirillius.cooler.controller.API.DataType;
import ru.kirillius.cooler.controller.API.MessageSystem;
import ru.kirillius.cooler.controller.API.Operation;

public class SettingsMenu extends Menu<Void> {
    public SettingsMenu(MessageSystem messageSystem) {
        super("Settings");
        add(new ReactiveMenuItemBinding(
                messageSystem,
                DataType.START_TEMP,
                "Start temperature",
                "°C",
                0,
                40,
                1
        ));
        add(new ReactiveMenuItemBinding(
                messageSystem,
                DataType.STOP_TEMP,
                "Stop temperature",
                "°C",
                0,
                40,
                1
        ));
        add(new ReactiveMenuItemBinding(
                messageSystem,
                DataType.MAX_TEMP,
                "Max temperature",
                "°C",
                25,
                80,
                1
        ));
        add(new ReactiveMenuItemBinding(
                messageSystem,
                DataType.MAX_LEVEL,
                "Max power level",
                "%",
                0,
                255,
                2.55f
        ));
        add(new ReactiveMenuItemBinding(
                messageSystem,
                DataType.MIN_LEVEL,
                "Min power level",
                "%",
                0,
                255,
                2.55f
        ));
        add(new CallbackMenuItem<>("Save settings") {
            @Override
            public Void select() {
                Operation operation = messageSystem.sendCommand(ActionType.SAVE);
                operation.waitForReturn();
                System.out.println(operation.isSuccessful() ? "Save OK" : "Save failed!");
                return null;
            }
        });
        add(new CallbackMenuItem<>("Exit") {
            @Override
            public Void select() {
                close();
                return null;
            }
        });
    }

    @Override
    protected Void OnSelect(int index, MenuItem<Void> item, Void value) {
        return null;
    }
}
