# Generated by Django 5.2.5 on 2025-08-23 08:23

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

    dependencies = [
        ('loans', '0007_merge_20250822_2040'),
    ]

    operations = [
        migrations.RunSQL(
            """
            CREATE TABLE IF NOT EXISTS penalty_charges (
                id CHAR(32) NOT NULL PRIMARY KEY,
                loan_id CHAR(32) NOT NULL,
                amount DECIMAL(12,2) NOT NULL,
                penalty_rate DECIMAL(5,2) NOT NULL,
                days_overdue INT NOT NULL,
                outstanding_amount DECIMAL(12,2) NOT NULL,
                applied_date DATETIME(6) NOT NULL,
                created_at DATETIME(6) NOT NULL,
                INDEX idx_penalty_charges_loan_id (loan_id),
                INDEX idx_penalty_charges_applied_date (applied_date)
            );
            """,
            reverse_sql="DROP TABLE IF EXISTS penalty_charges;"
        ),
        migrations.RunSQL(
            """
            CREATE TABLE IF NOT EXISTS repayments (
                id CHAR(32) NOT NULL PRIMARY KEY,
                loan_id CHAR(32) NOT NULL,
                amount DECIMAL(12,2) NOT NULL,
                payment_method VARCHAR(20) NOT NULL,
                mpesa_transaction_id VARCHAR(50) NULL,
                mpesa_phone_number VARCHAR(17) NULL,
                receipt_number VARCHAR(20) NOT NULL UNIQUE,
                payment_date DATETIME(6) NOT NULL,
                created_at DATETIME(6) NOT NULL,
                INDEX idx_repayments_loan_id (loan_id),
                INDEX idx_repayments_payment_date (payment_date),
                INDEX idx_repayments_receipt_number (receipt_number)
            );
            """,
            reverse_sql="DROP TABLE IF EXISTS repayments;"
        ),
    ]
