"""End-to-end: ingredient + recipe + match all wired together."""
import pytest

pytestmark = pytest.mark.requires_postgres


def _admin() -> dict:
    return {"Authorization": "Bearer test-admin-token"}


def test_seed_data_present_and_resolvable(client):
    r = client.get("/api/recipes")
    assert r.status_code == 200
    recipes = r.json()
    assert len(recipes) >= 30, f"expected >=30 seeded recipes, got {len(recipes)}"


def test_resolve_against_seeded_ingredients(client):
    r = client.post(
        "/api/admin/recipes/resolve-ingredient",
        json={"text": "1 lb chicken thighs"},
        headers=_admin(),
    )
    assert r.status_code == 200
    candidates = r.json()["candidates"]
    assert candidates, "expected at least one candidate"
    assert "chicken" in candidates[0]["name"].lower()


def test_match_job_runs_against_seeded_data(db_session):
    from app.services.matcher import run_match_job

    written = run_match_job(db_session)
    assert written >= 0
