# Generated by Django 5.2.17 on 2026-09-02 22:21

import django.db.models.deletion
import uuid
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('customers', '0003_dealer_customer_dealer_inquiry_feasibilityassessment_and_more'),
        ('tenancy', '0004_staffprofile'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AddField(
            model_name='notificationpreference',
            name='email_enabled',
            field=models.BooleanField(default=True),
        ),
        migrations.CreateModel(
            name='ServiceSuspensionLog',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('event_type', models.CharField(choices=[('WARNING', 'Suspension Warning'), ('SUSPENSION', 'Service Suspension'), ('RESTORATION', 'Service Restoration')], max_length=30)),
                ('trigger_type', models.CharField(choices=[('SYSTEM_AUTOMATED', 'System Automated'), ('MANUAL_STAFF', 'Manual Staff Action'), ('PAYMENT_TRIGGERED', 'Payment Triggered'), ('PTP_EXEMPTION', 'Promise-to-Pay Exemption')], default='SYSTEM_AUTOMATED', max_length=30)),
                ('previous_status', models.CharField(max_length=40)),
                ('new_status', models.CharField(max_length=40)),
                ('outstanding_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=12)),
                ('reason', models.TextField(blank=True)),
                ('invoices_snapshot', models.JSONField(blank=True, default=list)),
                ('linked_payment_id', models.UUIDField(blank=True, null=True)),
                ('linked_promise_id', models.UUIDField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('actor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='performed_suspension_logs', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='suspension_logs', to='customers.customer')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
                ('service_account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='suspension_logs', to='customers.serviceaccount')),
            ],
            options={
                'db_table': 'customers_service_suspension_log',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['organization', 'event_type'], name='susp_log_org_event_idx'), models.Index(fields=['organization', 'service_account'], name='susp_log_org_svc_idx'), models.Index(fields=['organization', 'customer'], name='susp_log_org_cust_idx'), models.Index(fields=['organization', 'created_at'], name='susp_log_org_created_idx')],
            },
        ),
        migrations.CreateModel(
            name='SuspensionPolicy',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('grace_period_days', models.PositiveSmallIntegerField(default=3, help_text='Grace period days after due date before overdue penalties/actions')),
                ('suspension_threshold_days', models.PositiveSmallIntegerField(default=5, help_text='Days past grace period before automated suspension is triggered')),
                ('minimum_outstanding_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), help_text='Minimum outstanding debt required to qualify for automated suspension', max_digits=12)),
                ('auto_suspension_enabled', models.BooleanField(default=True, help_text='Enable/disable automated batch suspension processing')),
                ('auto_restoration_enabled', models.BooleanField(default=True, help_text='Enable/disable automatic service restoration upon full verified payment')),
                ('restore_on_partial_payment', models.BooleanField(default=False, help_text='If True, restores service on partial payment; if False, requires full balance clearance')),
                ('ptp_exemption_enabled', models.BooleanField(default=True, help_text='If True, active and unbreached Promise-to-Pay exempts subscriber from suspension')),
                ('warning_days_before_suspension', models.PositiveSmallIntegerField(default=2, help_text='Days before suspension to dispatch pre-suspension warning notice')),
                ('send_suspension_warning', models.BooleanField(default=True, help_text='Enable/disable pre-suspension warning notifications')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
            ],
            options={
                'db_table': 'customers_suspension_policy',
                'constraints': [models.UniqueConstraint(fields=('organization',), name='unique_suspension_policy_per_org')],
            },
        ),
    ]
