# Generated by Django 5.2.6 on 2025-10-12 21:31

import django.core.validators
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        (
            "content",
            "0060_remove_tuitionpayment_uniq_payment_txn_per_invoice_not_null_and_more",
        ),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="CommsLog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("when", models.DateTimeField(auto_now_add=True)),
                ("channel", models.CharField(max_length=10)),
                ("recipient", models.CharField(max_length=200)),
                ("template_slug", models.CharField(max_length=80)),
                ("status", models.CharField(max_length=12)),
                ("detail", models.TextField(blank=True)),
            ],
        ),
        migrations.CreateModel(
            name="EmailBounce",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("email", models.EmailField(max_length=254)),
                ("event", models.CharField(max_length=32)),
                ("reason", models.CharField(blank=True, max_length=120)),
                (
                    "occurred_at",
                    models.DateTimeField(default=django.utils.timezone.now),
                ),
                ("raw", models.JSONField(blank=True, default=dict)),
            ],
        ),
        migrations.CreateModel(
            name="MessageTemplate",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("slug", models.SlugField(max_length=80, unique=True)),
                (
                    "kind",
                    models.CharField(
                        choices=[("email", "Email"), ("sms", "SMS")], max_length=10
                    ),
                ),
                ("subject_template", models.CharField(blank=True, max_length=200)),
                ("body_text_template", models.TextField(blank=True)),
                ("body_html_template", models.TextField(blank=True)),
                ("is_active", models.BooleanField(default=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name="EmailOutbox",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("to", models.EmailField(max_length=254)),
                ("context", models.JSONField(blank=True, default=dict)),
                ("from_email", models.CharField(blank=True, max_length=200)),
                ("reply_to", models.CharField(blank=True, max_length=200)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("queued", "Queued"),
                            ("sending", "Sending"),
                            ("sent", "Sent"),
                            ("failed", "Failed"),
                            ("bounced", "Bounced"),
                        ],
                        default="queued",
                        max_length=12,
                    ),
                ),
                ("attempts", models.IntegerField(default=0)),
                ("last_error", models.TextField(blank=True)),
                ("provider", models.CharField(blank=True, max_length=32)),
                ("provider_ref", models.CharField(blank=True, max_length=120)),
                (
                    "scheduled_at",
                    models.DateTimeField(default=django.utils.timezone.now),
                ),
                ("sent_at", models.DateTimeField(blank=True, null=True)),
                ("next_attempt_at", models.DateTimeField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="emails_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        limit_choices_to={"kind": "email"},
                        on_delete=django.db.models.deletion.PROTECT,
                        to="content.messagetemplate",
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["status", "scheduled_at"],
                        name="content_ema_status_734cc6_idx",
                    ),
                    models.Index(
                        fields=["to", "template", "status"],
                        name="content_ema_to_63a6c3_idx",
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="SmsOutbox",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "to",
                    models.CharField(
                        max_length=20,
                        validators=[
                            django.core.validators.RegexValidator(
                                "^\\+?\\d{8,15}$",
                                "Enter a valid international phone number.",
                            )
                        ],
                    ),
                ),
                ("sender_id", models.CharField(blank=True, max_length=15)),
                ("context", models.JSONField(blank=True, default=dict)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("queued", "Queued"),
                            ("sending", "Sending"),
                            ("sent", "Sent"),
                            ("failed", "Failed"),
                            ("bounced", "Bounced"),
                        ],
                        default="queued",
                        max_length=12,
                    ),
                ),
                ("attempts", models.IntegerField(default=0)),
                ("last_error", models.TextField(blank=True)),
                ("provider", models.CharField(blank=True, max_length=32)),
                ("provider_ref", models.CharField(blank=True, max_length=120)),
                (
                    "scheduled_at",
                    models.DateTimeField(default=django.utils.timezone.now),
                ),
                ("sent_at", models.DateTimeField(blank=True, null=True)),
                ("next_attempt_at", models.DateTimeField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="sms_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        limit_choices_to={"kind": "sms"},
                        on_delete=django.db.models.deletion.PROTECT,
                        to="content.messagetemplate",
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["status", "scheduled_at"],
                        name="content_sms_status_8992db_idx",
                    ),
                    models.Index(
                        fields=["to", "template", "status"],
                        name="content_sms_to_aecf2b_idx",
                    ),
                ],
            },
        ),
    ]
