# Generated by Django 5.2.15 on 2026-07-04 18:13

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('tenancy', '0002_auditlog'),
    ]

    operations = [
        migrations.CreateModel(
            name='Customer',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('customer_number', models.CharField(max_length=50)),
                ('first_name', models.CharField(max_length=150)),
                ('last_name', models.CharField(blank=True, 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)),
                ('address_line', models.CharField(max_length=255)),
                ('area', models.CharField(blank=True, max_length=150)),
                ('city', models.CharField(max_length=150)),
                ('is_active', models.BooleanField(default=True)),
                ('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_customer',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='InternetPackage',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=150)),
                ('code', models.CharField(max_length=50)),
                ('download_speed_mbps', models.PositiveIntegerField()),
                ('upload_speed_mbps', models.PositiveIntegerField()),
                ('monthly_price', models.DecimalField(decimal_places=2, max_digits=12)),
                ('is_active', models.BooleanField(default=True)),
                ('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_internet_package',
                'ordering': ['monthly_price', 'name'],
            },
        ),
        migrations.CreateModel(
            name='NotificationPreference',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('sms_enabled', models.BooleanField(default=True)),
                ('whatsapp_enabled', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('customer', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='notification_preference', to='customers.customer')),
                ('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_notification_preference',
            },
        ),
        migrations.CreateModel(
            name='ServiceAccount',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('service_number', models.CharField(max_length=50)),
                ('status', models.CharField(choices=[('ACTIVE', 'Active'), ('GRACE_PERIOD', 'Grace Period'), ('SUSPENSION_PENDING', 'Suspension Pending'), ('SUSPENDED_NON_PAYMENT', 'Suspended Non-Payment'), ('RESTORE_PENDING', 'Restore Pending')], default='ACTIVE', max_length=40)),
                ('activated_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='service_accounts', to='customers.customer')),
                ('internet_package', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='service_accounts', to='customers.internetpackage')),
                ('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_service_account',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='BillingProfile',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('billing_cycle', models.CharField(choices=[('MONTHLY', 'Monthly')], default='MONTHLY', max_length=20)),
                ('billing_day', models.PositiveSmallIntegerField()),
                ('due_day', models.PositiveSmallIntegerField()),
                ('is_active', models.BooleanField(default=True)),
                ('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')),
                ('service_account', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='billing_profile', to='customers.serviceaccount')),
            ],
            options={
                'db_table': 'customers_billing_profile',
            },
        ),
        migrations.AddIndex(
            model_name='customer',
            index=models.Index(fields=['organization', 'phone'], name='customer_org_phone_idx'),
        ),
        migrations.AddIndex(
            model_name='customer',
            index=models.Index(fields=['organization', 'is_active'], name='customer_org_active_idx'),
        ),
        migrations.AddConstraint(
            model_name='customer',
            constraint=models.UniqueConstraint(fields=('organization', 'customer_number'), name='unique_customer_number_per_org'),
        ),
        migrations.AddIndex(
            model_name='internetpackage',
            index=models.Index(fields=['organization', 'is_active'], name='package_org_active_idx'),
        ),
        migrations.AddConstraint(
            model_name='internetpackage',
            constraint=models.UniqueConstraint(fields=('organization', 'code'), name='unique_package_code_per_org'),
        ),
        migrations.AddIndex(
            model_name='serviceaccount',
            index=models.Index(fields=['organization', 'status'], name='service_org_status_idx'),
        ),
        migrations.AddIndex(
            model_name='serviceaccount',
            index=models.Index(fields=['organization', 'customer'], name='service_org_customer_idx'),
        ),
        migrations.AddConstraint(
            model_name='serviceaccount',
            constraint=models.UniqueConstraint(fields=('organization', 'service_number'), name='unique_service_number_per_org'),
        ),
        migrations.AddConstraint(
            model_name='billingprofile',
            constraint=models.CheckConstraint(condition=models.Q(('billing_day__gte', 1), ('billing_day__lte', 28)), name='billing_day_between_1_and_28'),
        ),
        migrations.AddConstraint(
            model_name='billingprofile',
            constraint=models.CheckConstraint(condition=models.Q(('due_day__gte', 1), ('due_day__lte', 28)), name='due_day_between_1_and_28'),
        ),
    ]
