# Generated by Django 5.2.6 on 2026-02-26 23:31

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='AIConfig',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('api_key', models.CharField(blank=True, default='', max_length=512)),
                ('model', models.CharField(blank=True, default='gpt-4o-mini', max_length=128)),
                ('temperature', models.FloatField(default=0.2)),
                ('max_tokens', models.IntegerField(default=1024)),
                ('timeout_sec', models.IntegerField(default=30)),
                ('provider', models.CharField(default='openai', max_length=64)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='Chat',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(blank=True, default='', max_length=255)),
                ('conversation_summary', models.TextField(blank=True, default='')),
                ('current_topic', models.CharField(blank=True, default='', max_length=128)),
                ('pending_clarification', models.JSONField(blank=True, default=None, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                (
                    'owner',
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='ai_chats',
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name='Message',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                (
                    'role',
                    models.CharField(
                        choices=[('system', 'system'), ('user', 'user'), ('assistant', 'assistant')], max_length=16
                    ),
                ),
                ('content', models.TextField()),
                ('meta', models.JSONField(blank=True, default=None, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                (
                    'chat',
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='django_ai_admin.chat'
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name='QueryLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('route', models.CharField(blank=True, default='', max_length=32)),
                ('question', models.TextField()),
                ('orm_code', models.TextField(blank=True, default='')),
                ('query_meta', models.JSONField(blank=True, default=None, null=True)),
                ('duration_ms', models.IntegerField(default=0)),
                ('rows', models.IntegerField(default=0)),
                ('truncated', models.BooleanField(default=False)),
                ('error', models.TextField(blank=True, default='')),
                ('intent_label', models.CharField(blank=True, default='', max_length=32)),
                ('intent_confidence', models.FloatField(default=0.0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                (
                    'chat',
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name='query_logs',
                        to='django_ai_admin.chat',
                    ),
                ),
                (
                    'user',
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name='ai_query_logs',
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.AddIndex(
            model_name='chat',
            index=models.Index(fields=['owner', '-updated_at'], name='django_ai_a_owner_i_dad1f3_idx'),
        ),
    ]
