# Generated by Django 5.1.4 on 2025-02-08 12:42

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('accounts', '0003_account_is_archived_account_is_trading_enabled'),
        ('customers', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Transaction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('updated_by', models.CharField(blank=True, max_length=255, null=True)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=20)),
                ('currency', models.CharField(max_length=3)),
                ('transaction_type', models.CharField(choices=[('DEPOSIT', 'Deposit'), ('WITHDRAWAL', 'Withdrawal'), ('BONUS', 'Bonus'), ('REBATE', 'Rebate'), ('COMMISSION', 'Commission'), ('CORRECTION', 'Correction'), ('INTERNAL_TRANSFER', 'Internal Transfer'), ('CREDIT', 'Credit'), ('CHARGE', 'Charge'), ('COMPENSATION', 'Compensation')], max_length=20)),
                ('direction', models.CharField(choices=[('IN', 'Credit/Incoming'), ('OUT', 'Debit/Outgoing')], max_length=3)),
                ('status', models.CharField(choices=[('PENDING', 'Pending'), ('APPROVED', 'Approved'), ('REJECTED', 'Rejected'), ('CANCELLED', 'Cancelled'), ('FAILED', 'Failed')], default='PENDING', max_length=10)),
                ('payment_method', models.CharField(blank=True, choices=[('WIRE', 'Wire Transfer'), ('CRYPTO', 'Cryptocurrency'), ('CARD', 'Credit/Debit Card'), ('MANUAL', 'Manual'), ('SYSTEM', 'System Generated')], max_length=10, null=True)),
                ('payment_gateway', models.CharField(max_length=50)),
                ('gateway_fees', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
                ('payment_reference', models.CharField(blank=True, max_length=255, null=True)),
                ('notes', models.TextField(blank=True)),
                ('rejection_reason', models.TextField(blank=True)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions', to='accounts.account')),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_transactions', to=settings.AUTH_USER_MODEL)),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='created_transactions', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions', to='customers.customer')),
            ],
            options={
                'db_table': 'transactions',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='TransactionEvidence',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.CharField(blank=True, max_length=255, null=True)),
                ('updated_by', models.CharField(blank=True, max_length=255, null=True)),
                ('file', models.FileField(upload_to='transaction_evidences/%Y/%m/%d/')),
                ('verified', models.BooleanField(default=False)),
                ('verified_at', models.DateTimeField(blank=True, null=True)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('transaction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='evidences', to='transactions.transaction')),
            ],
            options={
                'db_table': 'transaction_evidences',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='CommissionRebateTransaction',
            fields=[
                ('transaction_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='transactions.transaction')),
                ('calculation_basis', models.JSONField(help_text='Parameters used for calculation')),
                ('ib_account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='commission_rebate_transactions', to='accounts.account')),
            ],
            options={
                'db_table': 'commission_rebate_transactions',
            },
            bases=('transactions.transaction',),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['transaction_type', 'status'], name='transaction_transac_9f5934_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['account', 'created_at'], name='transaction_account_6c549c_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['payment_method'], name='transaction_payment_afdbde_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['payment_gateway'], name='transaction_payment_050505_idx'),
        ),
    ]
