from __future__ import annotations

from dataclasses import dataclass
from typing import Mapping


@dataclass(frozen=True)
class ModelAlias:
    canonical: str
    provider: str
    provider_model: str


class AliasCatalog:
    """Pure mapping of canonical model ids to provider-specific variants."""

    def __init__(self, aliases: Mapping[str, Mapping[str, str]]) -> None:
        self._aliases = {
            canonical: dict(provider_map) for canonical, provider_map in aliases.items()
        }

    def providers_for(self, canonical_model: str) -> list[str]:
        models = self._aliases.get(canonical_model, {})
        return list(models.keys())

    def resolve_provider_model(self, canonical_model: str, provider: str) -> str:
        models = self._aliases.get(canonical_model)
        if models is None:
            return canonical_model
        return models.get(provider, canonical_model)
