<?php

declare(strict_types=1);

namespace App\Framework\Console;

/**
 * Keyboard input codes für TUI Navigation
 */
enum TuiKeyCode: string
{
    case ARROW_UP = "\033[A";
    case ARROW_DOWN = "\033[B";
    case ARROW_LEFT = "\033[D";
    case ARROW_RIGHT = "\033[C";
    case ENTER = "\n";
    case SPACE = " ";
    case BACKSPACE = "\177";
    case ESCAPE = "\033";
    case TAB = "\t";
    case DELETE = "\033[3~";
    case HOME = "\033[H";
    case END = "\033[F";
    case PAGE_UP = "\033[5~";
    case PAGE_DOWN = "\033[6~";
    case F1 = "\033OP";

    /**
     * Check if this is a navigation key
     */
    public function isNavigationKey(): bool
    {
        return match($this) {
            self::ARROW_UP, self::ARROW_DOWN, self::ARROW_LEFT, self::ARROW_RIGHT,
            self::HOME, self::END, self::PAGE_UP, self::PAGE_DOWN => true,
            default => false
        };
    }

    /**
     * Check if this is an action key
     */
    public function isActionKey(): bool
    {
        return match($this) {
            self::ENTER, self::SPACE, self::BACKSPACE, self::ESCAPE => true,
            default => false
        };
    }

    /**
     * Get human-readable description
     */
    public function getDescription(): string
    {
        return match($this) {
            self::ARROW_UP => 'Arrow Up',
            self::ARROW_DOWN => 'Arrow Down',
            self::ARROW_LEFT => 'Arrow Left',
            self::ARROW_RIGHT => 'Arrow Right',
            self::ENTER => 'Enter',
            self::SPACE => 'Space',
            self::BACKSPACE => 'Backspace',
            self::ESCAPE => 'Escape',
            self::TAB => 'Tab',
            self::DELETE => 'Delete',
            self::HOME => 'Home',
            self::END => 'End',
            self::PAGE_UP => 'Page Up',
            self::PAGE_DOWN => 'Page Down',
            self::F1 => 'F1',
        };
    }
}
