from src.domain.composition_recipes.schemas import CompositionRecipe, PresentationExpectations
from src.domain.email.catalog import (
    EMAIL_TEMPLATE_CATALOG,
    get_email_template_definition,
    resolve_email_profile,
)


def test_catalog_contains_only_semantic_definitions_without_html_or_provider_fields() -> None:
    assert "auth.magic_link" in EMAIL_TEMPLATE_CATALOG
    for definition in EMAIL_TEMPLATE_CATALOG.values():
        assert definition.version_id.endswith(".v1")
        assert definition.archetype in {
            "action", "confirmation", "status_update", "reminder",
            "notification", "receipt", "summary", "security",
        }
        assert not hasattr(definition, "html")
        assert not hasattr(definition, "provider")
        assert not hasattr(definition, "sender")


def test_recipe_selects_profile_without_admitting_a_capability() -> None:
    recipe = CompositionRecipe(
        slug="appointment.standard",
        name="Appointment standard",
        starter_id="operations",
        presentation=PresentationExpectations(email_profile="appointment.standard"),
        required_capabilities=[],
    )
    profile = resolve_email_profile(recipe)
    assert profile.id == "appointment.standard"
    assert recipe.required_capabilities == []


def test_unknown_template_is_rejected() -> None:
    try:
        get_email_template_definition("booking.confirmation")
    except ValueError as exc:
        assert "unknown canonical email template" in str(exc)
    else:
        raise AssertionError("unknown template was accepted")
