# Generated by Django 4.2.13 on 2024-06-08 17:50

import django.core.serializers.json
import django.db.models.deletion
import django.db.models.functions.text
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models

import users.models.user


class Migration(migrations.Migration):
    """
    This migration is a combination of all the migrations til 0.10.0
    """

    replaces = [
        ("users", "0001_initial"),
        ("users", "0002_preference_default_no_share"),
        ("users", "0003_preference_discover_layout"),
        ("users", "0004_alter_preference_classic_homepage"),
        ("users", "0005_add_dedicated_username"),
        ("users", "0006_unique_email"),
        ("users", "0007_user_pending_email"),
        ("users", "0008_user_at_least_one_login_method"),
        ("users", "0007_username_case_insensitive"),
        ("users", "0009_add_local_follow"),
        ("users", "0010_add_local_mute_block"),
        ("users", "0011_preference_hidden_categories"),
        ("users", "0015_user_mastodon_last_reachable"),
        ("users", "0012_apidentity"),
        ("users", "0013_init_identity"),
        ("users", "0014_preference_mastodon_skip_relationship_and_more"),
        ("users", "0015_remove_preference_mastodon_publish_public_and_more"),
        ("users", "0016_rename_preference_default_no_share"),
        ("users", "0017_mastodon_site_username_bd2db5_idx"),
        ("users", "0018_apidentity_anonymous_viewable"),
        ("users", "0019_task"),
        ("users", "0020_user_language"),
        ("users", "0021_alter_user_language"),
    ]
    initial = True

    dependencies = [
        ("takahe", "0001_initial"),
        ("auth", "0012_alter_user_first_name_max_length"),
    ]

    operations = [
        migrations.CreateModel(
            name="User",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("password", models.CharField(max_length=128, verbose_name="password")),
                (
                    "last_login",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="last login"
                    ),
                ),
                (
                    "is_superuser",
                    models.BooleanField(
                        default=False,
                        help_text="Designates that this user has all permissions without explicitly assigning them.",
                        verbose_name="superuser status",
                    ),
                ),
                (
                    "first_name",
                    models.CharField(
                        blank=True, max_length=150, verbose_name="first name"
                    ),
                ),
                (
                    "last_name",
                    models.CharField(
                        blank=True, max_length=150, verbose_name="last name"
                    ),
                ),
                (
                    "email",
                    models.EmailField(
                        default=None,
                        max_length=254,
                        null=True,
                        unique=True,
                        verbose_name="email address",
                    ),
                ),
                (
                    "is_staff",
                    models.BooleanField(
                        default=False,
                        help_text="Designates whether the user can log into this admin site.",
                        verbose_name="staff status",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True,
                        help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
                        verbose_name="active",
                    ),
                ),
                (
                    "date_joined",
                    models.DateTimeField(
                        default=django.utils.timezone.now, verbose_name="date joined"
                    ),
                ),
                (
                    "username",
                    models.CharField(
                        error_messages={
                            "unique": "A user with that username already exists."
                        },
                        help_text="Required. 50 characters or fewer. Letters, digits and _ only.",
                        max_length=100,
                        null=True,
                        unique=True,
                        validators=[users.models.user.UsernameValidator()],
                        verbose_name="username",
                    ),
                ),
                ("following", models.JSONField(default=list)),
                (
                    "mastodon_id",
                    models.CharField(default=None, max_length=100, null=True),
                ),
                (
                    "mastodon_site",
                    models.CharField(default=None, max_length=100, null=True),
                ),
                ("mastodon_token", models.CharField(default="", max_length=2048)),
                (
                    "mastodon_refresh_token",
                    models.CharField(default="", max_length=2048),
                ),
                ("mastodon_locked", models.BooleanField(default=False)),
                ("mastodon_followers", models.JSONField(default=list)),
                ("mastodon_following", models.JSONField(default=list)),
                ("mastodon_mutes", models.JSONField(default=list)),
                ("mastodon_blocks", models.JSONField(default=list)),
                ("mastodon_domain_blocks", models.JSONField(default=list)),
                ("mastodon_account", models.JSONField(default=dict)),
                (
                    "mastodon_last_refresh",
                    models.DateTimeField(default=django.utils.timezone.now),
                ),
                ("read_announcement_index", models.PositiveIntegerField(default=0)),
                (
                    "groups",
                    models.ManyToManyField(
                        blank=True,
                        help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
                        related_name="user_set",
                        related_query_name="user",
                        to="auth.group",
                        verbose_name="groups",
                    ),
                ),
                (
                    "user_permissions",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Specific permissions for this user.",
                        related_name="user_set",
                        related_query_name="user",
                        to="auth.permission",
                        verbose_name="user permissions",
                    ),
                ),
                (
                    "mastodon_username",
                    models.CharField(default=None, max_length=100, null=True),
                ),
                (
                    "pending_email",
                    models.EmailField(
                        default=None,
                        max_length=254,
                        null=True,
                        verbose_name="email address pending verification",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Preference",
            fields=[
                (
                    "user",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        primary_key=True,
                        serialize=False,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                ("profile_layout", models.JSONField(blank=True, default=list)),
                (
                    "export_status",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        encoder=django.core.serializers.json.DjangoJSONEncoder,
                        null=True,
                    ),
                ),
                (
                    "import_status",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        encoder=django.core.serializers.json.DjangoJSONEncoder,
                        null=True,
                    ),
                ),
                ("default_visibility", models.PositiveSmallIntegerField(default=0)),
                ("classic_homepage", models.PositiveSmallIntegerField(default=0)),
                ("mastodon_publish_public", models.BooleanField(default=False)),
                ("mastodon_append_tag", models.CharField(default="", max_length=2048)),
                ("show_last_edit", models.PositiveSmallIntegerField(default=0)),
                ("no_anonymous_view", models.PositiveSmallIntegerField(default=0)),
                ("default_no_share", models.BooleanField(default=False)),
                ("discover_layout", models.JSONField(blank=True, default=list)),
            ],
        ),
        migrations.AddConstraint(
            model_name="user",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("is_active", False),
                    ("mastodon_username__isnull", False),
                    ("email__isnull", False),
                    _connector="OR",
                ),
                name="at_least_one_login_method",
            ),
        ),
        migrations.AddConstraint(
            model_name="user",
            constraint=models.UniqueConstraint(
                django.db.models.functions.text.Lower("email"), name="unique_email"
            ),
        ),
        migrations.AddConstraint(
            model_name="user",
            constraint=models.UniqueConstraint(
                django.db.models.functions.text.Lower("username"),
                name="unique_username",
            ),
        ),
        migrations.AddConstraint(
            model_name="user",
            constraint=models.UniqueConstraint(
                django.db.models.functions.text.Lower("mastodon_username"),
                django.db.models.functions.text.Lower("mastodon_site"),
                name="unique_mastodon_username",
            ),
        ),
        migrations.AddConstraint(
            model_name="user",
            constraint=models.UniqueConstraint(
                django.db.models.functions.text.Lower("mastodon_id"),
                django.db.models.functions.text.Lower("mastodon_site"),
                name="unique_mastodon_id",
            ),
        ),
        migrations.CreateModel(
            name="Follow",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_time", models.DateTimeField(auto_now_add=True)),
                ("edited_time", models.DateTimeField(auto_now=True)),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "target",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="user",
            name="local_following",
            field=models.ManyToManyField(
                related_name="local_followers",
                through="users.Follow",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="user",
            name="muting",
            field=models.JSONField(default=list),
        ),
        migrations.AddField(
            model_name="user",
            name="rejecting",
            field=models.JSONField(default=list),
        ),
        migrations.CreateModel(
            name="Mute",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_time", models.DateTimeField(auto_now_add=True)),
                ("edited_time", models.DateTimeField(auto_now=True)),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "target",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Block",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_time", models.DateTimeField(auto_now_add=True)),
                ("edited_time", models.DateTimeField(auto_now=True)),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "target",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="user",
            name="local_blocking",
            field=models.ManyToManyField(
                related_name="local_blocked_by",
                through="users.Block",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="user",
            name="local_muting",
            field=models.ManyToManyField(
                related_name="+", through="users.Mute", to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.AddField(
            model_name="preference",
            name="hidden_categories",
            field=models.JSONField(default=list),
        ),
        migrations.AddField(
            model_name="user",
            name="mastodon_last_reachable",
            field=models.DateTimeField(default=django.utils.timezone.now),
        ),
        migrations.CreateModel(
            name="APIdentity",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("local", models.BooleanField()),
                ("username", models.CharField(blank=True, max_length=500, null=True)),
                (
                    "domain_name",
                    models.CharField(blank=True, max_length=500, null=True),
                ),
                ("deleted", models.DateTimeField(blank=True, null=True)),
                (
                    "user",
                    models.OneToOneField(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="identity",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["local", "username"],
                        name="users_apide_local_2d8170_idx",
                    ),
                    models.Index(
                        fields=["domain_name", "username"],
                        name="users_apide_domain__53ffa5_idx",
                    ),
                ],
            },
        ),
        migrations.AddField(
            model_name="preference",
            name="mastodon_skip_relationship",
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name="preference",
            name="mastodon_skip_userinfo",
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name="preference",
            name="mastodon_repost_mode",
            field=models.PositiveSmallIntegerField(default=0),
        ),
        migrations.AddField(
            model_name="preference",
            name="post_public_mode",
            field=models.PositiveSmallIntegerField(default=0),
        ),
        migrations.AlterField(
            model_name="preference",
            name="show_last_edit",
            field=models.PositiveSmallIntegerField(default=1),
        ),
        migrations.RemoveField(
            model_name="preference",
            name="mastodon_publish_public",
        ),
        migrations.AddField(
            model_name="preference",
            name="mastodon_default_repost",
            field=models.BooleanField(default=True),
        ),
        migrations.RemoveField(
            model_name="preference",
            name="default_no_share",
        ),
        migrations.AddIndex(
            model_name="user",
            index=models.Index(
                fields=["mastodon_site", "mastodon_username"],
                name="users_user_mastodo_bd2db5_idx",
            ),
        ),
        migrations.AddField(
            model_name="apidentity",
            name="anonymous_viewable",
            field=models.BooleanField(default=True),
        ),
        migrations.CreateModel(
            name="Task",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("type", models.CharField(max_length=20)),
                (
                    "state",
                    models.IntegerField(
                        choices=[
                            (0, "Pending"),
                            (1, "Started"),
                            (2, "Complete"),
                            (3, "Failed"),
                        ],
                        default=0,
                    ),
                ),
                ("metadata", models.JSONField(default=dict)),
                ("message", models.TextField(default="")),
                ("created_time", models.DateTimeField(auto_now_add=True)),
                ("edited_time", models.DateTimeField(auto_now=True)),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["user", "type"], name="users_task_user_id_e29f34_idx"
                    )
                ],
            },
        ),
        migrations.AddField(
            model_name="user",
            name="language",
            field=models.CharField(
                choices=[
                    ("en", "English"),
                    ("zh-hans", "Simplified Chinese"),
                    ("zh-hant", "Traditional Chinese"),
                    ("da", "Danish"),
                ],
                default="en",
                max_length=10,
                verbose_name="language",
            ),
        ),
    ]
