"""external_content_blog: the first vertical recipe demonstrating
external.entity_ingest's reusability beyond content-ingest's own install path.
Presentation half only (content.collection) -- see the recipe file's header
comment for why the ingestion half can't appear in `requires`.
"""
from __future__ import annotations

from src.domain.app_blocks.vertical_recipes import (
    load_recipes,
    match_recipe_for_intent,
    match_vertical_recipe,
    validate_recipes,
)
from src.domain.app_blocks.schemas import ProductIntent


def test_recipe_is_loaded_and_valid():
    recipes = load_recipes()
    recipe = next((r for r in recipes if r.id == "external_content_blog"), None)
    assert recipe is not None
    assert recipe.required_app_blocks == ["content.collection"]
    assert validate_recipes(recipes) == []


def test_matches_relevant_prompts():
    for prompt in [
        "I want an external content blog synced from Airtable",
        "Set up an airtable blog for our site",
        "We need a webhook fed blog",
    ]:
        assert match_vertical_recipe(prompt) is not None


def test_does_not_match_unrelated_prompts():
    for prompt in [
        "I need a contact form",
        "Track customer orders",
        "Build a booking calendar",
    ]:
        match = match_vertical_recipe(prompt)
        assert match is None or match.id != "external_content_blog"


def test_match_recipe_for_intent_resolves_through_full_product_intent():
    intent = ProductIntent(source_prompt="We want an airtable blog with synced content")
    recipe = match_recipe_for_intent(intent)
    assert recipe is not None
    assert recipe.id == "external_content_blog"
