# Generated by Django 4.2 on 2023-05-15 11:13

from django.db import migrations


def add_default_workflow(apps, schema_editor):
    Workflow = apps.get_model("wagtailcore", "Workflow")
    WorkflowContentType = apps.get_model("wagtailcore", "WorkflowContentType")
    ContentType = apps.get_model("contenttypes", "ContentType")
    Person = apps.get_model("base", "Person")

    default_workflow = Workflow.objects.filter(active=True).first()
    person_ct = ContentType.objects.get_for_model(Person)

    WorkflowContentType.objects.create(
        workflow=default_workflow,
        content_type=person_ct,
    )


def remove_default_workflow(apps, schema_editor):
    WorkflowContentType = apps.get_model("wagtailcore", "WorkflowContentType")
    ContentType = apps.get_model("contenttypes", "ContentType")
    Person = apps.get_model("base", "Person")

    person_ct = ContentType.objects.get_for_model(Person)

    WorkflowContentType.objects.filter(content_type=person_ct).delete()


class Migration(migrations.Migration):

    dependencies = [
        ("base", "0013_person_lockablemixin"),
        ("wagtailcore", "0083_workflowcontenttype"),
    ]

    operations = [
        migrations.RunPython(
            add_default_workflow,
            remove_default_workflow,
        ),
    ]
