# Generated by Django 4.2.19 on 2026-03-07 00:00

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


class Migration(migrations.Migration):
    dependencies = [
        ("core", "0039_userxmppsecuritysettings"),
    ]

    operations = [
        migrations.CreateModel(
            name="CommandSecurityPolicy",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("scope_key", models.CharField(default="gateway.tasks", max_length=64)),
                ("enabled", models.BooleanField(default=True)),
                ("require_omemo", models.BooleanField(default=False)),
                ("require_trusted_omemo_fingerprint", models.BooleanField(default=False)),
                ("allowed_services", models.JSONField(blank=True, default=list)),
                ("allowed_channels", models.JSONField(blank=True, default=dict)),
                ("settings", models.JSONField(blank=True, default=dict)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="command_security_policies",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(fields=["user", "scope_key"], name="core_comman_user_id_701379_idx"),
                    models.Index(
                        fields=["user", "enabled", "updated_at"],
                        name="core_comman_user_id_82e21d_idx",
                    ),
                ],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("user", "scope_key"),
                        name="unique_command_security_policy_per_scope",
                    )
                ],
            },
        ),
        migrations.CreateModel(
            name="GatewayCommandEvent",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("service", models.CharField(choices=[("signal", "Signal"), ("whatsapp", "WhatsApp"), ("xmpp", "XMPP"), ("instagram", "Instagram"), ("web", "Web")], max_length=255)),
                ("channel_identifier", models.CharField(blank=True, default="", max_length=255)),
                ("sender_identifier", models.CharField(blank=True, default="", max_length=255)),
                ("scope_key", models.CharField(blank=True, default="", max_length=64)),
                ("command_name", models.CharField(blank=True, default="", max_length=64)),
                ("command_text", models.TextField(blank=True, default="")),
                ("status", models.CharField(choices=[("pending", "Pending"), ("blocked", "Blocked"), ("ok", "OK"), ("failed", "Failed"), ("ignored", "Ignored")], default="pending", max_length=32)),
                ("error", models.TextField(blank=True, default="")),
                ("request_meta", models.JSONField(blank=True, default=dict)),
                ("response_meta", models.JSONField(blank=True, default=dict)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "source_message",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="gateway_command_events",
                        to="core.message",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="gateway_command_events",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["user", "scope_key", "created_at"],
                        name="core_gatewa_user_id_d997cf_idx",
                    ),
                    models.Index(
                        fields=["user", "status", "created_at"],
                        name="core_gatewa_user_id_639afe_idx",
                    ),
                ],
            },
        ),
    ]
