# Generated by Django 5.2.13 on 2026-05-17 19:15

from django.db import migrations, models


def _backfill_doc_kind(apps, schema_editor):
    """PRD §5.1 FRFA-CS016 — backfill existing rows: any current GrantCallDocument
    flagged is_guideline becomes doc_kind='guidelines' so the publish-time
    check doesn't suddenly fail for pre-existing draft calls."""
    GrantCallDocument = apps.get_model("rims_grants", "GrantCallDocument")
    GrantCallDocument.objects.filter(is_guideline=True, doc_kind="other").update(doc_kind="guidelines")


class Migration(migrations.Migration):

    dependencies = [
        ("rims_grants", "0035_cs005_fellowship_challenge_fields"),
    ]

    operations = [
        migrations.AddField(
            model_name="grantcall",
            name="applicant_attachment_checklist",
            field=models.JSONField(
                blank=True,
                default=list,
                help_text='Optional checklist of expected applicant attachments, e.g. ["CV", "Cover letter"].',
            ),
        ),
        migrations.AddField(
            model_name="grantcall",
            name="applicant_attachment_formats",
            field=models.CharField(
                default="pdf,docx",
                help_text="Comma-separated allowed file extensions (no dot, lower-case). e.g. pdf,docx,xlsx.",
                max_length=120,
            ),
        ),
        migrations.AddField(
            model_name="grantcall",
            name="applicant_attachment_max_size_mb",
            field=models.PositiveSmallIntegerField(
                default=10, help_text="Maximum size per applicant attachment, in megabytes."
            ),
        ),
        migrations.AddField(
            model_name="grantcalldocument",
            name="doc_kind",
            field=models.CharField(
                choices=[
                    ("guidelines", "Guidelines"),
                    ("proposal_template", "Proposal template"),
                    ("budget_template", "Budget template"),
                    ("tc", "Terms & conditions"),
                    ("instructions", "Application instructions"),
                    ("fellowship_terms", "Fellowship terms"),
                    ("host_agreement", "Host institution agreement"),
                    ("innovation_brief", "Innovation brief"),
                    ("judging_criteria", "Judging criteria"),
                    ("other", "Other"),
                ],
                db_index=True,
                default="other",
                help_text="Classifies the document so publish-time checks know which required types are present (PRD FRFA-CS016).",
                max_length=32,
            ),
        ),
        migrations.RunPython(_backfill_doc_kind, migrations.RunPython.noop),
    ]
