# Generated by Django 5.1.15 on 2026-02-12 17:07

from django.db import migrations, models


def migrate_private_to_review_status(apps, schema_editor):
    """Copy private boolean to review_status: True -> 'pending', False -> 'accepted'."""
    Case = apps.get_model("cases", "Case")
    Case.objects.filter(private=True).update(review_status="pending")
    # private=False cases already have review_status="accepted" (the default)


def migrate_review_status_to_private(apps, schema_editor):
    """Reverse: copy review_status back to private boolean."""
    Case = apps.get_model("cases", "Case")
    Case.objects.filter(review_status="pending").update(private=True)
    Case.objects.filter(review_status="rejected").update(private=True)
    # review_status="accepted" cases already have private=False (the default)


class Migration(migrations.Migration):
    dependencies = [
        ("cases", "0024_add_performance_indexes"),
    ]

    operations = [
        # Step 1: Add review_status field (with default "accepted")
        migrations.AddField(
            model_name="case",
            name="review_status",
            field=models.CharField(
                choices=[
                    ("pending", "Pending"),
                    ("accepted", "Accepted"),
                    ("rejected", "Rejected"),
                ],
                db_index=True,
                default="accepted",
                help_text="Review status for case visibility",
                max_length=10,
            ),
        ),
        # Step 2: Copy data from private to review_status
        migrations.RunPython(
            migrate_private_to_review_status,
            migrate_review_status_to_private,
        ),
        # Step 3: Remove private field
        migrations.RemoveField(
            model_name="case",
            name="private",
        ),
    ]
