# Generated by Django 5.2.8 on 2025-12-06 20:41

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('comms_credits', '0002_add_stripe_customer_id'),
        ('core', '0022_add_can_use_tasks'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='EmployeeLocationUpdate',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('event_id', models.IntegerField(db_index=True, help_text='ID of the active job in tenant schema')),
                ('latitude', models.DecimalField(decimal_places=7, help_text='GPS latitude', max_digits=10)),
                ('longitude', models.DecimalField(decimal_places=7, help_text='GPS longitude', max_digits=10)),
                ('accuracy', models.FloatField(blank=True, help_text='GPS accuracy in meters', null=True)),
                ('altitude', models.FloatField(blank=True, help_text='Altitude in meters (if available)', null=True)),
                ('heading', models.FloatField(blank=True, help_text='Direction of travel in degrees (0-360)', null=True)),
                ('speed', models.FloatField(blank=True, help_text='Speed in meters per second', null=True)),
                ('timestamp', models.DateTimeField(db_index=True, help_text='When the location was captured on device')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='When the server received this update')),
                ('battery_level', models.FloatField(blank=True, help_text='Device battery level (0.0-1.0)', null=True)),
                ('employee', models.ForeignKey(help_text='Employee being tracked', on_delete=django.db.models.deletion.CASCADE, related_name='location_updates', to=settings.AUTH_USER_MODEL)),
                ('tenant', models.ForeignKey(help_text='Tenant this location update belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='employee_locations', to='core.tenant')),
            ],
            options={
                'verbose_name': 'Employee Location Update',
                'verbose_name_plural': 'Employee Location Updates',
                'ordering': ['-timestamp'],
                'indexes': [models.Index(fields=['tenant', 'event_id', '-timestamp'], name='field_mobil_tenant__1284a1_idx'), models.Index(fields=['employee', '-timestamp'], name='field_mobil_employe_7b4ee0_idx'), models.Index(fields=['tenant', 'employee', 'event_id'], name='field_mobil_tenant__f49e41_idx')],
            },
        ),
        migrations.CreateModel(
            name='EventStatusHistory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('event_id', models.IntegerField(db_index=True, help_text='ID of the Event in tenant schema')),
                ('old_status', models.CharField(help_text='Previous status before change', max_length=20)),
                ('new_status', models.CharField(help_text='New status after change', max_length=20)),
                ('changed_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('notes', models.TextField(blank=True, help_text='Optional notes about the status change')),
                ('latitude', models.DecimalField(blank=True, decimal_places=7, help_text='Latitude where status was changed', max_digits=10, null=True)),
                ('longitude', models.DecimalField(blank=True, decimal_places=7, help_text='Longitude where status was changed', max_digits=10, null=True)),
                ('source', models.CharField(choices=[('mobile_app', 'Mobile App'), ('web_app', 'Web App'), ('api', 'API'), ('system', 'System')], default='mobile_app', help_text='Where the status change originated', max_length=20)),
                ('changed_by', models.ForeignKey(help_text='User who made the status change', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='status_changes', to=settings.AUTH_USER_MODEL)),
                ('tenant', models.ForeignKey(help_text='Tenant this status change belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='event_status_history', to='core.tenant')),
            ],
            options={
                'verbose_name': 'Event Status History',
                'verbose_name_plural': 'Event Status Histories',
                'ordering': ['-changed_at'],
                'indexes': [models.Index(fields=['tenant', 'event_id'], name='field_mobil_tenant__746f7d_idx'), models.Index(fields=['changed_by', '-changed_at'], name='field_mobil_changed_18d75d_idx')],
            },
        ),
        migrations.CreateModel(
            name='FieldCallLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('event_id', models.IntegerField(db_index=True, help_text='ID of the job this call is associated with')),
                ('call_type', models.CharField(choices=[('voice', 'Voice Call'), ('sms', 'SMS')], max_length=10)),
                ('direction', models.CharField(choices=[('outbound', 'Employee to Customer'), ('inbound', 'Customer to Employee')], max_length=10)),
                ('status', models.CharField(choices=[('initiated', 'Initiated'), ('ringing', 'Ringing'), ('in_progress', 'In Progress'), ('completed', 'Completed'), ('busy', 'Busy'), ('no_answer', 'No Answer'), ('failed', 'Failed'), ('canceled', 'Canceled')], default='initiated', max_length=20)),
                ('customer_phone', models.CharField(help_text="Customer's phone number (E.164 format)", max_length=20)),
                ('proxy_number', models.CharField(help_text='Twilio proxy number used', max_length=20)),
                ('twilio_call_sid', models.CharField(blank=True, help_text='Twilio Call SID for voice calls', max_length=50)),
                ('twilio_message_sid', models.CharField(blank=True, help_text='Twilio Message SID for SMS', max_length=50)),
                ('duration_seconds', models.IntegerField(blank=True, help_text='Call duration in seconds (for voice)', null=True)),
                ('cost_cents', models.IntegerField(default=0, help_text='Cost charged to tenant in cents')),
                ('initiated_at', models.DateTimeField(auto_now_add=True)),
                ('answered_at', models.DateTimeField(blank=True, null=True)),
                ('ended_at', models.DateTimeField(blank=True, null=True)),
                ('employee', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='field_calls', to=settings.AUTH_USER_MODEL)),
                ('masked_session', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='field_calls', to='comms_credits.maskedsession')),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='field_call_logs', to='core.tenant')),
            ],
            options={
                'verbose_name': 'Field Call Log',
                'verbose_name_plural': 'Field Call Logs',
                'ordering': ['-initiated_at'],
                'indexes': [models.Index(fields=['tenant', 'event_id'], name='field_mobil_tenant__8235dc_idx'), models.Index(fields=['employee', '-initiated_at'], name='field_mobil_employe_2a932d_idx'), models.Index(fields=['twilio_call_sid'], name='field_mobil_twilio__4c77e8_idx')],
            },
        ),
    ]
