# Generated by Django 5.2.17 on 2026-09-02 14:58

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


class Migration(migrations.Migration):

    dependencies = [
        ('customers', '0002_internetpackage_description_country_city_area_and_more'),
        ('network', '0001_initial'),
        ('tenancy', '0003_organization_address_organization_email_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Dealer',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('dealer_code', models.CharField(max_length=50)),
                ('name', models.CharField(max_length=150)),
                ('company_name', models.CharField(blank=True, max_length=200)),
                ('cnic', models.CharField(blank=True, max_length=50)),
                ('phone', models.CharField(max_length=30)),
                ('alternate_phone', models.CharField(blank=True, max_length=30)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('address_line', models.TextField(blank=True)),
                ('city', models.CharField(blank=True, max_length=150)),
                ('area', models.CharField(blank=True, max_length=150)),
                ('commission_rate_percentage', models.DecimalField(decimal_places=2, default=0.0, max_digits=5)),
                ('commission_type', models.CharField(choices=[('PERCENTAGE', 'Percentage of Revenue'), ('FLAT_PER_USER', 'Flat Rate Per Subscriber')], default='PERCENTAGE', max_length=30)),
                ('joining_date', models.DateField()),
                ('status', models.CharField(choices=[('ACTIVE', 'Active'), ('INACTIVE', 'Inactive'), ('SUSPENDED', 'Suspended'), ('TERMINATED', 'Terminated')], default='ACTIVE', max_length=30)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('assigned_area', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dealers', to='customers.area')),
                ('country', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='customers.country')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_dealers', to=settings.AUTH_USER_MODEL)),
                ('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_dealer',
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='customer',
            name='dealer',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='customers', to='customers.dealer'),
        ),
        migrations.CreateModel(
            name='Inquiry',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('inquiry_number', models.CharField(max_length=50)),
                ('full_name', models.CharField(max_length=150)),
                ('phone', models.CharField(max_length=30)),
                ('alternate_phone', models.CharField(blank=True, max_length=30)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('cnic', models.CharField(blank=True, max_length=50)),
                ('address_line', models.TextField()),
                ('city', models.CharField(max_length=150)),
                ('area', models.CharField(blank=True, max_length=150)),
                ('connection_type', models.CharField(choices=[('FIBER', 'Fiber to the Home (FTTH)'), ('WIRELESS', 'Wireless Broadband'), ('COPPER', 'Copper DSL'), ('OTHER', 'Other')], default='FIBER', max_length=30)),
                ('source', models.CharField(choices=[('WALK_IN', 'Walk-in'), ('PHONE_CALL', 'Phone Call'), ('WEBSITE', 'Website Lead'), ('SOCIAL_MEDIA', 'Social Media'), ('DEALER', 'Dealer / Sub-ISP'), ('REFERRAL', 'Customer Referral'), ('OTHER', 'Other')], default='WALK_IN', max_length=30)),
                ('status', models.CharField(choices=[('NEW', 'New'), ('CONTACTED', 'Contacted'), ('FEASIBILITY_PENDING', 'Feasibility Pending'), ('FEASIBLE', 'Feasible'), ('NOT_FEASIBLE', 'Not Feasible'), ('FOLLOW_UP', 'Follow-up'), ('CONVERTED', 'Converted'), ('LOST', 'Lost'), ('CANCELLED', 'Cancelled')], default='NEW', max_length=30)),
                ('notes', models.TextField(blank=True)),
                ('follow_up_date', models.DateField(blank=True, null=True)),
                ('converted_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('assigned_staff', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_inquiries', to=settings.AUTH_USER_MODEL)),
                ('converted_customer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='converted_from_inquiry', to='customers.customer')),
                ('country', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='customers.country')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_inquiries', to=settings.AUTH_USER_MODEL)),
                ('dealer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='inquiries', to='customers.dealer')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
                ('preferred_package', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='inquiries', to='customers.internetpackage')),
            ],
            options={
                'db_table': 'customers_inquiry',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='FeasibilityAssessment',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('feasibility_number', models.CharField(max_length=50)),
                ('address_line', models.TextField()),
                ('city', models.CharField(max_length=150)),
                ('area', models.CharField(blank=True, max_length=150)),
                ('connection_type', models.CharField(choices=[('FIBER', 'Fiber to the Home (FTTH)'), ('WIRELESS', 'Wireless Broadband'), ('COPPER', 'Copper DSL'), ('OTHER', 'Other')], default='FIBER', max_length=30)),
                ('status', models.CharField(choices=[('PENDING', 'Pending'), ('ASSIGNED', 'Assigned'), ('IN_PROGRESS', 'In Progress'), ('FEASIBLE', 'Feasible'), ('NOT_FEASIBLE', 'Not Feasible'), ('CANCELLED', 'Cancelled')], default='PENDING', max_length=30)),
                ('not_feasible_reason', models.CharField(blank=True, choices=[('NO_COVERAGE', 'No Coverage in Area'), ('NO_AVAILABLE_PORT', 'No Available Port on DP / FAT'), ('NO_SUITABLE_NODE', 'No Suitable Network Node'), ('CAPACITY_UNAVAILABLE', 'Backhaul Capacity Unavailable'), ('INFRASTRUCTURE_UNAVAILABLE', 'Civil / Pole Infrastructure Unavailable'), ('DISTANCE_LIMITATION', 'Exceeds Maximum Physical Distance'), ('OTHER', 'Other Technical Reason')], max_length=50)),
                ('not_feasible_details', models.TextField(blank=True)),
                ('assessment_date', models.DateField(blank=True, null=True)),
                ('completion_date', models.DateTimeField(blank=True, null=True)),
                ('remarks', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('assigned_technician', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_feasibilities', to=settings.AUTH_USER_MODEL)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_feasibilities', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='feasibility_assessments', to='customers.customer')),
                ('network_node', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='feasibility_checks', to='network.networknode')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
                ('package', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='feasibilities', to='customers.internetpackage')),
                ('inquiry', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='feasibility_assessments', to='customers.inquiry')),
            ],
            options={
                'db_table': 'customers_feasibility_assessment',
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddIndex(
            model_name='dealer',
            index=models.Index(fields=['organization', 'status'], name='dealer_org_status_idx'),
        ),
        migrations.AddIndex(
            model_name='dealer',
            index=models.Index(fields=['organization', 'phone'], name='dealer_org_phone_idx'),
        ),
        migrations.AddConstraint(
            model_name='dealer',
            constraint=models.UniqueConstraint(fields=('organization', 'dealer_code'), name='unique_dealer_code_per_org'),
        ),
        migrations.AddIndex(
            model_name='inquiry',
            index=models.Index(fields=['organization', 'status'], name='inquiry_org_status_idx'),
        ),
        migrations.AddIndex(
            model_name='inquiry',
            index=models.Index(fields=['organization', 'phone'], name='inquiry_org_phone_idx'),
        ),
        migrations.AddIndex(
            model_name='inquiry',
            index=models.Index(fields=['organization', 'follow_up_date'], name='inquiry_org_follow_up_idx'),
        ),
        migrations.AddConstraint(
            model_name='inquiry',
            constraint=models.UniqueConstraint(fields=('organization', 'inquiry_number'), name='unique_inquiry_number_per_org'),
        ),
        migrations.AddIndex(
            model_name='feasibilityassessment',
            index=models.Index(fields=['organization', 'status'], name='fsb_org_status_idx'),
        ),
        migrations.AddConstraint(
            model_name='feasibilityassessment',
            constraint=models.UniqueConstraint(fields=('organization', 'feasibility_number'), name='unique_fsb_number_per_org'),
        ),
    ]
