# Generated by Django 4.2.4 on 2023-08-18 14:42
import copy

from django.conf import settings
import django.contrib.auth.models
import django.core.validators
from django.contrib.auth.hashers import make_password
from django.db import migrations, models
import django.db.models.deletion
import django_project_base.base.fields
import re
import taggit.managers

from django_project_base.settings import TEST_USER_ONE_DATA, TEST_USER_TWO_DATA


def forwards_func(apps, schema_editor):
    ProjectModel = apps.get_model("demo_django_base", "Project")
    UserProfileModel = apps.get_model("demo_django_base", "UserProfile")
    db_alias = schema_editor.connection.alias
    user_one_data: dict = copy.copy(TEST_USER_ONE_DATA)
    user_two_data: dict = copy.copy(TEST_USER_TWO_DATA)
    user_one_data.update(dict(password=make_password(TEST_USER_ONE_DATA["password"])))
    user_two_data.update(dict(password=make_password(TEST_USER_TWO_DATA["password"])))
    user1 = UserProfileModel.objects.using(db_alias).create(**user_one_data)
    user2 = UserProfileModel.objects.using(db_alias).create(**user_two_data)
    ProjectModel.objects.using(db_alias).bulk_create(
        [
            ProjectModel(name="Project One", slug="project-one", description="project one description", owner=user1),
            ProjectModel(name="Project Two", slug="project-two", description="project two description", owner=user2),
            ProjectModel(
                name="Project Three", slug="project-three", description="project three description", owner=user2
            ),
            ProjectModel(name="Project Four", slug="project-four", description="project four description", owner=user1),
        ]
    )


def reverse_func(apps, schema_editor):
    pass


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        ("auth", "0012_alter_user_first_name_max_length"),
    ]

    operations = [
        migrations.CreateModel(
            name="DemoProjectTag",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(max_length=100, unique=True, verbose_name="name"),
                ),
                (
                    "slug",
                    models.SlugField(
                        allow_unicode=True,
                        max_length=100,
                        unique=True,
                        verbose_name="slug",
                    ),
                ),
                (
                    "color",
                    django_project_base.base.fields.HexColorField(max_length=7, verbose_name="Color"),
                ),
                (
                    "icon",
                    models.CharField(blank=True, max_length=10, null=True, verbose_name="Icon"),
                ),
                ("content", models.CharField(blank=True, max_length=20, null=True)),
            ],
            options={
                "verbose_name": "Tag",
                "verbose_name_plural": "Tags",
            },
        ),
        migrations.CreateModel(
            name="Permission",
            fields=[
                (
                    "permission_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="auth.permission",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
            bases=("auth.permission",),
            managers=[
                ("objects", django.contrib.auth.models.PermissionManager()),
            ],
        ),
        migrations.CreateModel(
            name="Project",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(db_index=True, max_length=80, verbose_name="Name"),
                ),
                ("slug", models.SlugField(max_length=80, verbose_name="Slug")),
                (
                    "description",
                    models.TextField(blank=True, null=True, verbose_name="Description"),
                ),
                (
                    "logo",
                    models.FileField(blank=True, null=True, upload_to="", verbose_name="Logo"),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Role",
            fields=[
                (
                    "group_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="auth.group",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
            bases=("auth.group",),
            managers=[
                ("objects", django.contrib.auth.models.GroupManager()),
            ],
        ),
        migrations.CreateModel(
            name="UserProfile",
            fields=[
                (
                    "user_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "bio",
                    models.TextField(blank=True, max_length=500, null=True, verbose_name="Bio"),
                ),
                (
                    "phone_number",
                    models.CharField(
                        blank=True,
                        max_length=20,
                        null=True,
                        verbose_name="Phone number",
                    ),
                ),
                (
                    "language",
                    models.CharField(blank=True, max_length=10, null=True, verbose_name="Language"),
                ),
                (
                    "theme",
                    models.CharField(blank=True, max_length=10, null=True, verbose_name="Theme"),
                ),
                (
                    "avatar",
                    models.FileField(blank=True, null=True, upload_to="", verbose_name="Avatar"),
                ),
                (
                    "reverse_full_name_order",
                    models.BooleanField(blank=True, null=True, verbose_name="Reverse full name order"),
                ),
                (
                    "delete_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="Delete profile at"),
                ),
                ("password_invalid", models.BooleanField(default=False)),
            ],
            options={
                "abstract": False,
            },
            bases=("auth.user",),
            managers=[
                ("objects", django.contrib.auth.models.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name="ProjectMember",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "member",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="projects",
                        to=settings.DJANGO_PROJECT_BASE_PROFILE_MODEL,
                        verbose_name="Owner",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="members",
                        to=settings.DJANGO_PROJECT_BASE_PROJECT_MODEL,
                        verbose_name="Project",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.AddField(
            model_name="project",
            name="owner",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="user_profiles",
                to=settings.DJANGO_PROJECT_BASE_PROFILE_MODEL,
            ),
        ),
        migrations.CreateModel(
            name="MergeUserGroup",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "users",
                    models.CharField(
                        max_length=1024,
                        validators=[
                            django.core.validators.RegexValidator(
                                re.compile("^\\d+(?:,\\d+)*\\Z"),
                                code="invalid",
                                message="Enter only digits separated by commas.",
                            )
                        ],
                    ),
                ),
                ("created_by", models.PositiveIntegerField()),
                (
                    "project",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.DJANGO_PROJECT_BASE_PROJECT_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="DpbTaggedItemThroughDemo",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "object_id",
                    models.IntegerField(db_index=True, verbose_name="object ID"),
                ),
                ("main_object", models.BooleanField(default=False)),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="%(app_label)s_%(class)s_tagged_items",
                        to="contenttypes.contenttype",
                        verbose_name="content type",
                    ),
                ),
                (
                    "tag",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="%(app_label)s_%(class)s_items",
                        to=settings.DJANGO_PROJECT_BASE_TAG_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.AddField(
            model_name="demoprojecttag",
            name="project",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to=settings.DJANGO_PROJECT_BASE_PROJECT_MODEL,
                verbose_name="Project",
            ),
        ),
        migrations.CreateModel(
            name="Apartment",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("number", models.IntegerField()),
                (
                    "tags",
                    taggit.managers.TaggableManager(
                        help_text="A comma-separated list of tags.",
                        through="demo_django_base.DpbTaggedItemThroughDemo",
                        to="demo_django_base.DemoProjectTag",
                        verbose_name="Tags",
                    ),
                ),
            ],
        ),
        migrations.RunPython(forwards_func, reverse_func),
    ]
