namespace Engine.Input;

public enum KeyboardButtonCode
{
  A,
  B,
  C,
  D,
  E,
  F,
  G,
  H,
  I,
  J,
  K,
  L,
  M,
  N,
  O,
  P,
  Q,
  R,
  S,
  T,
  U,
  V,
  W,
  X,
  Y,
  Z,

  D1,
  D2,
  D3,
  D4,
  D5,
  D6,
  D7,
  D8,
  D9,
  D0,

  Ctrl,
  Alt,
  Shift,

  Up,
  Down,
  Left,
  Right,

  Escape,
  Enter,
  Space,
  Tab,
  Backspace,
  Delete,
  Insert,
  Home,
  End,
  PageUp,
  PageDown,

  TotalCount = PageDown + 1
}

public static class KeyboardButtonCodeHelper
{
  public static List<KeyboardButtonCode> GetAllPrintableKeys() =>
    Enum.GetValues<KeyboardButtonCode>().Where(parX => parX.IsPrintableKey()).ToList();

  public static bool IsPrintableKey(this KeyboardButtonCode parKey) =>
    parKey is >= KeyboardButtonCode.A and <= KeyboardButtonCode.Z
      or >= KeyboardButtonCode.D1 and <= KeyboardButtonCode.D0 or KeyboardButtonCode.Space;

  public static char GetChar(this KeyboardButtonCode parKey)
  {
    return parKey switch
    {
      KeyboardButtonCode.A => 'A',
      KeyboardButtonCode.B => 'B',
      KeyboardButtonCode.C => 'C',
      KeyboardButtonCode.D => 'D',
      KeyboardButtonCode.E => 'E',
      KeyboardButtonCode.F => 'F',
      KeyboardButtonCode.G => 'G',
      KeyboardButtonCode.H => 'H',
      KeyboardButtonCode.I => 'I',
      KeyboardButtonCode.J => 'J',
      KeyboardButtonCode.K => 'K',
      KeyboardButtonCode.L => 'L',
      KeyboardButtonCode.M => 'M',
      KeyboardButtonCode.N => 'N',
      KeyboardButtonCode.O => 'O',
      KeyboardButtonCode.P => 'P',
      KeyboardButtonCode.Q => 'Q',
      KeyboardButtonCode.R => 'R',
      KeyboardButtonCode.S => 'S',
      KeyboardButtonCode.T => 'T',
      KeyboardButtonCode.U => 'U',
      KeyboardButtonCode.V => 'V',
      KeyboardButtonCode.W => 'W',
      KeyboardButtonCode.X => 'X',
      KeyboardButtonCode.Y => 'Y',
      KeyboardButtonCode.Z => 'Z',

      KeyboardButtonCode.D1 => '1',
      KeyboardButtonCode.D2 => '2',
      KeyboardButtonCode.D3 => '3',
      KeyboardButtonCode.D4 => '4',
      KeyboardButtonCode.D5 => '5',
      KeyboardButtonCode.D6 => '6',
      KeyboardButtonCode.D7 => '7',
      KeyboardButtonCode.D8 => '8',
      KeyboardButtonCode.D9 => '9',
      KeyboardButtonCode.D0 => '0',

      KeyboardButtonCode.Space => ' ',
      _ => '\0'
    };
  }
}