# Generated by Django 4.1.5 on 2023-01-27 14:38

import django.contrib.postgres.indexes
import django.contrib.postgres.search
from django.db import migrations, models
import django.db.models.deletion
import django.db.models.functions.text
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
        ("aids", "0173_aid_import_updated"),
        ("organizations", "0009_organization_imported_date_organization_is_imported"),
        ("backers", "0015_backer_perimeter"),
        ("projects", "0015_project_image"),
    ]

    operations = [
        migrations.AlterField(
            model_name="project",
            name="due_date",
            field=models.DateField(
                blank=True, null=True, verbose_name="Date d’échéance"
            ),
        ),
        migrations.AlterField(
            model_name="project",
            name="other_project_owner",
            field=models.CharField(
                blank=True,
                max_length=180,
                null=True,
                verbose_name="Autre maître d’ouvrage",
            ),
        ),
        migrations.CreateModel(
            name="ValidatedProject",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "project_name",
                    models.CharField(max_length=255, verbose_name="Nom du projet"),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True, default="", verbose_name="Description du projet"
                    ),
                ),
                (
                    "aid_name",
                    models.CharField(max_length=180, verbose_name="Nom de l’aide"),
                ),
                (
                    "financer_name",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=255,
                        verbose_name="Nom du porteur de l’aide obtenue",
                    ),
                ),
                (
                    "budget",
                    models.PositiveIntegerField(
                        blank=True, null=True, verbose_name="Budget définitif"
                    ),
                ),
                (
                    "amount_obtained",
                    models.PositiveIntegerField(
                        blank=True, null=True, verbose_name="Montant obtenu"
                    ),
                ),
                (
                    "date_obtained",
                    models.DateTimeField(
                        blank=True,
                        help_text="Date à laquelle l’aide a été obtenue par le porteur du projet",
                        null=True,
                        verbose_name="Date de l’obtention",
                    ),
                ),
                (
                    "date_created",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        verbose_name="Date de création",
                    ),
                ),
                (
                    "search_vector_unaccented_validated_project",
                    django.contrib.postgres.search.SearchVectorField(
                        null=True,
                        verbose_name="Search vector unaccented_validated_project",
                    ),
                ),
                (
                    "import_uniqueid",
                    models.CharField(
                        blank=True,
                        max_length=64,
                        null=True,
                        unique=True,
                        verbose_name="Identifiant d’import unique",
                    ),
                ),
                (
                    "aid_linked",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="aids.aid",
                        verbose_name="Aide liée",
                    ),
                ),
                (
                    "financer_linked",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="backers.backer",
                        verbose_name="Porteur d’aides lié",
                    ),
                ),
                (
                    "organization",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="organizations.organization",
                        verbose_name="Organisation porteuse",
                    ),
                ),
                (
                    "project_linked",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="projects.project",
                        verbose_name="Projet lié",
                    ),
                ),
            ],
            options={
                "verbose_name": "Projet subventionné",
                "verbose_name_plural": "Projets subventionnés",
                "ordering": ["project_name"],
            },
        ),
        migrations.AddIndex(
            model_name="validatedproject",
            index=django.contrib.postgres.indexes.GinIndex(
                fields=["search_vector_unaccented_validated_project"],
                name="projects_va_search__8f658c_gin",
            ),
        ),
        migrations.AddConstraint(
            model_name="validatedproject",
            constraint=models.UniqueConstraint(
                django.db.models.functions.text.Lower("project_name"),
                django.db.models.functions.text.Lower("aid_name"),
                models.F("financer_name"),
                models.F("amount_obtained"),
                models.F("date_obtained"),
                name="unique_projectname_aidname_financername_amount_date",
            ),
        ),
    ]
