"""Pydantic configuration models."""

from __future__ import annotations

from typing import ClassVar, Literal

from pydantic import BaseModel, ConfigDict, Field


def _default_registry_variants() -> list[RegistryVariant]:
    """Return default registry variants.

    Returns:
        Empty list when no variants are configured.
    """
    return []


class RegistryVariant(BaseModel):
    """A variant for a registry entry."""

    model_config: ClassVar[ConfigDict] = ConfigDict(extra="forbid")

    id: str
    description: str
    manifest_url: str


class RegistryHistory(BaseModel):
    """History metadata attached to a registry entry."""

    model_config: ClassVar[ConfigDict] = ConfigDict(extra="forbid")

    strategy: Literal["github-tags"]
    repository: str
    file_path: str
    pattern: str | None = None
    variant_files: dict[str, str] = Field(default_factory=dict)


class RegistryEntry(BaseModel):
    """A single registry entry."""

    model_config: ClassVar[ConfigDict] = ConfigDict(extra="forbid")

    id: str
    name: str
    description: str
    pricing: Literal["paid", "free"] = "free"
    manifest_url: str
    default_variant: str | None = None
    variants: list[RegistryVariant] = Field(
        default_factory=_default_registry_variants,
    )
    history: RegistryHistory | None = None


class RegistryIndex(BaseModel):
    """Registry index data."""

    model_config: ClassVar[ConfigDict] = ConfigDict(extra="forbid")

    version: str
    entries: list[RegistryEntry]
