from grantflow.tests.security_openapi_helpers import openapi_spec, schema_props_for


def test_openapi_declares_portfolio_filter_schema_fields():
    spec = openapi_spec()

    portfolio_filters = schema_props_for(spec, "PortfolioMetricsFiltersPublicResponse")
    assert "toc_text_risk_level" in portfolio_filters
    assert "mel_risk_level" in portfolio_filters


def test_openapi_declares_portfolio_review_workflow_filter_schema_fields():
    spec = openapi_spec()

    for schema_name in [
        "PortfolioReviewWorkflowFiltersPublicResponse",
        "PortfolioReviewWorkflowTrendsFiltersPublicResponse",
    ]:
        props = schema_props_for(spec, schema_name)
        for name in [
            "donor_id",
            "status",
            "hitl_enabled",
            "warning_level",
            "grounding_risk_level",
            "toc_text_risk_level",
            "event_type",
            "finding_id",
            "finding_code",
            "finding_section",
            "comment_status",
            "workflow_state",
            "overdue_after_hours",
        ]:
            assert name in props

    for schema_name in [
        "PortfolioReviewWorkflowSLAFiltersPublicResponse",
        "PortfolioReviewWorkflowSLAHotspotsFiltersPublicResponse",
        "PortfolioReviewWorkflowSLAHotspotsTrendsFiltersPublicResponse",
        "PortfolioReviewWorkflowSLATrendsFiltersPublicResponse",
    ]:
        props = schema_props_for(spec, schema_name)
        for name in [
            "donor_id",
            "status",
            "hitl_enabled",
            "warning_level",
            "grounding_risk_level",
            "toc_text_risk_level",
            "finding_id",
            "finding_code",
            "finding_section",
            "comment_status",
            "workflow_state",
            "overdue_after_hours",
        ]:
            assert name in props

    assert "top_limit" in schema_props_for(spec, "PortfolioReviewWorkflowSLAFiltersPublicResponse")
    for schema_name in [
        "PortfolioReviewWorkflowSLAHotspotsFiltersPublicResponse",
        "PortfolioReviewWorkflowSLAHotspotsTrendsFiltersPublicResponse",
    ]:
        props = schema_props_for(spec, schema_name)
        for name in ["top_limit", "hotspot_kind", "hotspot_severity", "min_overdue_hours"]:
            assert name in props


def test_openapi_declares_job_review_workflow_filter_schema_fields():
    spec = openapi_spec()

    for schema_name in [
        "JobReviewWorkflowSLAFiltersPublicResponse",
        "JobReviewWorkflowSLAHotspotsFiltersPublicResponse",
        "JobReviewWorkflowSLAHotspotsTrendsFiltersPublicResponse",
    ]:
        props = schema_props_for(spec, schema_name)
        for name in [
            "finding_id",
            "finding_code",
            "finding_section",
            "comment_status",
            "workflow_state",
            "overdue_after_hours",
        ]:
            assert name in props

    for schema_name in [
        "JobReviewWorkflowSLAHotspotsFiltersPublicResponse",
        "JobReviewWorkflowSLAHotspotsTrendsFiltersPublicResponse",
    ]:
        props = schema_props_for(spec, schema_name)
        for name in ["top_limit", "hotspot_kind", "hotspot_severity", "min_overdue_hours"]:
            assert name in props
