from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ("accounts", "0008_populate_mobile_country"),
        ("tenants", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="OtpSendLog",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("mobile", models.CharField(db_index=True, max_length=20, verbose_name="mobile")),
                ("provider", models.CharField(blank=True, default="", max_length=64, verbose_name="provider")),
                (
                    "status",
                    models.CharField(
                        choices=[("sent", "Sent"), ("failed", "Failed")],
                        db_index=True,
                        default="sent",
                        max_length=10,
                        verbose_name="status",
                    ),
                ),
                ("error_message", models.TextField(blank=True, default="", verbose_name="error message")),
                ("ip_address", models.GenericIPAddressField(blank=True, null=True, verbose_name="IP address")),
                (
                    "otp_token",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="send_logs",
                        to="accounts.mobileotptoken",
                        verbose_name="OTP token",
                    ),
                ),
                (
                    "tenant",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to="tenants.tenant",
                        verbose_name="tenant",
                    ),
                ),
            ],
            options={
                "verbose_name": "OTP send log",
                "verbose_name_plural": "OTP send logs",
                "ordering": ["-created_at"],
            },
        ),
        migrations.AddIndex(
            model_name="otpsendlog",
            index=models.Index(fields=["mobile", "-created_at"], name="accounts_ot_mobile_idx"),
        ),
    ]
