"""念念官方表情包 — 四套 × 12 张。"""

from __future__ import annotations

from typing import Any

from niannian.chat.stickers_catalog import (
    STICKER_PACK_VERSION,
    build_sticker_catalog,
    chat_mode_to_sticker_pack,
    resolve_sticker_id,
)

STICKER_PACK_ID = STICKER_PACK_VERSION

STICKERS: dict[str, dict[str, str]] = {
    row["id"]: {"file": row["file"], "label": row["label"], "tags": row["tags"], "pack": row["pack"]}
    for row in build_sticker_catalog().values()
}


def list_stickers(*, pack: str | None = None) -> list[dict[str, Any]]:
    rows: list[dict[str, Any]] = []
    for sid, row in STICKERS.items():
        if pack and row.get("pack") != pack:
            continue
        rows.append(
            {
                "id": sid,
                "pack": row["pack"],
                "file": row["file"],
                "label": row["label"],
                "tags": row.get("tags", ""),
            }
        )
    return rows


def sticker_label(sticker_id: str) -> str:
    canonical = resolve_sticker_id(sticker_id)
    row = STICKERS.get(canonical)
    return str(row["label"]) if row else sticker_id


def validate_sticker_id(sticker_id: str) -> None:
    canonical = resolve_sticker_id(sticker_id)
    if canonical not in STICKERS:
        raise ValueError(f"unknown sticker_id: {sticker_id!r}")


def sticker_pack_for_chat_mode(chat_mode: str | None) -> str:
    return chat_mode_to_sticker_pack(chat_mode)
