# Generated by Django 5.2.4 on 2025-12-26 22:16

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


class Migration(migrations.Migration):

    dependencies = [
        ("calls", "0022_usermessage_twilio_call_sid"),
        ("companies", "0022_alter_dealershipdepartment_phone_number"),
    ]

    operations = [
        migrations.CreateModel(
            name="CallCatchPhrase",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "speaker",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("agent", "Agent"),
                            ("user", "User"),
                            ("advisor", "Advisor"),
                        ],
                        max_length=20,
                        null=True,
                    ),
                ),
                (
                    "confidence",
                    models.FloatField(
                        blank=True,
                        help_text="Confidence score between 0 and 1",
                        null=True,
                    ),
                ),
                (
                    "source",
                    models.CharField(
                        choices=[
                            ("string", "String Match"),
                            ("assemblyai", "AssemblyAI"),
                            ("llm", "LLM"),
                        ],
                        max_length=20,
                    ),
                ),
                (
                    "matched_text",
                    models.TextField(
                        blank=True,
                        help_text="Exact utterance text that triggered the phrase",
                    ),
                ),
                (
                    "detected_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="When phrase was detected"
                    ),
                ),
                (
                    "model_version",
                    models.CharField(
                        blank=True,
                        help_text="AI / model version used for detection",
                        max_length=50,
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="catchphrase",
            name="allowed_speakers",
            field=models.JSONField(
                blank=True, default=list, help_text="e.g. ['user', 'agent']"
            ),
        ),
        migrations.AddField(
            model_name="catchphrase",
            name="is_active",
            field=models.BooleanField(default=True),
        ),
        migrations.AddField(
            model_name="catchphrase",
            name="match_type",
            field=models.CharField(
                choices=[
                    ("string", "String Match"),
                    ("word", "Word Boundary"),
                    ("semantic", "Semantic (LLM)"),
                ],
                default="string",
                help_text="How this phrase should be detected",
                max_length=20,
            ),
        ),
        migrations.AddField(
            model_name="catchphrase",
            name="min_confidence",
            field=models.FloatField(
                default=0.7, help_text="Ignore detections below this confidence"
            ),
        ),
        migrations.AddField(
            model_name="catchphrase",
            name="synonyms",
            field=models.JSONField(
                blank=True,
                default=list,
                help_text="Alternative phrasings or variations",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="catchphrase",
            unique_together={("company", "phrase")},
        ),
        migrations.AddIndex(
            model_name="catchphrase",
            index=models.Index(
                fields=["company", "is_active"], name="companies_c_company_afe634_idx"
            ),
        ),
        migrations.AddField(
            model_name="callcatchphrase",
            name="call",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="catch_phrases",
                to="calls.call",
            ),
        ),
        migrations.AddField(
            model_name="callcatchphrase",
            name="company",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE, to="companies.company"
            ),
        ),
        migrations.AddField(
            model_name="callcatchphrase",
            name="phrase",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="occurrences",
                to="companies.catchphrase",
            ),
        ),
        migrations.AddIndex(
            model_name="callcatchphrase",
            index=models.Index(
                fields=["company", "phrase"], name="companies_c_company_545320_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="callcatchphrase",
            index=models.Index(fields=["call"], name="companies_c_call_id_f570ad_idx"),
        ),
        migrations.AlterUniqueTogether(
            name="callcatchphrase",
            unique_together={("call", "phrase")},
        ),
    ]
