# Generated by Django 3.2.17 on 2023-02-15 15:24

import agir.lib.form_fields
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import dynamic_filenames
import uuid


class Migration(migrations.Migration):
    dependencies = [
        ("events", "0023_event_location_departement_id"),
        ("event_requests", "0002_event_theme_calendar_and_email_fields"),
    ]

    operations = [
        migrations.CreateModel(
            name="EventAssetTemplate",
            fields=[
                (
                    "created",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        editable=False,
                        verbose_name="date de création",
                    ),
                ),
                (
                    "modified",
                    models.DateTimeField(
                        auto_now=True, verbose_name="dernière modification"
                    ),
                ),
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="UUID interne à l'API pour identifier la ressource",
                        primary_key=True,
                        serialize=False,
                        verbose_name="UUID",
                    ),
                ),
                ("name", models.CharField(max_length=200, verbose_name="Nom")),
                (
                    "file",
                    models.FileField(
                        help_text="Le fichier doit être au format SVG et contenir des variables correspondantes aux données d'un événement (au format: {{ nom_de_la_variable }})",
                        max_length=255,
                        upload_to=dynamic_filenames.FilePattern(
                            filename_pattern="{app_label}/{model_name}/{instance.id}/{uuid:.8base32}{ext}"
                        ),
                        validators=[
                            django.core.validators.FileExtensionValidator(["svg"])
                        ],
                        verbose_name="Fichier",
                    ),
                ),
            ],
            options={
                "verbose_name": "Template de visuel",
                "verbose_name_plural": "Templates de visuels",
            },
        ),
        migrations.CreateModel(
            name="EventAsset",
            fields=[
                (
                    "created",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        editable=False,
                        verbose_name="date de création",
                    ),
                ),
                (
                    "modified",
                    models.DateTimeField(
                        auto_now=True, verbose_name="dernière modification"
                    ),
                ),
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="UUID interne à l'API pour identifier la ressource",
                        primary_key=True,
                        serialize=False,
                        verbose_name="UUID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        editable=False, max_length=200, verbose_name="Nom"
                    ),
                ),
                (
                    "file",
                    models.FileField(
                        editable=False,
                        max_length=255,
                        upload_to=dynamic_filenames.FilePattern(
                            filename_pattern="{app_label}/{model_name}/{instance.id}/{uuid:.8base32}{ext}"
                        ),
                        validators=[
                            django.core.validators.FileExtensionValidator(["pdf"])
                        ],
                        verbose_name="Fichier",
                    ),
                ),
                (
                    "extra_data",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        encoder=agir.lib.form_fields.CustomJSONEncoder,
                        help_text="Les données qui seront utilisées, en plus de celles de l'événement, pour générer le visuel",
                        verbose_name="Données supplémentaires",
                    ),
                ),
                (
                    "event",
                    models.ForeignKey(
                        editable=False,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="event_assets",
                        related_query_name="event_asset",
                        to="events.event",
                        verbose_name="événement",
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to="event_requests.eventassettemplate",
                        verbose_name="template",
                    ),
                ),
            ],
            options={
                "verbose_name": "Visuel de l'événement",
                "verbose_name_plural": "Visuels des événements",
            },
        ),
        migrations.AddField(
            model_name="eventtheme",
            name="event_asset_templates",
            field=models.ManyToManyField(
                blank=True,
                related_name="event_themes",
                related_query_name="event_theme",
                to="event_requests.EventAssetTemplate",
            ),
        ),
        migrations.AddField(
            model_name="eventthemetype",
            name="event_asset_templates",
            field=models.ManyToManyField(
                blank=True,
                related_name="event_theme_types",
                related_query_name="event_theme_type",
                to="event_requests.EventAssetTemplate",
            ),
        ),
        migrations.AddConstraint(
            model_name="eventasset",
            constraint=models.UniqueConstraint(
                fields=("event", "template"),
                name="unique_event_asset_for_event_and_template",
            ),
        ),
    ]
