import { canonicalThemeKey, resolveThemeFolder } from './ThemeEntityTextures';

/** 对齐 Unity Animator Integer「Action」 */
export enum PlayerAction {
    Idle = 0,
    Move = 1,
    Jump = 2,
    Win = 3,
    Fail = 4,
}

export interface PlayerAnimSidePaths {
    idle: string;
    move: string;
    jump: string;
    win?: string;
    fail?: string;
}

export interface PlayerAnimPaths {
    front: PlayerAnimSidePaths;
    back: PlayerAnimSidePaths;
}

/** 各主题 skin 动画目录；无序列帧的主题返回 null（仍用静态贴图） */
export function resolvePlayerAnimPaths(theme: string | undefined): PlayerAnimPaths | null {
    const key = canonicalThemeKey(theme);
    const folder = resolveThemeFolder(theme);
    const base = `textures/${folder}`;

    switch (key) {
        case 'silu':
        case 'sanxing':
        case 'snow':
        case 'chinese':
        case 'redArmy':
        case 'numMan':
            return {
                front: {
                    idle: `${base}/skin/待机正面`,
                    move: `${base}/skin/走`,
                    jump: `${base}/skin/跳`,
                    fail: key === 'silu' ? `${base}/player/失败正` : undefined,
                },
                back: {
                    idle: `${base}/skin/待机背面`,
                    move: `${base}/skin/走背面`,
                    jump: `${base}/skin/跳背面`,
                    fail: key === 'silu' ? `${base}/player/失败反` : undefined,
                },
            };
        default:
            return null;
    }
}

export function actionFolder(side: PlayerAnimSidePaths, action: PlayerAction): string {
    switch (action) {
        case PlayerAction.Move: return side.move;
        case PlayerAction.Jump: return side.jump;
        case PlayerAction.Win: return side.win ?? side.idle;
        case PlayerAction.Fail: return side.fail ?? side.idle;
        default: return side.idle;
    }
}
