# Generated by Django 5.2.9 on 2026-01-31 12:58

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='SearchQuery',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('query', models.CharField(db_index=True, help_text='The search query text entered by the user', max_length=500)),
                ('language_code', models.CharField(blank=True, db_index=True, help_text="Language code for the search (e.g., 'en', 'el', 'de')", max_length=10, null=True)),
                ('content_type', models.CharField(choices=[('product', 'Product'), ('blog_post', 'Blog Post'), ('federated', 'Federated')], db_index=True, help_text='Type of content being searched', max_length=20)),
                ('results_count', models.IntegerField(db_index=True, help_text='Number of results returned')),
                ('estimated_total_hits', models.IntegerField(help_text='Estimated total number of matching documents')),
                ('processing_time_ms', models.IntegerField(blank=True, help_text='Time taken to process the search in milliseconds', null=True)),
                ('session_key', models.CharField(blank=True, help_text='Session key for anonymous users', max_length=40, null=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, help_text='IP address of the user', null=True)),
                ('user_agent', models.TextField(blank=True, help_text='User agent string from the request', null=True)),
                ('timestamp', models.DateTimeField(auto_now_add=True, db_index=True, help_text='When the search was performed')),
                ('user', models.ForeignKey(blank=True, help_text='User who performed the search (if authenticated)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='search_queries', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Search Query',
                'verbose_name_plural': 'Search Queries',
                'db_table': 'search_query',
                'ordering': ['-timestamp'],
            },
        ),
        migrations.CreateModel(
            name='SearchClick',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('result_id', models.CharField(help_text='ID of the clicked result (Product or BlogPost ID)', max_length=100)),
                ('result_type', models.CharField(choices=[('product', 'Product'), ('blog_post', 'Blog Post')], help_text='Type of result that was clicked', max_length=20)),
                ('position', models.IntegerField(help_text='Position of the result in search results (0-indexed)')),
                ('timestamp', models.DateTimeField(auto_now_add=True, db_index=True, help_text='When the click occurred')),
                ('search_query', models.ForeignKey(help_text='The search query that led to this click', on_delete=django.db.models.deletion.CASCADE, related_name='clicks', to='search.searchquery')),
            ],
            options={
                'verbose_name': 'Search Click',
                'verbose_name_plural': 'Search Clicks',
                'db_table': 'search_click',
                'ordering': ['-timestamp'],
            },
        ),
        migrations.AddIndex(
            model_name='searchquery',
            index=models.Index(fields=['query', 'language_code'], name='search_query_lang_idx'),
        ),
        migrations.AddIndex(
            model_name='searchquery',
            index=models.Index(fields=['timestamp', 'content_type'], name='search_time_type_idx'),
        ),
        migrations.AddIndex(
            model_name='searchclick',
            index=models.Index(fields=['search_query', 'timestamp'], name='search_click_query_idx'),
        ),
    ]
