# Generated by Django 4.2.24 on 2026-01-10

from django.db import migrations


def backfill_content_modalities(apps, schema_editor):
    """
    Backfill existing annotations with ["TEXT"] for content_modalities.

    This sets a default modality for all existing annotations that have
    an empty content_modalities array.
    """
    Annotation = apps.get_model("annotations", "Annotation")

    # Update all annotations where content_modalities is empty
    Annotation.objects.filter(content_modalities=[]).update(
        content_modalities=["TEXT"]
    )


def reverse_backfill(apps, schema_editor):
    """
    Reverse the backfill by setting content_modalities back to empty.

    Note: This will reset ALL annotations to empty, not just the ones
    that were backfilled. Use with caution.
    """
    Annotation = apps.get_model("annotations", "Annotation")
    Annotation.objects.update(content_modalities=[])


class Migration(migrations.Migration):

    dependencies = [
        ("annotations", "0052_add_content_modalities"),
    ]

    operations = [
        migrations.RunPython(backfill_content_modalities, reverse_backfill),
    ]
