"""念念表情包目录 — 四套模式 × 24 张（基础 12 + 梗图 12）· SSOT。"""

from __future__ import annotations

from typing import TypedDict

STICKER_PACK_VERSION = "niannian_v2"

# chat_mode → 贴纸套系（auto 与 default 共用 default 套）
STICKER_MODE_PACKS: tuple[str, ...] = ("default", "companion", "work", "education")

PACK_LABELS: dict[str, str] = {
    "default": "正常",
    "companion": "陪伴",
    "work": "工作",
    "education": "学习",
}

# slug, label — 基础 12 张
STICKER_EMOTIONS: tuple[tuple[str, str], ...] = (
    ("hi", "嗨～"),
    ("think", "让我想想"),
    ("happy", "太好了"),
    ("sorry", "对不起"),
    ("cheer", "加油呀"),
    ("serious", "说正经的"),
    ("hug", "抱抱你"),
    ("sleepy", "想睡了"),
    ("pout", "哼～"),
    ("laugh", "哈哈"),
    ("confused", "啥？？"),
    ("ok", "OK啦"),
)

STICKER_MEMES: tuple[tuple[str, str], ...] = (
    ("facepalm", "扶额"),
    ("speechless", "无语"),
    ("meltdown", "破防了"),
    ("melon", "吃瓜"),
    ("peek", "暗中观察"),
    ("thanks", "栓Q"),
    ("flee", "润了"),
    ("absurd", "离谱"),
    ("only_this", "就这？"),
    ("wow", "好家伙"),
    ("flat", "摆烂了"),
    ("overtime", "卷死了"),
)

STICKER_ITEMS: tuple[tuple[str, str], ...] = STICKER_EMOTIONS + STICKER_MEMES

# v1 兼容：nn_* → default/*
LEGACY_STICKER_IDS: dict[str, str] = {
    f"nn_{slug}": f"default_{slug}" for slug, _ in STICKER_EMOTIONS[:6]
}


class StickerRow(TypedDict):
    id: str
    pack: str
    file: str
    label: str
    tags: str


def chat_mode_to_sticker_pack(chat_mode: str | None) -> str:
    mode = (chat_mode or "auto").strip()
    if mode in ("companion", "work", "education"):
        return mode
    return "default"


def build_sticker_catalog() -> dict[str, StickerRow]:
    rows: dict[str, StickerRow] = {}
    for pack in STICKER_MODE_PACKS:
        for slug, label in STICKER_ITEMS:
            sid = f"{pack}_{slug}"
            tag = PACK_LABELS[pack]
            if slug in dict(STICKER_MEMES):
                tag = f"{tag}·梗"
            rows[sid] = {
                "id": sid,
                "pack": pack,
                "file": f"{pack}/{slug}.png",
                "label": label,
                "tags": tag,
            }
    return rows


def resolve_sticker_id(sticker_id: str) -> str:
    return LEGACY_STICKER_IDS.get(sticker_id, sticker_id)
