"""Presentation contracts for the Content Collection family.

These are composition IDs, not new storage or execution capabilities. A
generated app resolves membership through Dataset and renders one of these
presentation contracts locally or through its existing records adapter.
"""

from dataclasses import dataclass

COLLECTION_BLOCK_IDS = (
    "collection.index",
    "collection.grid",
    "collection.list",
    "collection.nav",
    "collection.featured",
    "collection.breadcrumbs",
    "collection.pagination",
)


@dataclass(frozen=True)
class CollectionRecipe:
    id: str
    blocks: tuple[str, ...]
    description: str


COLLECTION_RECIPES = (
    CollectionRecipe(
        id="business_pages",
        blocks=("collection.index", "collection.grid", "collection.nav"),
        description="Grouped Services, Industries, Locations, or Case Studies pages.",
    ),
    CollectionRecipe(
        id="blog",
        blocks=(
            "collection.index",
            "collection.grid",
            "collection.nav",
            "collection.pagination",
        ),
        description="Blog or resource posts grouped by category and route.",
    ),
)


def collection_recipe(recipe_id: str) -> CollectionRecipe:
    for recipe in COLLECTION_RECIPES:
        if recipe.id == recipe_id:
            return recipe
    raise KeyError(recipe_id)


def collection_recipe_for_text(text: str) -> CollectionRecipe:
    """Resolve the smallest admitted collection recipe for Codegen context."""
    lowered = (text or "").lower()
    if any(term in lowered for term in ("blog", "post", "resource", "article", "category")):
        return collection_recipe("blog")
    return collection_recipe("business_pages")
