from dataclasses import dataclass
from typing import Dict, Optional


@dataclass(frozen=True)
class ChannelMeta:
    id: str
    label: str
    blurb: str


CHANNEL_ORDER = ("telegram", "whatsapp", "discord")
CHANNEL_ALIASES: Dict[str, str] = {"tg": "telegram", "wa": "whatsapp"}
CHANNEL_META: Dict[str, ChannelMeta] = {
    "telegram": ChannelMeta("telegram", "Telegram", "Bot API style channel"),
    "whatsapp": ChannelMeta("whatsapp", "WhatsApp", "Web session style channel"),
    "discord": ChannelMeta("discord", "Discord", "Bot token style channel"),
}


def normalize_channel_id(raw: Optional[str]) -> Optional[str]:
    if not raw:
        return None
    key = raw.strip().lower()
    key = CHANNEL_ALIASES.get(key, key)
    return key if key in CHANNEL_META else None

