# Generated by Django 5.2.11 on 2026-02-09 15:57

import authentik.lib.utils.time
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("authentik_core", "0057_remove_user_groups_remove_user_user_permissions_and_more"),
        ("authentik_events", "0016_alter_event_action"),
        ("contenttypes", "0002_remove_content_type_name"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="LifecycleRule",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
                ("name", models.TextField(unique=True)),
                ("object_id", models.TextField(default=None, null=True)),
                (
                    "interval",
                    models.TextField(
                        default="days=60",
                        validators=[authentik.lib.utils.time.timedelta_string_validator],
                    ),
                ),
                (
                    "grace_period",
                    models.TextField(
                        default="days=30",
                        validators=[authentik.lib.utils.time.timedelta_string_validator],
                    ),
                ),
                ("min_reviewers", models.PositiveSmallIntegerField(default=1)),
                ("min_reviewers_is_per_group", models.BooleanField(default=False)),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="contenttypes.contenttype"
                    ),
                ),
                (
                    "notification_transports",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Select which transports should be used to notify the reviewers. If none are selected, the notification will only be shown in the authentik UI.",
                        to="authentik_events.notificationtransport",
                    ),
                ),
                ("reviewer_groups", models.ManyToManyField(blank=True, to="authentik_core.group")),
                ("reviewers", models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name="LifecycleIteration",
            fields=[
                (
                    "managed",
                    models.TextField(
                        default=None,
                        help_text="Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.",
                        null=True,
                        unique=True,
                        verbose_name="Managed by authentik",
                    ),
                ),
                ("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
                ("object_id", models.TextField()),
                (
                    "state",
                    models.CharField(
                        choices=[
                            ("REVIEWED", "Reviewed"),
                            ("PENDING", "Pending"),
                            ("OVERDUE", "Overdue"),
                            ("CANCELED", "Canceled"),
                        ],
                        default="PENDING",
                        max_length=10,
                    ),
                ),
                ("opened_on", models.DateField(auto_now_add=True)),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="contenttypes.contenttype"
                    ),
                ),
                (
                    "rule",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="authentik_lifecycle.lifecyclerule",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Review",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
                ("timestamp", models.DateTimeField(auto_now_add=True)),
                ("note", models.TextField(null=True)),
                (
                    "iteration",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="authentik_lifecycle.lifecycleiteration",
                    ),
                ),
                (
                    "reviewer",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
                    ),
                ),
            ],
        ),
        migrations.AddIndex(
            model_name="lifecyclerule",
            index=models.Index(fields=["content_type"], name="authentik_l_content_4e3a6a_idx"),
        ),
        migrations.AddConstraint(
            model_name="lifecyclerule",
            constraint=models.UniqueConstraint(
                condition=models.Q(("object_id__isnull", True)),
                fields=("content_type",),
                name="uniq_lifecycle_rule_ct_null_object",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="lifecyclerule",
            unique_together={("content_type", "object_id")},
        ),
        migrations.AddIndex(
            model_name="lifecycleiteration",
            index=models.Index(
                fields=["content_type", "opened_on"], name="authentik_l_content_09c32a_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="review",
            unique_together={("iteration", "reviewer")},
        ),
    ]
