# Generated by Django 5.2.8 on 2025-11-15 15:04

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


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0104_odooprofile_partner_id"),
        ("pages", "0035_chatsession_chatmessage"),
        ("sites", "0002_alter_domain_unique"),
    ]

    operations = [
        migrations.CreateModel(
            name="OdooChatBridge",
            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)),
                (
                    "channel_id",
                    models.PositiveIntegerField(
                        help_text="Identifier of the Odoo mail.channel that should receive forwarded messages."
                    ),
                ),
                (
                    "channel_uuid",
                    models.CharField(
                        blank=True,
                        help_text="Optional UUID of the Odoo mail.channel for reference.",
                        max_length=64,
                    ),
                ),
                (
                    "is_enabled",
                    models.BooleanField(
                        default=True,
                        help_text="Disable to stop forwarding chat messages to this Odoo channel.",
                    ),
                ),
                (
                    "is_default",
                    models.BooleanField(
                        default=False,
                        help_text="Use as the fallback bridge when no site-specific configuration is defined.",
                    ),
                ),
                (
                    "notify_partner_ids",
                    models.JSONField(
                        blank=True,
                        default=list,
                        help_text="Additional Odoo partner IDs to notify when posting messages. Provide a JSON array of integers.",
                    ),
                ),
                (
                    "profile",
                    models.ForeignKey(
                        help_text="Verified Odoo employee credentials used to post chat messages.",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="chat_bridges",
                        to="core.odooprofile",
                    ),
                ),
                (
                    "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="odoo_chat_bridges",
                        to="sites.site",
                    ),
                ),
            ],
            options={
                "verbose_name": "Odoo chat bridge",
                "verbose_name_plural": "Odoo chat bridges",
                "ordering": ["site__domain", "pk"],
                "constraints": [
                    models.UniqueConstraint(
                        condition=models.Q(("site__isnull", False)),
                        fields=("site",),
                        name="unique_odoo_chat_bridge_site",
                    ),
                    models.UniqueConstraint(
                        condition=models.Q(("is_default", True)),
                        fields=("is_default",),
                        name="single_default_odoo_chat_bridge",
                    ),
                ],
            },
        ),
    ]
