from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


def test_product_code_review_gate_endpoint_returns_all_product_gate():
    app = FastAPI()
    app.include_router(router, prefix="/api/v1")
    client = TestClient(app)

    response = client.get("/api/v1/agents/product-code-review-gate")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "product_code_review_gate_v1"
    assert data["program_status"]["current_task_id"] == "P2-111"
    assert data["program_status"]["next_task_id"] == "P2-112"
    assert data["program_status"]["read_only_mode"] is True
    assert data["rollups"]["product_scope_count"] == len(data["product_review_matrix"]) >= 16
    assert data["tenant_asset_inventory_summary"]["public_route_count"] >= 31
    assert data["rollups"]["pre_deploy_gate_count"] == len(data["pre_deploy_gates"]) == 8
    assert data["rollups"]["post_deploy_gate_count"] == len(data["post_deploy_gates"]) == 6
    assert data["rollups"]["ai_reviewer_count"] == len(data["ai_reviewer_lanes"]) == 5
    assert data["rollups"]["mainstream_tool_count"] == len(data["mainstream_tool_lanes"]) == 9
    assert data["rollups"]["active_write_gate_count"] == 0
    assert data["rollups"]["action_button_count"] == 0
    assert data["gate_boundaries"]["auto_merge_allowed"] is False
    assert data["gate_boundaries"]["aider_auto_patch_allowed"] is False
    assert data["gate_boundaries"]["external_scanner_activation_allowed"] is False
    assert data["gate_boundaries"]["artifact_signing_allowed"] is False
    assert any(product["product_id"] == "PRD-001" for product in data["product_review_matrix"])
    assert any(product["product_id"] == "PRD-006" for product in data["product_review_matrix"])
    assert any(tool["tool_id"] == "codeql" for tool in data["mainstream_tool_lanes"])
    assert any(tool["tool_id"] == "semgrep" for tool in data["mainstream_tool_lanes"])
    assert any(tool["tool_id"] == "osv_scanner" for tool in data["mainstream_tool_lanes"])
