# Generated migration for enhanced reports models

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


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('loans', '0001_initial'),
        ('reports', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='CustomerRequest',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('request_number', models.CharField(max_length=20, unique=True)),
                ('request_type', models.CharField(choices=[('loan_inquiry', 'Loan Inquiry'), ('payment_issue', 'Payment Issue'), ('account_issue', 'Account Issue'), ('document_issue', 'Document Issue'), ('rollover_request', 'Rollover Request'), ('complaint', 'Complaint'), ('technical_support', 'Technical Support'), ('general_inquiry', 'General Inquiry'), ('loan_extension', 'Loan Extension'), ('payment_plan', 'Payment Plan Request'), ('account_closure', 'Account Closure'), ('statement_request', 'Statement Request'), ('receipt_request', 'Receipt Request'), ('other', 'Other')], max_length=30)),
                ('subject', models.CharField(max_length=200)),
                ('description', models.TextField()),
                ('priority', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('urgent', 'Urgent')], default='medium', max_length=20)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('in_progress', 'In Progress'), ('resolved', 'Resolved'), ('closed', 'Closed'), ('escalated', 'Escalated'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
                ('resolution_notes', models.TextField(blank=True, null=True)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('assigned_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_requests', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='customer_requests', to=settings.AUTH_USER_MODEL)),
                ('related_application', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='loans.loanapplication')),
                ('related_loan', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='loans.Loan')),
                ('resolved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_requests', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'customer_requests',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='RegistrationFee',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('product_type', models.CharField(choices=[('boost', 'Boost'), ('boost_plus', 'Boost Plus'), ('mwamba', 'Mwamba'), ('imara', 'Imara'), ('account_opening', 'Account Opening'), ('document_processing', 'Document Processing'), ('statement_request', 'Statement Request'), ('certificate', 'Certificate'), ('other', 'Other')], max_length=30)),
                ('fee_name', models.CharField(max_length=200)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=10)),
                ('description', models.TextField(blank=True, null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('effective_from', models.DateTimeField(default=django.utils.timezone.now)),
                ('effective_to', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'registration_fees',
                'ordering': ['product_type', 'fee_name'],
            },
        ),
        migrations.CreateModel(
            name='RegistrationFeePayment',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('receipt_number', models.CharField(max_length=20, unique=True)),
                ('amount_paid', models.DecimalField(decimal_places=2, max_digits=10)),
                ('payment_method', models.CharField(choices=[('mpesa', 'M-Pesa'), ('bank', 'Bank Transfer'), ('cash', 'Cash'), ('cheque', 'Cheque'), ('card', 'Card Payment')], max_length=20)),
                ('payment_date', models.DateTimeField(default=django.utils.timezone.now)),
                ('transaction_reference', models.CharField(blank=True, max_length=100, null=True)),
                ('payment_notes', models.TextField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
                ('processed_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='processed_reg_fees', to=settings.AUTH_USER_MODEL)),
                ('registration_fee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='reports.registrationfee')),
                ('related_application', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='loans.loanapplication')),
                ('related_loan', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='loans.Loan')),
            ],
            options={
                'db_table': 'registration_fee_payments',
                'ordering': ['-payment_date'],
            },
        ),
        migrations.CreateModel(
            name='ReportSchedule',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=200)),
                ('report_type', models.CharField(choices=[('loans_due', 'Loans Due Report'), ('delinquent_loans', 'Delinquent Loans Report'), ('loans_in_arrears', 'Loans in Arrears Report'), ('processing_fees', 'Processing Fees Report'), ('interest_income', 'Interest Income Report'), ('registration_fees', 'Registration Fees Report'), ('customer_requests', 'Customer Requests Report'), ('portfolio_summary', 'Portfolio Summary Report'), ('collection_report', 'Collection Report'), ('risk_analysis', 'Risk Analysis Report')], max_length=30)),
                ('frequency', models.CharField(choices=[('daily', 'Daily'), ('weekly', 'Weekly'), ('monthly', 'Monthly'), ('quarterly', 'Quarterly'), ('yearly', 'Yearly')], max_length=20)),
                ('is_active', models.BooleanField(default=True)),
                ('next_run', models.DateTimeField()),
                ('last_run', models.DateTimeField(blank=True, null=True)),
                ('parameters', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
                ('recipients', models.ManyToManyField(related_name='scheduled_reports', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'report_schedules',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='ReportExecution',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('report_type', models.CharField(max_length=30)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('running', 'Running'), ('completed', 'Completed'), ('failed', 'Failed')], default='pending', max_length=20)),
                ('started_at', models.DateTimeField(auto_now_add=True)),
                ('completed_at', models.DateTimeField(blank=True, null=True)),
                ('error_message', models.TextField(blank=True, null=True)),
                ('pdf_file', models.FileField(blank=True, null=True, upload_to='reports/generated/')),
                ('excel_file', models.FileField(blank=True, null=True, upload_to='reports/generated/')),
                ('parameters', models.JSONField(blank=True, default=dict)),
                ('records_processed', models.PositiveIntegerField(default=0)),
                ('execution_time', models.FloatField(blank=True, null=True)),
                ('schedule', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='reports.reportschedule')),
            ],
            options={
                'db_table': 'report_executions',
                'ordering': ['-started_at'],
            },
        ),
    ]
