# Generated by Django 4.2.17 on 2026-01-21 19:55

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


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="BrevoMessage",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("subject", models.TextField()),
                ("sent_date", models.DateField(db_index=True)),
                ("total_sent", models.IntegerField(default=0)),
                ("total_delivered", models.IntegerField(default=0)),
                ("total_opened", models.IntegerField(default=0)),
                ("total_clicked", models.IntegerField(default=0)),
                ("total_bounced", models.IntegerField(default=0)),
                ("total_blocked", models.IntegerField(default=0)),
                ("delivery_rate", models.FloatField(default=0.0)),
                ("open_rate", models.FloatField(default=0.0)),
                ("click_rate", models.FloatField(default=0.0)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Brevo Message",
                "verbose_name_plural": "Brevo Messages",
                "db_table": "brevo_messages",
                "ordering": ["-sent_date", "subject"],
            },
        ),
        migrations.CreateModel(
            name="Email",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "brevo_message_id",
                    models.CharField(
                        db_index=True,
                        help_text="Brevo's unique message ID (e.g., <123456@smtp-relay.mailin.fr>)",
                        max_length=255,
                        unique=True,
                    ),
                ),
                ("recipient_email", models.EmailField(db_index=True, max_length=254)),
                ("sent_at", models.DateTimeField(db_index=True)),
                (
                    "events",
                    models.JSONField(
                        default=list,
                        help_text="Array of events: [{type, timestamp, ...extra_data}]",
                    ),
                ),
                (
                    "current_status",
                    models.CharField(
                        choices=[
                            ("sent", "Sent"),
                            ("delivered", "Delivered"),
                            ("opened", "Opened"),
                            ("clicked", "Clicked"),
                            ("bounced", "Bounced"),
                            ("blocked", "Blocked"),
                            ("deferred", "Deferred"),
                            ("unsubscribed", "Unsubscribed"),
                        ],
                        db_index=True,
                        default="sent",
                        max_length=20,
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "message",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="emails",
                        to="brevo_analytics.brevomessage",
                    ),
                ),
            ],
            options={
                "verbose_name": "Email",
                "verbose_name_plural": "Emails",
                "db_table": "brevo_emails",
                "ordering": ["-sent_at"],
            },
        ),
        migrations.AddIndex(
            model_name="brevomessage",
            index=models.Index(
                fields=["-sent_date"], name="brevo_messa_sent_da_aadce7_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="brevomessage",
            index=models.Index(
                fields=["subject", "sent_date"], name="brevo_messa_subject_3dc23c_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="brevomessage",
            unique_together={("subject", "sent_date")},
        ),
        migrations.AddIndex(
            model_name="email",
            index=models.Index(
                fields=["message", "-sent_at"], name="brevo_email_message_aeea8e_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="email",
            index=models.Index(
                fields=["recipient_email"], name="brevo_email_recipie_d4ea6a_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="email",
            index=models.Index(
                fields=["current_status"], name="brevo_email_current_aef117_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="email",
            index=models.Index(
                fields=["brevo_message_id"], name="brevo_email_brevo_m_343c18_idx"
            ),
        ),
    ]
