# Generated manually for initial AI assistant plugin schema.
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import uuid


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("wagtailcore", "0001_squashed_0016_change_page_url_path_to_text_field"),
    ]

    operations = [
        migrations.CreateModel(
            name="AiAssistantSession",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("uuid", models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ("site_id", models.PositiveIntegerField(db_index=True)),
                ("mode", models.CharField(choices=[("customer", "Customer"), ("admin", "Admin")], db_index=True, max_length=20)),
                ("visitor_id", models.CharField(blank=True, db_index=True, max_length=64)),
                ("language_code", models.CharField(blank=True, max_length=12)),
                ("status", models.CharField(choices=[("open", "Open"), ("closed", "Closed"), ("escalated", "Escalated")], db_index=True, default="open", max_length=20)),
                ("source_path", models.CharField(blank=True, max_length=255)),
                ("created_at", models.DateTimeField(db_index=True, default=django.utils.timezone.now)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("metadata", models.JSONField(blank=True, default=dict)),
                ("user", models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={"ordering": ["-created_at"]},
        ),
        migrations.CreateModel(
            name="AiAssistantSiteSettings",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("customer_enabled", models.BooleanField(default=True, verbose_name="Enable customer assistant")),
                ("admin_enabled", models.BooleanField(default=True, verbose_name="Enable admin assistant")),
                ("openai_api_key", models.CharField(blank=True, max_length=255, verbose_name="OpenAI API key")),
                ("openai_model", models.CharField(default="gpt-4o-mini", max_length=120, verbose_name="OpenAI model")),
                ("customer_system_prompt", models.TextField(blank=True, default="You are a helpful support assistant for this webshop/website.", verbose_name="Customer system prompt")),
                ("admin_system_prompt", models.TextField(blank=True, default="You are an admin support assistant for editors and webshop owners.", verbose_name="Admin system prompt")),
                ("escalation_email", models.EmailField(blank=True, max_length=254, verbose_name="Escalation email")),
                ("max_context_messages", models.PositiveIntegerField(default=12, verbose_name="Max context messages")),
                (
                    "site",
                    models.OneToOneField(
                        editable=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="wagtailcore.site",
                    ),
                ),
            ],
            options={"verbose_name": "AI Assistant Settings"},
        ),
        migrations.CreateModel(
            name="AiAssistantMessage",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("role", models.CharField(choices=[("user", "User"), ("assistant", "Assistant"), ("system", "System")], max_length=16)),
                ("content", models.TextField()),
                ("tokens_used", models.PositiveIntegerField(blank=True, null=True)),
                ("created_at", models.DateTimeField(db_index=True, default=django.utils.timezone.now)),
                ("raw", models.JSONField(blank=True, default=dict)),
                (
                    "session",
                    models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="messages", to="ai_assistant.aiassistantsession"),
                ),
            ],
            options={"ordering": ["created_at"]},
        ),
    ]
