# Generated by Django 5.2.9 on 2025-12-08 15:24

import uuid
from decimal import Decimal

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


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="Payment",
            fields=[
                (
                    "ecommerce_id",
                    models.UUIDField(
                        help_text="Unique ecommerce transaction identifier",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "reference_number",
                    models.CharField(
                        help_text="ATH Móvil reference number for completed transactions",
                        max_length=255,
                        unique=True,
                    ),
                ),
                (
                    "daily_transaction_id",
                    models.CharField(
                        blank=True,
                        help_text="ATH Móvil daily transaction ID",
                        max_length=10,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("OPEN", "Open (Pending Customer Confirmation)"),
                            ("CONFIRM", "Confirmed (Pending Authorization)"),
                            ("COMPLETED", "Completed"),
                            ("CANCEL", "Cancelled"),
                            ("EXPIRED", "Expired"),
                        ],
                        db_index=True,
                        default="OPEN",
                        max_length=16,
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("modified", models.DateTimeField(auto_now=True)),
                (
                    "transaction_date",
                    models.DateTimeField(
                        blank=True,
                        help_text="Transaction completion date from ATH Móvil",
                        null=True,
                    ),
                ),
                (
                    "total",
                    models.DecimalField(
                        decimal_places=2,
                        help_text="Total transaction amount",
                        max_digits=10,
                    ),
                ),
                (
                    "subtotal",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0.00"),
                        help_text="Subtotal before tax",
                        max_digits=10,
                    ),
                ),
                (
                    "tax",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0.00"),
                        help_text="Tax amount",
                        max_digits=10,
                    ),
                ),
                (
                    "fee",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0.00"),
                        help_text="ATH Móvil processing fee",
                        max_digits=10,
                    ),
                ),
                (
                    "net_amount",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0.00"),
                        help_text="Amount after possible fees",
                        max_digits=7,
                    ),
                ),
                (
                    "total_refunded_amount",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0.00"),
                        help_text="Amount refunded",
                        max_digits=10,
                    ),
                ),
                (
                    "customer_name",
                    models.CharField(
                        blank=True,
                        help_text="Customer name from ATH Móvil at the time of payment",
                        max_length=255,
                    ),
                ),
                (
                    "customer_phone",
                    models.CharField(
                        blank=True,
                        help_text="Customer phone number from ATH Móvil at the time of payment",
                        max_length=32,
                    ),
                ),
                (
                    "customer_email",
                    models.EmailField(
                        blank=True,
                        help_text="Customer phone number from ATH Móvil at the time of payment",
                        max_length=254,
                    ),
                ),
                ("metadata_1", models.CharField(blank=True, max_length=64, null=True)),
                ("metadata_2", models.CharField(blank=True, max_length=64, null=True)),
                ("message", models.TextField(blank=True, null=True)),
                (
                    "business_name",
                    models.CharField(
                        blank=True,
                        help_text="Business name from ATH Móvil",
                        max_length=255,
                    ),
                ),
            ],
            options={
                "db_table": "athm_payment",
                "verbose_name": "ATH Móvil Transaction",
                "verbose_name_plural": "ATH Móvil Transactions",
                "ordering": ["-created"],
                "indexes": [
                    models.Index(fields=["-created"], name="athm_payment_created_idx"),
                    models.Index(
                        fields=["status", "-created"], name="athm_payment_status_idx"
                    ),
                    models.Index(
                        fields=["reference_number"], name="athm_payment_ref_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="PaymentLineItem",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("name", models.CharField(help_text="Item name", max_length=128)),
                (
                    "description",
                    models.TextField(blank=True, help_text="Item description"),
                ),
                ("quantity", models.PositiveSmallIntegerField(default=1)),
                (
                    "price",
                    models.DecimalField(
                        decimal_places=2, help_text="Item price", max_digits=10
                    ),
                ),
                (
                    "tax",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0.00"),
                        help_text="Item tax",
                        max_digits=10,
                    ),
                ),
                ("metadata", models.CharField(blank=True, max_length=64)),
                (
                    "transaction",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="items",
                        related_query_name="item",
                        to="django_athm.payment",
                    ),
                ),
            ],
            options={
                "db_table": "athm_payment_item",
                "verbose_name": "ATH Móvil Payment Line Item",
                "verbose_name_plural": "ATH Móvil Payment Line Items",
            },
        ),
        migrations.CreateModel(
            name="Refund",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4, primary_key=True, serialize=False
                    ),
                ),
                ("reference_number", models.CharField(max_length=255, unique=True)),
                (
                    "daily_transaction_id",
                    models.CharField(
                        blank=True,
                        help_text="ATH Móvil daily transaction ID",
                        max_length=10,
                    ),
                ),
                ("amount", models.DecimalField(decimal_places=2, max_digits=7)),
                ("message", models.CharField(blank=True, max_length=50)),
                ("status", models.CharField(default="COMPLETED", max_length=20)),
                ("customer_name", models.CharField(blank=True, max_length=255)),
                ("customer_phone", models.CharField(blank=True, max_length=20)),
                ("customer_email", models.EmailField(blank=True, max_length=254)),
                ("transaction_date", models.DateTimeField()),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "payment",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="refunds",
                        to="django_athm.payment",
                    ),
                ),
            ],
            options={
                "db_table": "athm_refund",
                "verbose_name": "ATH Móvil Refund",
                "verbose_name_plural": "ATH Móvil Refunds",
            },
        ),
        migrations.CreateModel(
            name="WebhookEvent",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4, primary_key=True, serialize=False
                    ),
                ),
                (
                    "idempotency_key",
                    models.CharField(db_index=True, max_length=64, unique=True),
                ),
                (
                    "event_type",
                    models.CharField(
                        choices=[
                            ("simulated", "Payment Simulation"),
                            ("payment", "Payment Received"),
                            ("donation", "Donation Received"),
                            ("refund", "Refund Sent"),
                            ("ecommerce_completed", "eCommerce Payment Completed"),
                            ("ecommerce_cancelled", "eCommerce Payment Cancelled"),
                            ("ecommerce_expired", "eCommerce Payment Expired"),
                            ("unknown", "Unknown"),
                        ],
                        default="unknown",
                        help_text="Type of webhook event",
                        max_length=64,
                    ),
                ),
                (
                    "remote_ip",
                    models.GenericIPAddressField(
                        help_text="IP address of the webhook request"
                    ),
                ),
                ("payload", models.JSONField()),
                (
                    "processed",
                    models.BooleanField(
                        default=False,
                        help_text="Whether the webhook was successfully processed",
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("modified", models.DateTimeField(auto_now=True)),
                (
                    "transaction",
                    models.ForeignKey(
                        blank=True,
                        help_text="Associated transaction if found/created",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="webhook_events",
                        to="django_athm.payment",
                    ),
                ),
            ],
            options={
                "db_table": "athm_webhook_event",
                "verbose_name": "ATH Móvil Webhook Event",
                "verbose_name_plural": "ATH Móvil Webhook Events",
                "ordering": ["-created"],
                "indexes": [
                    models.Index(fields=["-created"], name="athm_webhook_created_idx"),
                    models.Index(
                        fields=["event_type", "processed"], name="athm_webhook_type_idx"
                    ),
                ],
            },
        ),
    ]
