# Generated by Django 5.2.10 on 2026-01-15 20:06

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


class Migration(migrations.Migration):

    dependencies = [
        ("django_ai_admin_chat", "0001_embedding_cache"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="ChatHistory",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("query", models.TextField(help_text="Pytanie użytkownika")),
                (
                    "search_type",
                    models.CharField(
                        choices=[("embedding", "Embedding Search"), ("keyword", "Keyword Search")],
                        help_text="Typ wyszukiwania użytego do znalezienia danych",
                        max_length=20,
                    ),
                ),
                (
                    "search_results",
                    models.JSONField(default=list, help_text="Wyniki wyszukiwania (lista SearchMatch jako JSON)"),
                ),
                ("context", models.TextField(help_text="Zbudowany kontekst z wyników wyszukiwania")),
                ("response", models.TextField(help_text="Odpowiedź asystenta")),
                (
                    "tokens_prompt",
                    models.IntegerField(blank=True, help_text="Liczba tokenów użytych w prompcie", null=True),
                ),
                (
                    "tokens_completion",
                    models.IntegerField(blank=True, help_text="Liczba tokenów użytych w odpowiedzi", null=True),
                ),
                (
                    "tokens_total",
                    models.IntegerField(
                        blank=True, help_text="Całkowita liczba tokenów (prompt + completion)", null=True
                    ),
                ),
                (
                    "chat_history",
                    models.JSONField(default=list, help_text="Historia chatu przed tym zapytaniem (lista wiadomości)"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        help_text="Użytkownik, który wykonał zapytanie",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="chat_histories",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Historia chatu",
                "verbose_name_plural": "Historie chatu",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(fields=["-created_at"], name="django_ai_a_created_35586a_idx"),
                    models.Index(fields=["user", "-created_at"], name="django_ai_a_user_id_3692c3_idx"),
                ],
            },
        ),
    ]
