# Generated manually — ConnectorConfig model for third-party integrations.

import uuid

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


class Migration(migrations.Migration):

    dependencies = [
        ("helpdesk", "0005_add_soft_delete_and_tag_uuid"),
        ("organizations", "0002_workspace_template_user_context_pref"),
        ("tenants", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="ConnectorConfig",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "public_id",
                    models.UUIDField(
                        db_index=True,
                        default=uuid.uuid4,
                        editable=False,
                        unique=True,
                        verbose_name="public id",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="created at"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="updated at"),
                ),
                (
                    "connector_type",
                    models.CharField(
                        choices=[
                            ("slack", "Slack"),
                            ("telegram", "Telegram"),
                            ("whatsapp", "WhatsApp"),
                            ("msteams", "Microsoft Teams"),
                            ("discord", "Discord"),
                            ("custom", "Custom"),
                        ],
                        db_index=True,
                        max_length=32,
                        verbose_name="connector type",
                    ),
                ),
                (
                    "name",
                    models.CharField(max_length=128, verbose_name="name"),
                ),
                (
                    "description",
                    models.TextField(blank=True, default="", verbose_name="description"),
                ),
                (
                    "is_active",
                    models.BooleanField(db_index=True, default=True, verbose_name="is active"),
                ),
                (
                    "config",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text=(
                            "Connector-specific configuration dict.  Keys vary per connector_type: "
                            "slack → bot_token, signing_secret, channel_id.  "
                            "telegram → bot_token, chat_id.  "
                            "custom → arbitrary key-value pairs."
                        ),
                        verbose_name="configuration",
                    ),
                ),
                (
                    "organization_node",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="organizations.organizationnode",
                        verbose_name="organization node",
                    ),
                ),
                (
                    "target_queue",
                    models.ForeignKey(
                        blank=True,
                        help_text="Queue where tickets from this connector will land.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="connectors",
                        to="helpdesk.queue",
                        verbose_name="target queue",
                    ),
                ),
                (
                    "tenant",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="tenants.tenant",
                        verbose_name="tenant",
                    ),
                ),
            ],
            options={
                "verbose_name": "connector config",
                "verbose_name_plural": "connector configs",
                "ordering": ("connector_type", "name"),
            },
        ),
        migrations.AddIndex(
            model_name="connectorconfig",
            index=models.Index(
                fields=["tenant", "connector_type", "is_active"],
                name="helpdesk_co_tenant__964e9c_idx",
            ),
        ),
    ]
