from uuid import uuid4

import pytest
from pydantic import ValidationError

from app.schemas.recipe import RecipeCreate, RecipeIngredientRef, ResolveIngredientRequest


def test_recipe_create_requires_canonical_ingredient_ids() -> None:
    iid = uuid4()
    payload = RecipeCreate(
        name="Sheet-Pan Chicken Thighs",
        servings=4,
        prep_time_minutes=10,
        cook_time_minutes=30,
        cuisine_tags=["american"],
        protein_type="chicken",
        ingredients=[RecipeIngredientRef(ingredient_id=iid, qty=2.0, unit="lb")],
        instructions=["Preheat oven", "Roast"],
    )
    assert payload.ingredients[0].ingredient_id == iid
    assert payload.servings == 4


def test_recipe_create_rejects_empty_ingredients() -> None:
    with pytest.raises(ValidationError):
        RecipeCreate(
            name="Empty",
            servings=4,
            prep_time_minutes=5,
            cook_time_minutes=5,
            cuisine_tags=[],
            protein_type="vegetarian",
            ingredients=[],
            instructions=["nope"],
        )


def test_resolve_ingredient_request_round_trip() -> None:
    req = ResolveIngredientRequest(text="1 lb chicken thighs")
    assert req.text == "1 lb chicken thighs"
