# Generated by Django 6.0 on 2026-01-11 18:20

import django.core.validators
import django.db.models.deletion
import django.utils.timezone
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('cases', '0008_casemessage_casemessageattachment_casemessageread_and_more'),
        ('customers', '0003_supportticket_supportticketmessage_and_more'),
        ('tenancy', '0003_tenant_address_line1_tenant_address_line2_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CollectionCase',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('reference', models.CharField(db_index=True, max_length=32)),
                ('status', models.CharField(choices=[('new', 'New'), ('in_review', 'In review'), ('preventive', 'Preventive'), ('amicable', 'Amicable'), ('pre_legal', 'Pre-legal'), ('legal', 'Legal'), ('disputed', 'Disputed'), ('settled', 'Settled'), ('closed', 'Closed'), ('write_off', 'Write-off')], db_index=True, default='new', max_length=20)),
                ('priority', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High')], db_index=True, default='medium', max_length=10)),
                ('principal_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18, validators=[django.core.validators.MinValueValidator(0)])),
                ('interest_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18, validators=[django.core.validators.MinValueValidator(0)])),
                ('penalty_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18, validators=[django.core.validators.MinValueValidator(0)])),
                ('fees_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18, validators=[django.core.validators.MinValueValidator(0)])),
                ('total_paid_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18, validators=[django.core.validators.MinValueValidator(0)])),
                ('due_date', models.DateField(blank=True, db_index=True, null=True)),
                ('next_action_type', models.CharField(blank=True, choices=[('call', 'Call'), ('sms', 'SMS'), ('email', 'Email'), ('visit', 'Visit'), ('letter', 'Letter'), ('negotiation', 'Negotiation'), ('notice', 'Formal notice'), ('lawyer', 'Transfer to lawyer'), ('other', 'Other')], max_length=20, null=True)),
                ('next_action_date', models.DateField(blank=True, db_index=True, null=True)),
                ('notes', models.TextField(blank=True, default='')),
                ('assigned_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_collection_cases', to=settings.AUTH_USER_MODEL)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_collection_cases', to=settings.AUTH_USER_MODEL)),
                ('debtor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='collection_cases', to='customers.customer')),
                ('portfolio', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='collection_cases', to='cases.portfolio')),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='collection_cases', to='tenancy.tenant')),
            ],
        ),
        migrations.CreateModel(
            name='CollectionAction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('action_type', models.CharField(choices=[('call', 'Call'), ('sms', 'SMS'), ('email', 'Email'), ('visit', 'Visit'), ('letter', 'Letter'), ('negotiation', 'Negotiation'), ('notice', 'Formal notice'), ('lawyer', 'Transfer to lawyer'), ('other', 'Other')], db_index=True, max_length=20)),
                ('outcome', models.CharField(blank=True, choices=[('reached', 'Reached'), ('not_reached', 'Not reached'), ('promise', 'Payment promise'), ('refused', 'Refused'), ('wrong_number', 'Wrong number'), ('rescheduled', 'Rescheduled'), ('partial_payment', 'Partial payment'), ('full_payment', 'Full payment'), ('dispute', 'Dispute'), ('other', 'Other')], db_index=True, max_length=20, null=True)),
                ('summary', models.CharField(blank=True, default='', max_length=240)),
                ('details', models.TextField(blank=True, default='')),
                ('action_date', models.DateTimeField(db_index=True, default=django.utils.timezone.now)),
                ('next_action_type', models.CharField(blank=True, choices=[('call', 'Call'), ('sms', 'SMS'), ('email', 'Email'), ('visit', 'Visit'), ('letter', 'Letter'), ('negotiation', 'Negotiation'), ('notice', 'Formal notice'), ('lawyer', 'Transfer to lawyer'), ('other', 'Other')], max_length=20, null=True)),
                ('next_action_date', models.DateField(blank=True, null=True)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_collection_actions', to=settings.AUTH_USER_MODEL)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='collection_actions', to='tenancy.tenant')),
                ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='actions', to='collections_management.collectioncase')),
            ],
        ),
        migrations.CreateModel(
            name='Payment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=18, validators=[django.core.validators.MinValueValidator(0)])),
                ('paid_at', models.DateTimeField(db_index=True, default=django.utils.timezone.now)),
                ('method', models.CharField(choices=[('cash', 'Cash'), ('bank_transfer', 'Bank transfer'), ('mobile_money', 'Mobile money'), ('cheque', 'Cheque'), ('card', 'Card'), ('other', 'Other')], default='other', max_length=30)),
                ('reference', models.CharField(blank=True, default='', max_length=64)),
                ('notes', models.TextField(blank=True, default='')),
                ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='collections_management.collectioncase')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_payments', to=settings.AUTH_USER_MODEL)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='tenancy.tenant')),
            ],
        ),
        migrations.CreateModel(
            name='PaymentPromise',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=18, validators=[django.core.validators.MinValueValidator(0)])),
                ('promised_date', models.DateField(db_index=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('kept', 'Kept'), ('broken', 'Broken'), ('cancelled', 'Cancelled')], db_index=True, default='pending', max_length=20)),
                ('notes', models.TextField(blank=True, default='')),
                ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='promises', to='collections_management.collectioncase')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_payment_promises', to=settings.AUTH_USER_MODEL)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payment_promises', to='tenancy.tenant')),
            ],
        ),
        migrations.AddIndex(
            model_name='collectioncase',
            index=models.Index(fields=['tenant', 'status', 'priority'], name='collections_tenant__42f3d7_idx'),
        ),
        migrations.AddIndex(
            model_name='collectioncase',
            index=models.Index(fields=['tenant', 'next_action_date'], name='collections_tenant__647528_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='collectioncase',
            unique_together={('tenant', 'reference')},
        ),
        migrations.AddIndex(
            model_name='collectionaction',
            index=models.Index(fields=['tenant', 'case', 'action_date'], name='collections_tenant__6c8a57_idx'),
        ),
        migrations.AddIndex(
            model_name='collectionaction',
            index=models.Index(fields=['tenant', 'action_type'], name='collections_tenant__612ce3_idx'),
        ),
        migrations.AddIndex(
            model_name='payment',
            index=models.Index(fields=['tenant', 'paid_at'], name='collections_tenant__4ffa9f_idx'),
        ),
        migrations.AddIndex(
            model_name='payment',
            index=models.Index(fields=['tenant', 'method'], name='collections_tenant__8dad7b_idx'),
        ),
        migrations.AddIndex(
            model_name='paymentpromise',
            index=models.Index(fields=['tenant', 'status', 'promised_date'], name='collections_tenant__a11591_idx'),
        ),
    ]
