# Generated by Django 5.2.8 on 2025-11-19 17:50

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("authentik_flows", "0028_flowtoken_revoke_on_execution"),
        ("authentik_policies", "0011_policybinding_failure_result_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="Connector",
            fields=[
                (
                    "connector_uuid",
                    models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False),
                ),
                ("name", models.TextField()),
                ("enabled", models.BooleanField(default=True)),
                (
                    "snapshot_expiry",
                    models.TextField(
                        default="hours=24",
                        validators=[authentik.lib.utils.time.timedelta_string_validator],
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Device",
            fields=[
                (
                    "policybindingmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        to="authentik_policies.policybindingmodel",
                    ),
                ),
                ("attributes", models.JSONField(blank=True, default=dict)),
                ("expires", models.DateTimeField(default=None, null=True)),
                ("expiring", models.BooleanField(default=True)),
                (
                    "device_uuid",
                    models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False),
                ),
                ("name", models.TextField()),
                ("identifier", models.TextField(unique=True)),
            ],
            options={
                "abstract": False,
            },
            bases=("authentik_policies.policybindingmodel", models.Model),
        ),
        migrations.CreateModel(
            name="DeviceGroup",
            fields=[
                (
                    "policybindingmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="authentik_policies.policybindingmodel",
                    ),
                ),
                ("name", models.TextField(unique=True)),
            ],
            bases=("authentik_policies.policybindingmodel",),
        ),
        migrations.CreateModel(
            name="DeviceConnection",
            fields=[
                (
                    "device_connection_uuid",
                    models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False),
                ),
                (
                    "connector",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="authentik_endpoints.connector",
                    ),
                ),
                (
                    "device",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="authentik_endpoints.device"
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.AddField(
            model_name="device",
            name="connections",
            field=models.ManyToManyField(
                through="authentik_endpoints.DeviceConnection", to="authentik_endpoints.connector"
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="group",
            field=models.ForeignKey(
                default=None,
                null=True,
                on_delete=django.db.models.deletion.SET_DEFAULT,
                to="authentik_endpoints.devicegroup",
            ),
        ),
        migrations.CreateModel(
            name="DeviceUserBinding",
            fields=[
                (
                    "policybinding_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="authentik_policies.policybinding",
                    ),
                ),
                ("is_primary", models.BooleanField(default=False)),
                (
                    "connector",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="authentik_endpoints.connector",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
            bases=("authentik_policies.policybinding",),
        ),
        migrations.CreateModel(
            name="EndpointStage",
            fields=[
                (
                    "stage_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="authentik_flows.stage",
                    ),
                ),
                (
                    "connector",
                    authentik.lib.models.InheritanceForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="authentik_endpoints.connector",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
            bases=("authentik_flows.stage",),
        ),
        migrations.CreateModel(
            name="DeviceFactSnapshot",
            fields=[
                ("expires", models.DateTimeField(default=None, null=True)),
                ("expiring", models.BooleanField(default=True)),
                (
                    "snapshot_id",
                    models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False),
                ),
                ("data", models.JSONField(default=dict)),
                ("created", models.DateTimeField(auto_now_add=True)),
                (
                    "connection",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="authentik_endpoints.deviceconnection",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "indexes": [
                    models.Index(fields=["expires"], name="authentik_e_expires_a1e8b7_idx"),
                    models.Index(fields=["expiring"], name="authentik_e_expirin_b1eb6b_idx"),
                    models.Index(
                        fields=["expiring", "expires"], name="authentik_e_expirin_ce06ca_idx"
                    ),
                ],
            },
        ),
        migrations.AddIndex(
            model_name="device",
            index=models.Index(fields=["expires"], name="authentik_e_expires_f533f5_idx"),
        ),
        migrations.AddIndex(
            model_name="device",
            index=models.Index(fields=["expiring"], name="authentik_e_expirin_038503_idx"),
        ),
        migrations.AddIndex(
            model_name="device",
            index=models.Index(
                fields=["expiring", "expires"], name="authentik_e_expirin_b26ba1_idx"
            ),
        ),
    ]
