# Generated migration for payments app

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('loans', '0016_enhance_mpesa_transaction'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='MpesaConfiguration',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('environment', models.CharField(choices=[('sandbox', 'Sandbox'), ('production', 'Production')], default='sandbox', max_length=20)),
                ('consumer_key', models.CharField(max_length=100)),
                ('consumer_secret', models.CharField(max_length=100)),
                ('business_short_code', models.CharField(max_length=10)),
                ('passkey', models.CharField(blank=True, max_length=100, null=True)),
                ('validation_url', models.URLField(help_text='URL for validating payments')),
                ('confirmation_url', models.URLField(help_text='URL for confirming payments')),
                ('response_type', models.CharField(choices=[('Completed', 'Completed'), ('Cancelled', 'Cancelled')], default='Completed', help_text='What to do if validation fails', max_length=20)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'mpesa_configurations',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PaymentAllocation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('allocated_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('loan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='loans.Loan')),
                ('mpesa_transaction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allocations', to='loans.mpesatransaction')),
                ('repayment', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='loans.repayment')),
            ],
            options={
                'db_table': 'payment_allocations',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='MpesaCallback',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('callback_type', models.CharField(choices=[('validation', 'Validation'), ('confirmation', 'Confirmation')], max_length=20)),
                ('raw_data', models.JSONField()),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.CharField(blank=True, max_length=500, null=True)),
                ('processed', models.BooleanField(default=False)),
                ('response_sent', models.JSONField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('transaction', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='loans.mpesatransaction')),
            ],
            options={
                'db_table': 'mpesa_callbacks',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='MpesaAccessToken',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('access_token', models.TextField()),
                ('expires_at', models.DateTimeField()),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('configuration', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='payments.mpesaconfiguration')),
            ],
            options={
                'db_table': 'mpesa_access_tokens',
                'ordering': ['-created_at'],
            },
        ),
    ]
