using System.Collections.Generic;
using SDL2;

namespace SlatedGameToolkit.Framework.Input.Devices
{
    public delegate void keyboardUpdate(SDL.SDL_Keycode keys, bool pressed);
    public static class Keyboard {
        private static HashSet<SDL.SDL_Keycode> pressedKeys = new HashSet<SDL.SDL_Keycode>();

        /// <summary>
        /// Whenever a keyboard update occurs.
        /// </summary>
        public static event keyboardUpdate keyboardUpdateEvent;
        public static bool IsKeyPressed(SDL.SDL_Keycode key) {
            return pressedKeys.Contains(key);
        }

        internal static void OnKeyPressed(SDL.SDL_Keycode key) {
            pressedKeys.Add(key);
            keyboardUpdateEvent?.Invoke(key, true);
        }
        
        internal static void OnKeyReleased(SDL.SDL_Keycode key) {
            pressedKeys.Remove(key);
            keyboardUpdateEvent?.Invoke(key, false);
        }
    }
}