# Generated by Django 5.2.17 on 2026-09-02 17:07

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


class Migration(migrations.Migration):

    dependencies = [
        ('billing', '0002_promisetopay'),
        ('customers', '0003_dealer_customer_dealer_inquiry_feasibilityassessment_and_more'),
        ('tenancy', '0003_organization_address_organization_email_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='RecoveryAllocation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('allocation_number', models.CharField(max_length=50)),
                ('outstanding_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('assigned_date', models.DateField(default=django.utils.timezone.now)),
                ('due_date', models.DateField(blank=True, null=True)),
                ('priority', models.CharField(choices=[('LOW', 'Low'), ('NORMAL', 'Normal'), ('HIGH', 'High'), ('CRITICAL', 'Critical')], default='NORMAL', max_length=20)),
                ('status', models.CharField(choices=[('ALLOCATED', 'Allocated'), ('IN_PROGRESS', 'In Progress'), ('CONTACTED', 'Contacted'), ('PROMISE_RECEIVED', 'Promise Received'), ('PAYMENT_COLLECTED', 'Payment Collected'), ('NO_RESPONSE', 'No Response'), ('FAILED', 'Failed'), ('ESCALATED', 'Escalated'), ('COMPLETED', 'Completed'), ('CANCELLED', 'Cancelled')], default='ALLOCATED', max_length=30)),
                ('notes', models.TextField(blank=True)),
                ('reassignment_reason', models.CharField(blank=True, max_length=255)),
                ('completed_date', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('assigned_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_recoveries', to=settings.AUTH_USER_MODEL)),
                ('assigned_staff', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='assigned_recoveries', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='recovery_allocations', to='customers.customer')),
                ('invoice', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='recovery_allocations', to='billing.invoice')),
                ('linked_promise', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='recovery_allocations', to='billing.promisetopay')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
                ('reassigned_from', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='reassignments', to='billing.recoveryallocation')),
                ('service_account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='recovery_allocations', to='customers.serviceaccount')),
            ],
            options={
                'db_table': 'billing_recovery_allocation',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['organization', 'status'], name='rec_org_status_idx'), models.Index(fields=['organization', 'assigned_staff'], name='rec_org_staff_idx'), models.Index(fields=['organization', 'customer'], name='rec_org_customer_idx'), models.Index(fields=['organization', 'due_date'], name='rec_org_due_date_idx')],
                'constraints': [models.UniqueConstraint(fields=('organization', 'allocation_number'), name='unique_allocation_number_per_org')],
            },
        ),
    ]
