# Generated by Django 5.2.8 on 2025-11-16 15:25

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


class Migration(migrations.Migration):

    dependencies = [
        ("pages", "0037_alter_siteproxy_options"),
        ("sites", "0002_alter_domain_unique"),
    ]

    operations = [
        migrations.AddField(
            model_name="chatsession",
            name="whatsapp_number",
            field=models.CharField(
                blank=True,
                db_index=True,
                help_text="WhatsApp sender identifier associated with the chat session.",
                max_length=64,
            ),
        ),
        migrations.CreateModel(
            name="WhatsAppChatBridge",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                (
                    "api_base_url",
                    models.URLField(
                        default="https://graph.facebook.com/v18.0",
                        help_text="Base URL for the WhatsApp Cloud API.",
                    ),
                ),
                (
                    "phone_number_id",
                    models.CharField(
                        help_text="Identifier of the WhatsApp phone number used to send messages.",
                        max_length=100,
                    ),
                ),
                (
                    "access_token",
                    models.CharField(
                        help_text="Bearer token used to authenticate against the WhatsApp API.",
                        max_length=255,
                    ),
                ),
                (
                    "is_enabled",
                    models.BooleanField(
                        default=True,
                        help_text="Disable to stop forwarding chat messages through this WhatsApp client.",
                    ),
                ),
                (
                    "is_default",
                    models.BooleanField(
                        default=False,
                        help_text="Use as the fallback bridge when no site-specific configuration is defined.",
                    ),
                ),
                (
                    "site",
                    models.ForeignKey(
                        blank=True,
                        help_text="Restrict this bridge to a specific site. Leave blank to use it as a fallback.",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="whatsapp_chat_bridges",
                        to="sites.site",
                    ),
                ),
            ],
            options={
                "verbose_name": "WhatsApp chat bridge",
                "verbose_name_plural": "WhatsApp chat bridges",
                "ordering": ["site__domain", "pk"],
                "constraints": [
                    models.UniqueConstraint(
                        condition=models.Q(("site__isnull", False)),
                        fields=("site",),
                        name="unique_whatsapp_chat_bridge_site",
                    ),
                    models.UniqueConstraint(
                        condition=models.Q(("is_default", True)),
                        fields=("is_default",),
                        name="single_default_whatsapp_chat_bridge",
                    ),
                ],
            },
        ),
    ]
