#pragma once

#include <cstdint>
#include <string>
#include <vector>

#include "application/config/ConfigCategory.h"
#include "application/config/ConfigValueData.h"

namespace ta::ui
{
    enum class ConfigControlKind : std::uint8_t
    {
        ActionRow,
        Checkbox,
        Colorpicker,
        FloatSlider,
        IntSlider,
        IntTextbox,
        Keybind,
        Select,
        Textbox
    };

    using ConfigColorSnapshot = ta::application::config::ConfigColorData;

    struct ConfigValueSnapshot
    {
        // Stable identity used for lookup and command routing.
        std::string id;
        std::string key;
        // Untranslated resource key used to build the visible label in the UI.
        std::string label_key;
        ConfigControlKind kind = ConfigControlKind::Textbox;

        bool bool_value = false;
        int int_value = 0;
        int int_min = 0;
        int int_max = 0;
        float float_value = 0.0f;
        float float_min = 0.0f;
        float float_max = 0.0f;
        float float_step = 0.1f;
        std::string text_value;
        ConfigColorSnapshot color_value{};
        std::vector<std::string> options;
        bool allow_none = true;

        [[nodiscard]] bool valid() const noexcept
        {
            return !id.empty() && !key.empty();
        }
    };

    struct ConfigPanelSnapshot
    {
        std::string id;
        std::string label_key;
        ta::application::config::ConfigCategory category =
            ta::application::config::ConfigCategory::Config;
        std::vector<ConfigValueSnapshot> values;
    };

    struct ConfigUiSnapshot
    {
        ConfigPanelSnapshot global_config;
        std::vector<ConfigPanelSnapshot> panels;
    };

    enum class ConfigCommandType : std::uint8_t
    {
        SetValue,
        InvokeAction
    };

    struct ConfigCommand
    {
        ConfigCommandType type = ConfigCommandType::SetValue;
        std::string key;
        ta::application::config::ConfigValueData value;
        std::uint64_t trace_id = 0;
    };
}
