from grantflow.tests.security_openapi_helpers import openapi_spec, response_schema_for


def test_openapi_declares_public_response_schemas_for_api_routes():
    spec = openapi_spec()

    expected_refs = {
        ("/.well-known/agent-capabilities.json", "get"): "AgentCapabilitiesPublicResponse",
        ("/agents/register", "post"): "AgentRegistrationPublicResponse",
        ("/generate", "post"): "GenerateAcceptedPublicResponse",
        ("/generate/from-preset", "post"): "GenerateFromPresetAcceptedPublicResponse",
        ("/generate/from-preset/batch", "post"): "GenerateFromPresetBatchPublicResponse",
        ("/generate/presets", "get"): "GeneratePresetListPublicResponse",
        ("/generate/presets/{preset_key}", "get"): "DemoGeneratePresetPublicResponse",
        ("/generate/presets/legacy", "get"): "GenerateLegacyPresetListPublicResponse",
        ("/generate/presets/legacy/{preset_key}", "get"): "GenerateLegacyPresetDetailPublicResponse",
        ("/generate/presets/rbm", "get"): "RBMSamplePresetListPublicResponse",
        ("/generate/presets/rbm/{sample_id}", "get"): "RBMSamplePresetDetailPublicResponse",
        ("/generate/preflight", "post"): "GeneratePreflightPublicResponse",
        ("/ingest/readiness", "post"): "GeneratePreflightPublicResponse",
        ("/ingest/recent", "get"): "IngestRecentListPublicResponse",
        ("/ingest/inventory", "get"): "IngestInventoryPublicResponse",
        ("/hitl/pending", "get"): "HITLPendingListPublicResponse",
        ("/queue/worker-heartbeat", "get"): "QueueWorkerHeartbeatPublicResponse",
        ("/queue/dead-letter", "get"): "DeadLetterQueueListPublicResponse",
        ("/queue/dead-letter/requeue", "post"): "DeadLetterQueueMutationPublicResponse",
        ("/queue/dead-letter", "delete"): "DeadLetterQueueMutationPublicResponse",
        ("/status/{job_id}", "get"): "JobStatusPublicResponse",
        ("/status/{job_id}/citations", "get"): "JobCitationsPublicResponse",
        ("/status/{job_id}/export-payload", "get"): "JobExportPayloadPublicResponse",
        ("/status/{job_id}/versions", "get"): "JobVersionsPublicResponse",
        ("/status/{job_id}/diff", "get"): "JobDiffPublicResponse",
        ("/status/{job_id}/events", "get"): "JobEventsPublicResponse",
        ("/status/{job_id}/metrics", "get"): "JobMetricsPublicResponse",
        ("/status/{job_id}/quality", "get"): "JobQualitySummaryPublicResponse",
        ("/status/{job_id}/grounding-gate", "get"): "JobGroundingGatePublicResponse",
        ("/status/{job_id}/critic", "get"): "JobCriticPublicResponse",
        ("/status/{job_id}/critic/findings", "get"): "CriticFindingsListPublicResponse",
        ("/status/{job_id}/critic/findings/{finding_id}", "get"): "CriticFatalFlawPublicResponse",
        ("/status/{job_id}/critic/findings/{finding_id}/ack", "post"): "CriticFatalFlawStatusUpdatePublicResponse",
        ("/status/{job_id}/critic/findings/{finding_id}/open", "post"): "CriticFatalFlawStatusUpdatePublicResponse",
        ("/status/{job_id}/critic/findings/{finding_id}/resolve", "post"): "CriticFatalFlawStatusUpdatePublicResponse",
        ("/status/{job_id}/critic/findings/bulk-status", "post"): "CriticFindingsBulkStatusPublicResponse",
        ("/status/{job_id}/comments", "get"): "JobCommentsPublicResponse",
        ("/status/{job_id}/comments", "post"): "ReviewCommentPublicResponse",
        ("/status/{job_id}/comments/bulk-status", "post"): "ReviewCommentsBulkStatusPublicResponse",
        ("/status/{job_id}/comments/{comment_id}/ack", "post"): "ReviewCommentPublicResponse",
        ("/status/{job_id}/comments/{comment_id}/resolve", "post"): "ReviewCommentPublicResponse",
        ("/status/{job_id}/comments/{comment_id}/reopen", "post"): "ReviewCommentPublicResponse",
        ("/status/{job_id}/review/workflow", "get"): "JobReviewWorkflowPublicResponse",
        ("/status/{job_id}/review/workflow/trends", "get"): "JobReviewWorkflowTrendsPublicResponse",
        ("/status/{job_id}/review/workflow/sla", "get"): "JobReviewWorkflowSLAPublicResponse",
        ("/status/{job_id}/review/workflow/sla/hotspots", "get"): "JobReviewWorkflowSLAHotspotsPublicResponse",
        ("/status/{job_id}/review/workflow/sla/trends", "get"): "JobReviewWorkflowSLATrendsPublicResponse",
        (
            "/status/{job_id}/review/workflow/sla/hotspots/trends",
            "get",
        ): "JobReviewWorkflowSLAHotspotsTrendsPublicResponse",
        ("/status/{job_id}/review/workflow/sla/profile", "get"): "JobReviewWorkflowSLAProfilePublicResponse",
        ("/status/{job_id}/review/workflow/sla/recompute", "post"): "JobReviewWorkflowSLARecomputePublicResponse",
        ("/portfolio/metrics", "get"): "PortfolioMetricsPublicResponse",
        ("/portfolio/quality", "get"): "PortfolioQualityPublicResponse",
        ("/portfolio/review-workflow", "get"): "PortfolioReviewWorkflowPublicResponse",
        ("/portfolio/review-workflow/sla", "get"): "PortfolioReviewWorkflowSLAPublicResponse",
        ("/portfolio/review-workflow/sla/hotspots", "get"): "PortfolioReviewWorkflowSLAHotspotsPublicResponse",
        (
            "/portfolio/review-workflow/sla/hotspots/trends",
            "get",
        ): "PortfolioReviewWorkflowSLAHotspotsTrendsPublicResponse",
        ("/portfolio/review-workflow/trends", "get"): "PortfolioReviewWorkflowTrendsPublicResponse",
        ("/portfolio/review-workflow/sla/trends", "get"): "PortfolioReviewWorkflowSLATrendsPublicResponse",
    }

    for (path, method), schema_name in expected_refs.items():
        assert response_schema_for(spec, path, method) == {"$ref": f"#/components/schemas/{schema_name}"}
