import type {GameState, PendingClaimState} from "../types/state";
import type {Tile} from "../types/tile.ts";

export interface RoomPlayerUpdatePayload {
    room_id?: string
    status?: string
    player_count?: number
    player_ids?: string[]
    players?: Array<{
        Index?: number
        index?: number
        PlayerID?: string
        player_id?: string
        PlayerName?: string
        player_name?: string
        AvatarUrl?: string
        avatar_url?: string
        Ready?: boolean
        ready?: boolean
        MissingSuit?: string | null
        missing_suit?: string | null
    }>
}


/**
 * 游戏动作定义（只描述“发生了什么”）
 */
export type GameAction =
// 初始化整局（进入房间 / 断线重连）
    | {
    type: 'GAME_INIT'
    payload: GameState
}

    // 开始游戏（发牌完成）
    | {
    type: 'GAME_START'
    payload: {
        dealerIndex: number
    }
}

    // 摸牌
    | {
    type: 'DRAW_TILE'
    payload: {
        playerId: string
        tile: Tile
    }
}

    // 出牌
    | {
    type: 'PLAY_TILE'
    payload: {
        playerId: string
        tile: Tile
        nextSeat: number
    }
}

    // 进入操作窗口（碰/杠/胡）
    | {
    type: 'PENDING_CLAIM'
    payload: PendingClaimState
}

    // 操作结束（碰/杠/胡/过）
    | {
    type: 'CLAIM_RESOLVED'
    payload: {
        playerId: string
        action: 'peng' | 'gang' | 'hu' | 'pass'
    }
}

    // 房间玩家更新（等待房间人数变化）
    | {
    type: 'ROOM_PLAYER_UPDATE'
    payload: RoomPlayerUpdatePayload
}
