package com.lazy.emulate.input

enum class GamepadButton {
    // D-Pad
    DPAD_UP,
    DPAD_DOWN,
    DPAD_LEFT,
    DPAD_RIGHT,

    // Face buttons (universal naming, mapped per console)
    FACE_BOTTOM,  // PS: Cross, Nintendo: B, Genesis: A
    FACE_RIGHT,   // PS: Circle, Nintendo: A, Genesis: B
    FACE_LEFT,    // PS: Square, Nintendo: Y, Genesis: X
    FACE_TOP,     // PS: Triangle, Nintendo: X, Genesis: Y

    // Shoulders
    L1,
    R1,
    L2,
    R2,

    // Sticks
    L3,
    R3,

    // Meta
    START,
    SELECT,

    // Genesis-specific
    MODE,        // Genesis mode button
    Z_BUTTON,    // Genesis 6-button Z
    C_BUTTON;    // Genesis 6-button C

    companion object {
        val PS1_BUTTONS = listOf(
            DPAD_UP, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT,
            FACE_BOTTOM, FACE_RIGHT, FACE_LEFT, FACE_TOP,
            L1, R1, L2, R2, L3, R3, START, SELECT
        )

        val NES_BUTTONS = listOf(
            DPAD_UP, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT,
            FACE_BOTTOM, FACE_RIGHT, START, SELECT
        )

        val SNES_BUTTONS = listOf(
            DPAD_UP, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT,
            FACE_BOTTOM, FACE_RIGHT, FACE_LEFT, FACE_TOP,
            L1, R1, START, SELECT
        )

        val N64_BUTTONS = listOf(
            DPAD_UP, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT,
            FACE_BOTTOM, FACE_RIGHT, FACE_LEFT, FACE_TOP,
            L1, R1, L2, START
        )

        val GENESIS_BUTTONS = listOf(
            DPAD_UP, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT,
            FACE_BOTTOM, FACE_RIGHT, FACE_LEFT,
            START, MODE, Z_BUTTON, C_BUTTON
        )

        val PS2_BUTTONS = PS1_BUTTONS

        fun buttonsForConsole(consoleType: com.lazy.emulate.emulation.ConsoleType): List<GamepadButton> {
            return when (consoleType) {
                com.lazy.emulate.emulation.ConsoleType.PS1 -> PS1_BUTTONS
                com.lazy.emulate.emulation.ConsoleType.NES -> NES_BUTTONS
                com.lazy.emulate.emulation.ConsoleType.SNES -> SNES_BUTTONS
                com.lazy.emulate.emulation.ConsoleType.N64 -> N64_BUTTONS
                com.lazy.emulate.emulation.ConsoleType.GENESIS -> GENESIS_BUTTONS
                com.lazy.emulate.emulation.ConsoleType.PS2 -> PS2_BUTTONS
            }
        }
    }
}
