# Generated by Django 5.2.7 on 2026-03-01 20:03

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


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0026_platformchatlink_is_group'),
    ]

    operations = [
        migrations.CreateModel(
            name='BusinessPlanDocument',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('source_service', models.CharField(choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], max_length=255)),
                ('source_channel_identifier', models.CharField(blank=True, default='', max_length=255)),
                ('title', models.CharField(default='Business Plan', max_length=255)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('final', 'Final')], default='draft', max_length=32)),
                ('content_markdown', models.TextField(blank=True, default='')),
                ('structured_payload', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='BusinessPlanRevision',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('content_markdown', models.TextField(blank=True, default='')),
                ('structured_payload', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['created_at'],
            },
        ),
        migrations.CreateModel(
            name='CommandAction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action_type', models.CharField(choices=[('extract_bp', 'Extract Business Plan'), ('post_result', 'Post Result'), ('save_document', 'Save Document')], max_length=64)),
                ('enabled', models.BooleanField(default=True)),
                ('config', models.JSONField(blank=True, default=dict)),
                ('position', models.PositiveIntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['position', 'id'],
            },
        ),
        migrations.CreateModel(
            name='CommandChannelBinding',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('direction', models.CharField(choices=[('ingress', 'Ingress'), ('egress', 'Egress'), ('scratchpad_mirror', 'Scratchpad Mirror')], max_length=64)),
                ('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='CommandProfile',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.CharField(default='bp', max_length=64)),
                ('name', models.CharField(default='Business Plan', max_length=255)),
                ('enabled', models.BooleanField(default=True)),
                ('trigger_token', models.CharField(default='#bp#', max_length=64)),
                ('reply_required', models.BooleanField(default=True)),
                ('exact_match_only', models.BooleanField(default=True)),
                ('window_scope', models.CharField(choices=[('conversation', 'Conversation')], default='conversation', max_length=64)),
                ('template_text', models.TextField(blank=True, default='')),
                ('visibility_mode', models.CharField(choices=[('status_in_source', 'Status In Source'), ('silent', 'Silent')], default='status_in_source', max_length=64)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='CommandRun',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('running', 'Running'), ('ok', 'OK'), ('failed', 'Failed'), ('skipped', 'Skipped')], default='pending', max_length=32)),
                ('error', models.TextField(blank=True, default='')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='TranslationBridge',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(default='Translation Bridge', max_length=255)),
                ('enabled', models.BooleanField(default=True)),
                ('a_service', models.CharField(choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], max_length=255)),
                ('a_channel_identifier', models.CharField(max_length=255)),
                ('a_language', models.CharField(default='en', max_length=64)),
                ('b_service', models.CharField(choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], max_length=255)),
                ('b_channel_identifier', models.CharField(max_length=255)),
                ('b_language', models.CharField(default='en', max_length=64)),
                ('direction', models.CharField(choices=[('a_to_b', 'A To B'), ('b_to_a', 'B To A'), ('bidirectional', 'Bidirectional')], default='bidirectional', max_length=32)),
                ('quick_mode_title', models.CharField(blank=True, default='', max_length=255)),
                ('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='TranslationEventLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('target_service', models.CharField(choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], max_length=255)),
                ('target_channel', models.CharField(max_length=255)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('ok', 'OK'), ('failed', 'Failed'), ('skipped', 'Skipped')], default='pending', max_length=32)),
                ('error', models.TextField(blank=True, default='')),
                ('origin_tag', models.CharField(blank=True, default='', max_length=255)),
                ('content_hash', models.CharField(blank=True, default='', max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.AddField(
            model_name='message',
            name='message_meta',
            field=models.JSONField(blank=True, default=dict, help_text='Normalized message metadata such as origin tags.'),
        ),
        migrations.AddField(
            model_name='message',
            name='reply_source_message_id',
            field=models.CharField(blank=True, help_text='Source message id for the replied target.', max_length=255, null=True),
        ),
        migrations.AddField(
            model_name='message',
            name='reply_source_service',
            field=models.CharField(blank=True, choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], help_text='Source service for the replied target.', max_length=255, null=True),
        ),
        migrations.AddField(
            model_name='message',
            name='reply_to',
            field=models.ForeignKey(blank=True, help_text='Resolved local message this message replies to.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='reply_children', to='core.message'),
        ),
        migrations.AddField(
            model_name='message',
            name='source_chat_id',
            field=models.CharField(blank=True, help_text='Source service chat or thread identifier when available.', max_length=255, null=True),
        ),
        migrations.AddField(
            model_name='message',
            name='source_message_id',
            field=models.CharField(blank=True, help_text='Source service message id when available.', max_length=255, null=True),
        ),
        migrations.AddField(
            model_name='message',
            name='source_service',
            field=models.CharField(blank=True, choices=[('signal', 'Signal'), ('whatsapp', 'WhatsApp'), ('xmpp', 'XMPP'), ('instagram', 'Instagram'), ('web', 'Web')], help_text='Source service where this message originally appeared.', max_length=255, null=True),
        ),
        migrations.AddIndex(
            model_name='message',
            index=models.Index(fields=['user', 'source_service', 'source_message_id'], name='core_messag_user_id_252699_idx'),
        ),
        migrations.AddIndex(
            model_name='message',
            index=models.Index(fields=['user', 'session', 'ts'], name='core_messag_user_id_ba0e73_idx'),
        ),
        migrations.AddIndex(
            model_name='message',
            index=models.Index(fields=['user', 'reply_source_service', 'reply_source_message_id'], name='core_messag_user_id_70ca93_idx'),
        ),
        migrations.AddField(
            model_name='businessplandocument',
            name='anchor_message',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='business_plan_anchor_docs', to='core.message'),
        ),
        migrations.AddField(
            model_name='businessplandocument',
            name='trigger_message',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='business_plan_trigger_docs', to='core.message'),
        ),
        migrations.AddField(
            model_name='businessplandocument',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='businessplanrevision',
            name='document',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='revisions', to='core.businessplandocument'),
        ),
        migrations.AddField(
            model_name='businessplanrevision',
            name='editor_user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='commandprofile',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='commandchannelbinding',
            name='profile',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='channel_bindings', to='core.commandprofile'),
        ),
        migrations.AddField(
            model_name='commandaction',
            name='profile',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='actions', to='core.commandprofile'),
        ),
        migrations.AddField(
            model_name='businessplandocument',
            name='command_profile',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='business_plan_documents', to='core.commandprofile'),
        ),
        migrations.AddField(
            model_name='commandrun',
            name='profile',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='runs', to='core.commandprofile'),
        ),
        migrations.AddField(
            model_name='commandrun',
            name='result_ref',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='command_runs', to='core.businessplandocument'),
        ),
        migrations.AddField(
            model_name='commandrun',
            name='trigger_message',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='command_runs', to='core.message'),
        ),
        migrations.AddField(
            model_name='commandrun',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='translationbridge',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='translationeventlog',
            name='bridge',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='core.translationbridge'),
        ),
        migrations.AddField(
            model_name='translationeventlog',
            name='source_message',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='translation_events', to='core.message'),
        ),
        migrations.AddConstraint(
            model_name='commandprofile',
            constraint=models.UniqueConstraint(fields=('user', 'slug'), name='unique_command_profile_per_user'),
        ),
        migrations.AddIndex(
            model_name='commandchannelbinding',
            index=models.Index(fields=['profile', 'direction', 'service'], name='core_comman_profile_6c16d5_idx'),
        ),
        migrations.AddIndex(
            model_name='commandchannelbinding',
            index=models.Index(fields=['profile', 'service', 'channel_identifier'], name='core_comman_profile_2c801d_idx'),
        ),
        migrations.AddIndex(
            model_name='commandaction',
            index=models.Index(fields=['profile', 'action_type', 'enabled'], name='core_comman_profile_f8e752_idx'),
        ),
        migrations.AddIndex(
            model_name='businessplandocument',
            index=models.Index(fields=['user', 'status', 'updated_at'], name='core_busine_user_id_028f36_idx'),
        ),
        migrations.AddIndex(
            model_name='businessplandocument',
            index=models.Index(fields=['user', 'source_service', 'source_channel_identifier'], name='core_busine_user_id_54ef14_idx'),
        ),
        migrations.AddIndex(
            model_name='commandrun',
            index=models.Index(fields=['user', 'status', 'updated_at'], name='core_comman_user_id_aa2881_idx'),
        ),
        migrations.AddConstraint(
            model_name='commandrun',
            constraint=models.UniqueConstraint(fields=('profile', 'trigger_message'), name='unique_command_run_profile_trigger_message'),
        ),
        migrations.AddIndex(
            model_name='translationbridge',
            index=models.Index(fields=['user', 'enabled'], name='core_transl_user_id_ce99cd_idx'),
        ),
        migrations.AddIndex(
            model_name='translationbridge',
            index=models.Index(fields=['user', 'a_service', 'a_channel_identifier'], name='core_transl_user_id_2f26ee_idx'),
        ),
        migrations.AddIndex(
            model_name='translationbridge',
            index=models.Index(fields=['user', 'b_service', 'b_channel_identifier'], name='core_transl_user_id_1f910a_idx'),
        ),
        migrations.AddIndex(
            model_name='translationeventlog',
            index=models.Index(fields=['bridge', 'created_at'], name='core_transl_bridge__509ffc_idx'),
        ),
        migrations.AddIndex(
            model_name='translationeventlog',
            index=models.Index(fields=['bridge', 'status', 'updated_at'], name='core_transl_bridge__0a7676_idx'),
        ),
        migrations.AddIndex(
            model_name='translationeventlog',
            index=models.Index(fields=['origin_tag'], name='core_transl_origin__a5c2f3_idx'),
        ),
    ]
