# Generated by Django 5.2.4 on 2025-07-20 04:14

import django.core.validators
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Loan',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('loan_number', models.CharField(max_length=20, unique=True)),
                ('principal_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('interest_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('processing_fee', models.DecimalField(decimal_places=2, max_digits=12)),
                ('total_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('disbursement_date', models.DateTimeField()),
                ('due_date', models.DateTimeField()),
                ('duration_days', models.PositiveIntegerField()),
                ('status', models.CharField(choices=[('active', 'Active'), ('paid', 'Paid'), ('defaulted', 'Defaulted'), ('rolled_over', 'Rolled Over'), ('written_off', 'Written Off')], default='active', max_length=20)),
                ('amount_paid', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('last_payment_date', models.DateTimeField(blank=True, null=True)),
                ('is_rolled_over', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'loans',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='LoanApplication',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('application_number', models.CharField(max_length=20, unique=True)),
                ('requested_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('requested_duration', models.PositiveIntegerField(help_text='Duration in days')),
                ('purpose', models.TextField()),
                ('interest_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('processing_fee_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('total_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('under_review', 'Under Review'), ('approved', 'Approved'), ('rejected', 'Rejected'), ('disbursed', 'Disbursed'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
                ('submitted_at', models.DateTimeField(auto_now_add=True)),
                ('reviewed_at', models.DateTimeField(blank=True, null=True)),
                ('approval_notes', models.TextField(blank=True, null=True)),
                ('supporting_documents', models.FileField(blank=True, null=True, upload_to='loan_documents/')),
                ('auto_approved', models.BooleanField(default=False)),
                ('credit_score', models.PositiveIntegerField(blank=True, null=True)),
            ],
            options={
                'db_table': 'loan_applications',
                'ordering': ['-submitted_at'],
            },
        ),
        migrations.CreateModel(
            name='LoanProduct',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=200)),
                ('product_type', models.CharField(choices=[('personal', 'Personal Loan'), ('business', 'Business Advance'), ('salary', 'Salary Loan'), ('emergency', 'Emergency Loan'), ('asset', 'Asset Finance')], max_length=20)),
                ('description', models.TextField()),
                ('min_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('max_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('interest_rate', models.DecimalField(decimal_places=2, help_text='Annual interest rate in percentage', max_digits=5, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])),
                ('processing_fee', models.DecimalField(decimal_places=2, help_text='Processing fee as percentage of loan amount', max_digits=5, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])),
                ('late_payment_penalty', models.DecimalField(decimal_places=2, default=5.0, help_text='Daily penalty rate for late payments', max_digits=5)),
                ('min_duration', models.PositiveIntegerField(help_text='Minimum duration in days')),
                ('max_duration', models.PositiveIntegerField(help_text='Maximum duration in days')),
                ('requires_guarantor', models.BooleanField(default=False)),
                ('requires_collateral', models.BooleanField(default=False)),
                ('minimum_income', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'loan_products',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='MpesaTransaction',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('transaction_type', models.CharField(choices=[('c2b', 'Customer to Business'), ('b2c', 'Business to Customer'), ('stk_push', 'STK Push')], max_length=20)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('phone_number', models.CharField(max_length=17)),
                ('mpesa_transaction_id', models.CharField(blank=True, max_length=50, null=True)),
                ('merchant_request_id', models.CharField(blank=True, max_length=50, null=True)),
                ('checkout_request_id', models.CharField(blank=True, max_length=50, null=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('success', 'Success'), ('failed', 'Failed'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
                ('result_code', models.CharField(blank=True, max_length=10, null=True)),
                ('result_description', models.TextField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'mpesa_transactions',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Repayment',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('payment_method', models.CharField(choices=[('mpesa', 'M-Pesa'), ('bank', 'Bank Transfer'), ('cash', 'Cash'), ('cheque', 'Cheque')], max_length=20)),
                ('mpesa_transaction_id', models.CharField(blank=True, max_length=50, null=True)),
                ('mpesa_phone_number', models.CharField(blank=True, max_length=17, null=True)),
                ('receipt_number', models.CharField(max_length=20, unique=True)),
                ('payment_date', models.DateTimeField(auto_now_add=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'db_table': 'repayments',
                'ordering': ['-payment_date'],
            },
        ),
        migrations.CreateModel(
            name='RolloverRequest',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('requested_duration', models.PositiveIntegerField(help_text='Additional days')),
                ('reason', models.TextField()),
                ('rollover_fee', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='pending', max_length=20)),
                ('reviewed_at', models.DateTimeField(blank=True, null=True)),
                ('review_notes', models.TextField(blank=True, null=True)),
                ('requested_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'db_table': 'rollover_requests',
                'ordering': ['-requested_at'],
            },
        ),
    ]
