# Generated by Django 4.2.4 on 2023-10-05 07:54
from gettext import gettext

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

from django_project_base.constants import INVITE_NOTIFICATION_TEXT


def forwards_func(apps, schema_editor):
    project_sett = apps.get_model("demo_django_base", "ProjectSettings")
    for project in apps.get_model("demo_django_base", "Project").objects.all():
        if not project_sett.objects.filter(
            project=project,
            name=INVITE_NOTIFICATION_TEXT,
        ).exists():
            project_sett.objects.create(
                project=project,
                name=INVITE_NOTIFICATION_TEXT,
                description=gettext(
                    "Text for invite notification view. __LINK__ is url to invite confirmation placeholder."
                ),
                value=gettext("Click link to join project: __LINK__"),
                value_type="char",
            )


def reverse_func(apps, schema_editor):
    pass


class Migration(migrations.Migration):
    dependencies = [
        ("demo_django_base", "0007_merge_20230927_0554"),
    ]

    operations = [
        migrations.CreateModel(
            name="ProjectInvite",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        primary_key=True,
                        serialize=False,
                        verbose_name="Id",
                    ),
                ),
                ("email", models.CharField(max_length=255, verbose_name="eMail")),
                (
                    "text",
                    models.TextField(null=True, verbose_name="Invitation message"),
                ),
                ("accepted", models.DateTimeField(blank=True, null=True)),
                (
                    "invited_by",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="project_user_invites",
                        to=settings.DJANGO_PROJECT_BASE_PROFILE_MODEL,
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.DJANGO_PROJECT_BASE_PROJECT_MODEL,
                    ),
                ),
                (
                    "role",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.DJANGO_PROJECT_BASE_ROLE_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
                "unique_together": {("project", "email")},
            },
        ),
        migrations.RunPython(forwards_func, reverse_func),
    ]
