async def _create_domain(client, slug="tpsc-domain", name="TPSC Domain"):
    response = await client.post("/domains/", json={"slug": slug, "name": name})
    assert response.status_code == 201, response.text
    return response.json()


async def _create_repo(client, domain_slug="tpsc-domain", slug="tpsc-repo"):
    response = await client.post(
        "/repos/",
        json={
            "domain_slug": domain_slug,
            "slug": slug,
            "name": "TPSC Repo",
        },
    )
    assert response.status_code == 201, response.text
    return response.json()


async def test_tpsc_router_catalog_ingest_snapshot_and_gdpr_report(client) -> None:
    await _create_domain(client)
    await _create_repo(client)

    catalog_response = await client.post(
        "/tpsc/catalog/",
        json={
            "slug": "example-service",
            "name": "Example Service",
            "pricing_model": "paid",
            "gdpr_maturity": "unknown",
        },
    )
    assert catalog_response.status_code == 201, catalog_response.text
    catalog = catalog_response.json()
    assert catalog["slug"] == "example-service"
    assert catalog["gdpr_warning"] is True

    ingest_response = await client.post(
        "/tpsc/ingest/",
        json={
            "repo_slug": "tpsc-repo",
            "entries": [
                {
                    "service_slug": "example-service",
                    "purpose": "test processing",
                    "auth_type": "api_key",
                }
            ],
        },
    )
    assert ingest_response.status_code == 201, ingest_response.text
    snapshot = ingest_response.json()
    assert snapshot["repo_id"] is not None
    assert snapshot["entry_count"] == 1
    assert snapshot["entries"][0]["gdpr_warning"] is True
    assert snapshot["entries"][0]["pricing_model"] == "paid"

    snapshots_response = await client.get("/tpsc/snapshots/", params={"repo_slug": "tpsc-repo"})
    assert snapshots_response.status_code == 200, snapshots_response.text
    assert snapshots_response.json()[0]["entries"][0]["service_slug"] == "example-service"

    report_response = await client.get("/tpsc/report/gdpr")
    assert report_response.status_code == 200, report_response.text
    report = report_response.json()
    assert report["total_services"] == 1
    assert report["warning_count"] == 1
    assert report["by_maturity"] == {"unknown": 1}
    assert report["warnings"][0]["repo_slug"] == "tpsc-repo"
