#pragma once

#include <cstddef>
#include <span>

namespace pp::app {

enum class InterfaceDirection {
    left_to_right,
    right_to_left,
};

enum class TimelapseRecordingAction {
    no_op,
    start_recording,
    stop_recording,
};

struct ScaleApplicationPlan {
    float scale = 1.0F;
    float display_density = 1.0F;
    float font_scale = 1.0F;
};

struct ScaleOptionSelection {
    bool has_selection = false;
    std::size_t index = 0;
};

struct InterfaceDirectionPlan {
    InterfaceDirection direction = InterfaceDirection::left_to_right;
};

struct TimelapsePreferencePlan {
    bool enabled = true;
    TimelapseRecordingAction recording_action = TimelapseRecordingAction::no_op;
};

struct StoredIntegerPreferencePlan {
    int value = 0;
};

struct StoredBooleanPreferencePlan {
    bool value = false;
};

[[nodiscard]] constexpr ScaleApplicationPlan plan_ui_scale(
    float requested_scale,
    float display_density) noexcept
{
    return {
        requested_scale,
        display_density,
        requested_scale * display_density,
    };
}

[[nodiscard]] constexpr ScaleApplicationPlan plan_viewport_scale(
    float requested_scale,
    float display_density = 1.0F) noexcept
{
    return {
        requested_scale,
        display_density,
        requested_scale * display_density,
    };
}

[[nodiscard]] constexpr ScaleOptionSelection plan_scale_option_selection(
    float current_scale,
    std::span<const float> options) noexcept
{
    ScaleOptionSelection selection;
    for (std::size_t index = 0; index < options.size(); ++index) {
        if (current_scale >= options[index]) {
            selection.has_selection = true;
            selection.index = index;
        }
    }
    return selection;
}

[[nodiscard]] constexpr InterfaceDirectionPlan plan_interface_direction(bool right_to_left) noexcept
{
    return {
        right_to_left ? InterfaceDirection::right_to_left : InterfaceDirection::left_to_right,
    };
}

[[nodiscard]] constexpr TimelapsePreferencePlan plan_timelapse_preference(
    bool enabled,
    bool recording_running) noexcept
{
    if (enabled && !recording_running) {
        return { enabled, TimelapseRecordingAction::start_recording };
    }
    if (!enabled && recording_running) {
        return { enabled, TimelapseRecordingAction::stop_recording };
    }
    return { enabled, TimelapseRecordingAction::no_op };
}

[[nodiscard]] constexpr StoredBooleanPreferencePlan plan_vr_controllers_preference(
    bool enabled) noexcept
{
    return { enabled };
}

[[nodiscard]] constexpr StoredIntegerPreferencePlan plan_canvas_cursor_mode(int mode) noexcept
{
    return { mode };
}

}
