#ifndef SUBSTATION_CONTROLLER_HPP_
#define SUBSTATION_CONTROLLER_HPP_

#include <memory>
#include <Controller/InventoryController/InventoryController.hpp>
#include <Machine/MSubstation/MSubstation.hpp>
#include <string>

class SubstationController final : public InventoryController
{
private:
    std::shared_ptr<MSubstation> substation;
    int energy = 0;
    int channelUpdatedCounter;
    MSubstation::Stats stats;
    std::unordered_map<DataLink::Channel, MSubstation::Condition> channelConditions;

    Command<uint32_t, int, std::unordered_map<DataLink::Channel, MSubstation::Condition>> updateSubstationState;
    Command<uint32_t, DataLink::Channel, MSubstation::Operator, int> setCondition;
    Command<uint32_t, MSubstation::Stats> updateStats;

    Widget* makeConditionRow(DataLink::Channel channel, Material &icon);
    Widget* makeBatteryLevelPage();
    Widget* makeDataOutputsPage();
    Widget* makeStatRow(std::string label, Widget *value);
    Widget* makeStatsPage();

public:
    SubstationController(ControllerChannel &channel);

    void onConnect(std::shared_ptr<Machine> substationMachine);

    virtual Widget* getRightPanel() override;
    virtual void update() override;
    virtual glm::vec4 getSlotHighlight(const std::string &id, int slot, ItemStack &stack) override;
};

#endif