# Generated by Django 5.1 on 2024-09-08 17:04
from django.db import migrations


def migrate_is_public_to_link_reach(apps, schema_editor):
    """
    Forward migration: Migrate 'is_public' to 'link_reach'.
    If is_public == True, set link_reach to 'public'
    """
    Document = apps.get_model("core", "Document")
    Document.objects.filter(is_public=True).update(link_reach="public")


def reverse_migrate_link_reach_to_is_public(apps, schema_editor):
    """
    Reverse migration: Migrate 'link_reach' back to 'is_public'.
    - If link_reach == 'public', set is_public to True
    - Else set is_public to False
    """
    Document = apps.get_model("core", "Document")
    Document.objects.filter(link_reach="public").update(is_public=True)
    Document.objects.filter(link_reach__in=["restricted", "authenticated"]).update(
        is_public=False
    )


class Migration(migrations.Migration):
    dependencies = [
        ("core", "0003_document_link_reach_document_link_role_and_more"),
    ]

    operations = [
        migrations.RunPython(
            migrate_is_public_to_link_reach, reverse_migrate_link_reach_to_is_public
        ),
    ]
