//
// Created by sebastian on 02.08.26.
//

#ifndef COLORRACE_KEYBOARD_H
#define COLORRACE_KEYBOARD_H
#include <unordered_set>
#include <vector>

namespace engine {
    class Window;
}

namespace engine {

    class Keyboard {
    public:
        explicit Keyboard(engine::Window& window);

        void update();
        bool isKeyDown(int key) const;

        const std::vector<int> &getCharsThisFrame();

        bool keyPressEvent(int key) const;
        bool keyPressEvent(int key, bool checkRepeats) const;
        bool keyReleaseEvent(int key) const;
    private:
        std::unordered_set<int> keysPressedThisFrame;
        std::unordered_set<int> keysRepeatedThisFrame;
        std::unordered_set<int> keysReleasedThisFrame;
        std::unordered_set<int> keysDown;
        std::vector<int> charsThisFrame;

        void addTextListener(Window& window);

        void addKeyListener(Window& window);
        void reportKeyPress(int key);
        void reportKeyRelease(int key);
        void reportKeyRepeat(int key);
        void reportChar(int key);
    };
}


#endif //COLORRACE_KEYBOARD_H
