# Generated by Django 5.2.11 on 2026-03-02 11:55

import uuid

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


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0028_airunlog'),
    ]

    operations = [
        migrations.CreateModel(
            name='AnswerMemory',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('service', models.CharField(choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], max_length=255)),
                ('channel_identifier', models.CharField(max_length=255)),
                ('question_fingerprint', models.CharField(max_length=128)),
                ('question_text', models.TextField(blank=True, default='')),
                ('answer_text', models.TextField(blank=True, default='')),
                ('confidence_meta', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
        ),
        migrations.CreateModel(
            name='AnswerSuggestionEvent',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('status', models.CharField(choices=[('suggested', 'Suggested'), ('accepted', 'Accepted'), ('dismissed', 'Dismissed')], default='suggested', max_length=32)),
                ('score', models.FloatField(default=0.0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='ChatTaskSource',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('service', models.CharField(choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], max_length=255)),
                ('channel_identifier', models.CharField(max_length=255)),
                ('enabled', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='DerivedTask',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('title', models.CharField(max_length=255)),
                ('source_service', models.CharField(choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], max_length=255)),
                ('source_channel', models.CharField(max_length=255)),
                ('reference_code', models.CharField(blank=True, default='', max_length=64)),
                ('external_key', models.CharField(blank=True, default='', max_length=255)),
                ('status_snapshot', models.CharField(blank=True, default='open', max_length=64)),
                ('immutable_payload', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
        ),
        migrations.CreateModel(
            name='DerivedTaskEvent',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('event_type', models.CharField(choices=[('created', 'Created'), ('progress', 'Progress'), ('completion_marked', 'Completion Marked'), ('synced', 'Synced'), ('sync_failed', 'Sync Failed'), ('parse_warning', 'Parse Warning')], max_length=32)),
                ('actor_identifier', models.CharField(blank=True, default='', max_length=255)),
                ('payload', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['created_at', 'id'],
            },
        ),
        migrations.CreateModel(
            name='ExternalSyncEvent',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('provider', models.CharField(default='mock', max_length=64)),
                ('idempotency_key', models.CharField(blank=True, default='', max_length=255)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('ok', 'OK'), ('failed', 'Failed'), ('retrying', 'Retrying')], default='pending', max_length=32)),
                ('payload', models.JSONField(blank=True, default=dict)),
                ('error', models.TextField(blank=True, default='')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='TaskCompletionPattern',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('phrase', models.CharField(max_length=64)),
                ('enabled', models.BooleanField(default=True)),
                ('position', models.PositiveIntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='TaskEpic',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255)),
                ('external_key', models.CharField(blank=True, default='', max_length=255)),
                ('active', models.BooleanField(default=True)),
                ('settings', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='TaskProject',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255)),
                ('external_key', models.CharField(blank=True, default='', max_length=255)),
                ('active', models.BooleanField(default=True)),
                ('settings', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='TaskProviderConfig',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('provider', models.CharField(default='mock', max_length=64)),
                ('enabled', models.BooleanField(default=False)),
                ('settings', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.RenameIndex(
            model_name='airunlog',
            new_name='core_airunl_user_id_13b24a_idx',
            old_name='core_airunl_user_id_6f4700_idx',
        ),
        migrations.RenameIndex(
            model_name='airunlog',
            new_name='core_airunl_user_id_678025_idx',
            old_name='core_airunl_user_id_b4486e_idx',
        ),
        migrations.RenameIndex(
            model_name='airunlog',
            new_name='core_airunl_user_id_55c2d4_idx',
            old_name='core_airunl_user_id_4f0f5e_idx',
        ),
        migrations.RenameIndex(
            model_name='airunlog',
            new_name='core_airunl_user_id_bef024_idx',
            old_name='core_airunl_user_id_953bff_idx',
        ),
        migrations.AddField(
            model_name='answermemory',
            name='answer_message',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='answer_memory_rows', to='core.message'),
        ),
        migrations.AddField(
            model_name='answermemory',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='answer_memory', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='answersuggestionevent',
            name='candidate_answer',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='suggestion_events', to='core.answermemory'),
        ),
        migrations.AddField(
            model_name='answersuggestionevent',
            name='message',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='answer_suggestion_events', to='core.message'),
        ),
        migrations.AddField(
            model_name='answersuggestionevent',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='answer_suggestion_events', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='chattasksource',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_task_sources', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='derivedtask',
            name='origin_message',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='derived_task_origins', to='core.message'),
        ),
        migrations.AddField(
            model_name='derivedtask',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='derived_tasks', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='derivedtaskevent',
            name='source_message',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='derived_task_events', to='core.message'),
        ),
        migrations.AddField(
            model_name='derivedtaskevent',
            name='task',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='core.derivedtask'),
        ),
        migrations.AddField(
            model_name='externalsyncevent',
            name='task',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='external_sync_events', to='core.derivedtask'),
        ),
        migrations.AddField(
            model_name='externalsyncevent',
            name='task_event',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='external_sync_events', to='core.derivedtaskevent'),
        ),
        migrations.AddField(
            model_name='externalsyncevent',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='external_sync_events', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='taskcompletionpattern',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='task_completion_patterns', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='derivedtask',
            name='epic',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='derived_tasks', to='core.taskepic'),
        ),
        migrations.AddField(
            model_name='chattasksource',
            name='epic',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='chat_sources', to='core.taskepic'),
        ),
        migrations.AddField(
            model_name='taskproject',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='task_projects', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='taskepic',
            name='project',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='epics', to='core.taskproject'),
        ),
        migrations.AddField(
            model_name='derivedtask',
            name='project',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='derived_tasks', to='core.taskproject'),
        ),
        migrations.AddField(
            model_name='chattasksource',
            name='project',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_sources', to='core.taskproject'),
        ),
        migrations.AddField(
            model_name='taskproviderconfig',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='task_provider_configs', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddIndex(
            model_name='answermemory',
            index=models.Index(fields=['user', 'service', 'channel_identifier', 'created_at'], name='core_answer_user_id_b88ba6_idx'),
        ),
        migrations.AddIndex(
            model_name='answermemory',
            index=models.Index(fields=['user', 'question_fingerprint', 'created_at'], name='core_answer_user_id_9353c7_idx'),
        ),
        migrations.AddIndex(
            model_name='answersuggestionevent',
            index=models.Index(fields=['user', 'status', 'created_at'], name='core_answer_user_id_05d0f9_idx'),
        ),
        migrations.AddIndex(
            model_name='answersuggestionevent',
            index=models.Index(fields=['message', 'status'], name='core_answer_message_1cb119_idx'),
        ),
        migrations.AddIndex(
            model_name='derivedtaskevent',
            index=models.Index(fields=['task', 'created_at'], name='core_derive_task_id_897ae5_idx'),
        ),
        migrations.AddIndex(
            model_name='derivedtaskevent',
            index=models.Index(fields=['event_type', 'created_at'], name='core_derive_event_t_1cf04b_idx'),
        ),
        migrations.AddIndex(
            model_name='externalsyncevent',
            index=models.Index(fields=['user', 'provider', 'status', 'updated_at'], name='core_extern_user_id_e71276_idx'),
        ),
        migrations.AddIndex(
            model_name='externalsyncevent',
            index=models.Index(fields=['idempotency_key'], name='core_extern_idempot_dce064_idx'),
        ),
        migrations.AddIndex(
            model_name='taskcompletionpattern',
            index=models.Index(fields=['user', 'enabled', 'position'], name='core_taskco_user_id_0c1b5e_idx'),
        ),
        migrations.AddConstraint(
            model_name='taskcompletionpattern',
            constraint=models.UniqueConstraint(fields=('user', 'phrase'), name='unique_task_completion_phrase_per_user'),
        ),
        migrations.AddIndex(
            model_name='taskproject',
            index=models.Index(fields=['user', 'active', 'updated_at'], name='core_taskpr_user_id_4f8472_idx'),
        ),
        migrations.AddConstraint(
            model_name='taskproject',
            constraint=models.UniqueConstraint(fields=('user', 'name'), name='unique_task_project_name_per_user'),
        ),
        migrations.AddIndex(
            model_name='taskepic',
            index=models.Index(fields=['project', 'active', 'updated_at'], name='core_taskep_project_ea76c3_idx'),
        ),
        migrations.AddConstraint(
            model_name='taskepic',
            constraint=models.UniqueConstraint(fields=('project', 'name'), name='unique_task_epic_name_per_project'),
        ),
        migrations.AddIndex(
            model_name='derivedtask',
            index=models.Index(fields=['user', 'project', 'created_at'], name='core_derive_user_id_a98675_idx'),
        ),
        migrations.AddIndex(
            model_name='derivedtask',
            index=models.Index(fields=['user', 'source_service', 'source_channel'], name='core_derive_user_id_aaa167_idx'),
        ),
        migrations.AddIndex(
            model_name='derivedtask',
            index=models.Index(fields=['user', 'reference_code'], name='core_derive_user_id_d06303_idx'),
        ),
        migrations.AddIndex(
            model_name='chattasksource',
            index=models.Index(fields=['user', 'service', 'channel_identifier', 'enabled'], name='core_chatta_user_id_01f271_idx'),
        ),
        migrations.AddIndex(
            model_name='chattasksource',
            index=models.Index(fields=['project', 'enabled'], name='core_chatta_project_826bab_idx'),
        ),
        migrations.AddConstraint(
            model_name='taskproviderconfig',
            constraint=models.UniqueConstraint(fields=('user', 'provider'), name='unique_task_provider_config_per_user'),
        ),
    ]
