# Generated by Django 3.1.7 on 2023-05-23 14:21

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("account", "0002_add_serviceaccount_api_token"),
    ]

    operations = [
        migrations.CreateModel(
            name="UserFlag",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("datetime_created", models.DateTimeField(auto_now_add=True)),
                ("datetime_updated", models.DateTimeField(auto_now=True)),
                ("name", models.TextField()),
                ("description", models.TextField(blank=True)),
                (
                    "app_label",
                    models.CharField(
                        help_text="The Django app label of the app that provided this flag type",
                        max_length=100,
                    ),
                ),
                (
                    "identifier",
                    models.SlugField(
                        help_text="The globally unique identifier for this flag type",
                        unique=True,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="UserFlagMembership",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("datetime_created", models.DateTimeField(auto_now_add=True)),
                ("datetime_updated", models.DateTimeField(auto_now=True)),
                ("datetime_valid_from", models.DateTimeField()),
                ("datetime_valid_until", models.DateTimeField(blank=True, null=True)),
                (
                    "related_object_id",
                    models.PositiveIntegerField(blank=True, null=True),
                ),
                (
                    "flag",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="users",
                        to="account.userflag",
                    ),
                ),
                (
                    "related_object_type",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="flags",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.AddIndex(
            model_name="userflagmembership",
            index=models.Index(
                fields=["user", "datetime_valid_from", "-datetime_valid_until"],
                name="account_use_user_id_9cb8dd_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="userflagmembership",
            index=models.Index(
                fields=["related_object_type", "related_object_id"],
                name="account_use_related_455ad8_idx",
            ),
        ),
    ]
