"""Call-type configuration constants (PRD §5.1 FRFA-CS005 — Call Type Configuration Table).

Centralises which sections, defaults, and required documents apply to each
``GrantCall.CallType``. Consumed by:

- ``forms.GrantCallForm`` to drop irrelevant per-type fields.
- ``call_create.html`` / ``call_update.html`` to gate UI sections per type.
- ``funding.validate_call_publishable`` (CS016) to enforce required admin
  documents at publish time.
- ``services._grant_doc_validator`` (CS020) for applicant-attachment policy.

Keep mappings small and explicit — every addition should map to a model field
that already exists on ``GrantCall``.
"""
from __future__ import annotations


# PRD §5.1 FRFA-CS005 — sections / defaults per call type. Field names below
# refer to ``forms.GrantCallForm`` field keys. Anything not listed in
# ``visible_fields`` is dropped from the form for that call type.
CALL_TYPE_RULES = {
    "grant": {
        "label": "Grant",
        "applicant_budget_required_default": True,
        "interview_required_default": False,
        "visible_fields": {
            "applicant_budget_required",
        },
    },
    "scholarship": {
        "label": "Scholarship",
        "applicant_budget_required_default": False,
        "interview_required_default": True,
        "visible_fields": {
            "scholarship_university_required",
            "scholarship_course_required",
            "scholarship_cohort_year",
        },
    },
    "fellowship": {
        "label": "Fellowship",
        "applicant_budget_required_default": False,
        "interview_required_default": True,
        "visible_fields": {
            "fellowship_host_institution_required",
            "fellowship_term_months",
        },
    },
    "challenge": {
        "label": "Challenge",
        "applicant_budget_required_default": False,
        "interview_required_default": False,
        "visible_fields": {
            "challenge_innovation_stage",
            "challenge_sector_focus",
        },
    },
}


# PRD §5.1 FRFA-CS016 — required administrative documents per call type. Used
# by ``funding.validate_call_publishable`` to block publish until every
# required ``GrantCallDocument.doc_kind`` row is present. Keys must match
# ``GrantCallDocument.DocKind`` values.
CALL_TYPE_REQUIRED_ADMIN_DOCS = {
    "grant": ("guidelines", "proposal_template", "budget_template", "tc"),
    "scholarship": ("guidelines", "instructions", "tc"),
    "fellowship": ("guidelines", "fellowship_terms", "host_agreement"),
    "challenge": ("guidelines", "innovation_brief", "judging_criteria", "tc"),
}


# PRD §5.1 FRFA-CS028 — fields that may be edited on a PUBLISHED call. Anything
# outside this set is rejected by ``forms.GrantCallActiveEditForm`` so a live
# call's critical contract (dates, type, budget ceiling, funding linkage) is
# not mutated mid-flight. Description + guidelines + FAQ are surfaced as the
# "non-critical" cohort per the SRS.
ACTIVE_CALL_EDITABLE_FIELDS = frozenset(
    {
        "description",
        "guidelines",
    }
)
