# Generated by Django 5.2.15 on 2026-07-05 19:33

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('customers', '0001_initial'),
        ('network', '0001_initial'),
        ('support', '0001_initial'),
        ('tenancy', '0002_auditlog'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='WorkOrder',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('work_order_number', models.CharField(max_length=50)),
                ('work_type', models.CharField(choices=[('INSTALLATION', 'Installation'), ('REPAIR', 'Repair'), ('DEVICE_REPLACEMENT', 'Device Replacement'), ('NETWORK_MAINTENANCE', 'Network Maintenance'), ('SITE_VISIT', 'Site Visit'), ('OTHER', 'Other')], max_length=40)),
                ('priority', models.CharField(choices=[('LOW', 'Low'), ('MEDIUM', 'Medium'), ('HIGH', 'High'), ('CRITICAL', 'Critical')], default='MEDIUM', max_length=20)),
                ('status', models.CharField(choices=[('CREATED', 'Created'), ('ASSIGNED', 'Assigned'), ('DISPATCHED', 'Dispatched'), ('ONSITE', 'Onsite'), ('COMPLETED', 'Completed')], default='CREATED', max_length=30)),
                ('title', models.CharField(max_length=255)),
                ('description', models.TextField()),
                ('dispatch_notes', models.TextField(blank=True)),
                ('onsite_notes', models.TextField(blank=True)),
                ('completion_notes', models.TextField(blank=True)),
                ('assigned_at', models.DateTimeField(blank=True, null=True)),
                ('dispatched_at', models.DateTimeField(blank=True, null=True)),
                ('onsite_at', models.DateTimeField(blank=True, null=True)),
                ('completed_at', models.DateTimeField(blank=True, null=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.PROTECT, related_name='assigned_work_orders', to=settings.AUTH_USER_MODEL)),
                ('complaint', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='work_orders', to='support.complaint')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_work_orders', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='work_orders', to='customers.customer')),
                ('incident', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='work_orders', to='support.incident')),
                ('network_node', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='work_orders', to='network.networknode')),
                ('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(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='work_orders', to='customers.serviceaccount')),
            ],
            options={
                'db_table': 'field_operations_work_order',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['organization', 'status'], name='work_order_org_status_idx'), models.Index(fields=['organization', 'priority'], name='work_order_org_priority_idx'), models.Index(fields=['organization', 'assigned_technician'], name='work_order_org_tech_idx'), models.Index(fields=['organization', 'customer'], name='work_order_org_customer_idx'), models.Index(fields=['organization', 'service_account'], name='work_order_org_service_idx')],
                'constraints': [models.UniqueConstraint(fields=('organization', 'work_order_number'), name='unique_work_order_number_per_org')],
            },
        ),
    ]
