# Generated by Django 5.0.1 on 2025-10-12 10:42

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


class Migration(migrations.Migration):

    dependencies = [
        ("billing", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="PaymentWebhook",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("received_at", models.DateTimeField(auto_now_add=True)),
                ("processed_at", models.DateTimeField(blank=True, null=True)),
                (
                    "processing_status",
                    models.CharField(
                        choices=[
                            ("received", "Received"),
                            ("processed", "Processed Successfully"),
                            ("failed", "Processing Failed"),
                            ("ignored", "Ignored"),
                        ],
                        default="received",
                        max_length=20,
                    ),
                ),
                ("processing_error", models.TextField(blank=True)),
                (
                    "event_type",
                    models.CharField(
                        choices=[
                            ("PAYMENT RECEIVED", "Payment Received"),
                            ("PAYMENT FAILED", "Payment Failed"),
                            ("PAYMENT PENDING", "Payment Pending"),
                            ("PAYMENT CANCELLED", "Payment Cancelled"),
                            ("OTHER", "Other"),
                        ],
                        default="OTHER",
                        max_length=50,
                    ),
                ),
                ("order_reference", models.CharField(db_index=True, max_length=100)),
                (
                    "transaction_id",
                    models.CharField(blank=True, max_length=100, null=True),
                ),
                ("payment_status", models.CharField(blank=True, max_length=50)),
                ("channel", models.CharField(blank=True, max_length=50)),
                (
                    "amount",
                    models.DecimalField(
                        blank=True, decimal_places=2, max_digits=10, null=True
                    ),
                ),
                ("raw_payload", models.JSONField()),
                ("source_ip", models.GenericIPAddressField(blank=True, null=True)),
                ("user_agent", models.TextField(blank=True)),
                (
                    "payment",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="webhook_logs",
                        to="billing.payment",
                    ),
                ),
            ],
            options={
                "ordering": ["-received_at"],
                "indexes": [
                    models.Index(
                        fields=["order_reference", "-received_at"],
                        name="billing_pay_order_r_700b9a_idx",
                    ),
                    models.Index(
                        fields=["event_type", "-received_at"],
                        name="billing_pay_event_t_5e55bc_idx",
                    ),
                    models.Index(
                        fields=["processing_status", "-received_at"],
                        name="billing_pay_process_4a82ed_idx",
                    ),
                ],
            },
        ),
    ]
