"""Initial migration for wallet transactions."""

from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="WalletTransaction",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "wtype",
                    models.CharField(
                        db_index=True,
                        help_text="Wallet type / point type (e.g., 'credit_balance', 'reward_points')",
                        max_length=50,
                    ),
                ),
                (
                    "iid",
                    models.BigIntegerField(
                        db_index=True,
                        help_text="Initiator ID - user who performed this transaction (-100 for system)",
                    ),
                ),
                (
                    "uid",
                    models.BigIntegerField(
                        db_index=True,
                        help_text="User ID - owner of the wallet",
                    ),
                ),
                (
                    "type",
                    models.CharField(
                        choices=[("c", "Credit/Add"), ("d", "Debit/Deduct")],
                        help_text="Transaction type: 'c' for credit/add, 'd' for debit/deduct",
                        max_length=1,
                    ),
                ),
                (
                    "amount",
                    models.DecimalField(
                        decimal_places=2,
                        help_text="Transaction amount",
                        max_digits=20,
                    ),
                ),
                (
                    "balance",
                    models.DecimalField(
                        decimal_places=2,
                        help_text="Balance after this transaction",
                        max_digits=20,
                    ),
                ),
                (
                    "trans_type",
                    models.IntegerField(
                        blank=True,
                        db_index=True,
                        help_text="Transaction type code (integer constant, e.g., 1000 for wallet-deposit)",
                        null=True,
                    ),
                ),
                (
                    "descr",
                    models.TextField(
                        blank=True,
                        default="",
                        help_text="Remarks/description",
                    ),
                ),
                (
                    "cdate",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_index=True,
                        help_text="Creation date/time",
                    ),
                ),
                (
                    "extra_data",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Additional fields stored as JSON",
                    ),
                ),
            ],
            options={
                "db_table": "wallet_transactions",
                "ordering": ["-cdate"],
            },
        ),
        migrations.AddIndex(
            model_name="wallettransaction",
            index=models.Index(fields=["uid", "wtype"], name="wallet_tran_uid_wtype_idx"),
        ),
        migrations.AddIndex(
            model_name="wallettransaction",
            index=models.Index(fields=["uid", "cdate"], name="wallet_tran_uid_cdate_idx"),
        ),
        migrations.AddIndex(
            model_name="wallettransaction",
            index=models.Index(fields=["wtype", "trans_type"], name="wallet_tran_wtype_trans_idx"),
        ),
        migrations.AddIndex(
            model_name="wallettransaction",
            index=models.Index(fields=["iid", "cdate"], name="wallet_tran_iid_cdate_idx"),
        ),
    ]
