// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

#pragma once

#include <IAEngine/Base.hpp>

#include <SDL3/SDL.h>

namespace ia::iae
{
    class InputManager
    {
      public:
        STATIC VOID Initialize();
        STATIC VOID Terminate();

        STATIC VOID OnSDLEvent(IN SDL_Event *event);

        STATIC Vec2 GetAxis();
        STATIC VOID SwitchModeToText();
        STATIC VOID SwitchModeToAction();
        STATIC Vec2 GetPointerPosition();
        STATIC BOOL IsKeyDown(IN InputKey key);
        STATIC BOOL WasKeyPressed(IN InputKey key);
        STATIC BOOL WasKeyReleased(IN InputKey key);
        STATIC BOOL IsActionDown(IN Handle action);
        STATIC BOOL WasActionPressed(IN Handle action);
        STATIC BOOL WasActionReleased(IN Handle action);
        STATIC BOOL IsActionDown(IN CONST String& action);
        STATIC BOOL WasActionPressed(IN CONST String& action);
        STATIC BOOL WasActionReleased(IN CONST String& action);
        STATIC Handle BindAction(IN CONST String &name, IN InputKey key);
        STATIC VOID BindAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey);

      private:
        STATIC BOOL s_keys[256];
        STATIC BOOL s_prevKeys[256];
        STATIC Vec2 s_pointerPosition;
        STATIC InputKey s_axisInputs[4];
        STATIC Map<String, Handle> s_actionNames;
        STATIC Vector<Vector<InputKey>> s_actions;
    };
} // namespace ia::iae