# Generated by Django 6.0.5 on 2026-06-21 15:33

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='UserSession',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('device_id', models.CharField(blank=True, db_index=True, max_length=255)),
                ('session_id', models.CharField(max_length=100, unique=True)),
                ('started_at', models.DateTimeField()),
                ('ended_at', models.DateTimeField(blank=True, null=True)),
                ('duration_seconds', models.PositiveIntegerField(blank=True, null=True)),
                ('platform', models.CharField(blank=True, max_length=20)),
                ('app_version', models.CharField(blank=True, max_length=20)),
                ('device_model', models.CharField(blank=True, max_length=100)),
                ('screens_viewed', models.PositiveIntegerField(default=0)),
                ('events_count', models.PositiveIntegerField(default=0)),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sessions', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'analytics_sessions',
                'ordering': ['-started_at'],
            },
        ),
        migrations.CreateModel(
            name='UserEvent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('device_id', models.CharField(blank=True, db_index=True, max_length=255)),
                ('event_type', models.CharField(choices=[('screen_view', 'Screen View'), ('screen_exit', 'Screen Exit'), ('tap', 'Tap / Click'), ('scroll', 'Scroll'), ('swipe', 'Swipe'), ('long_press', 'Long Press'), ('pull_to_refresh', 'Pull to Refresh'), ('search', 'Search'), ('search_result_click', 'Search Result Click'), ('store_view', 'Store View'), ('product_view', 'Product View'), ('event_view', 'Event View'), ('banner_click', 'Banner Click'), ('category_click', 'Category Click'), ('favorite_add', 'Add to Favorites'), ('favorite_remove', 'Remove from Favorites'), ('share', 'Share'), ('call', 'Phone Call'), ('whatsapp_click', 'WhatsApp Click'), ('instagram_click', 'Instagram Click'), ('website_click', 'Website Click'), ('coupon_claim', 'Coupon Claim'), ('review_submit', 'Review Submit'), ('add_to_cart', 'Add to Cart'), ('remove_from_cart', 'Remove from Cart'), ('checkout_start', 'Checkout Start'), ('purchase_complete', 'Purchase Complete'), ('app_open', 'App Open'), ('app_close', 'App Close'), ('app_background', 'App Backgrounded'), ('app_foreground', 'App Foregrounded'), ('login', 'Login'), ('logout', 'Logout'), ('signup', 'Signup'), ('notification_received', 'Notification Received'), ('notification_opened', 'Notification Opened'), ('notification_dismissed', 'Notification Dismissed'), ('error', 'Error'), ('crash', 'Crash'), ('custom', 'Custom Event')], db_index=True, max_length=50)),
                ('event_name', models.CharField(blank=True, help_text="Custom event name for more granular tracking (e.g. 'home_banner_1_click')", max_length=100)),
                ('screen_name', models.CharField(blank=True, db_index=True, max_length=100)),
                ('target_type', models.CharField(blank=True, help_text='Type of object interacted with: store, product, event, banner, category, etc.', max_length=50)),
                ('target_id', models.CharField(blank=True, help_text='ID of the object interacted with.', max_length=50)),
                ('target_name', models.CharField(blank=True, max_length=255)),
                ('metadata', models.JSONField(blank=True, default=dict, help_text='Any extra context: search query, scroll depth, duration, etc.')),
                ('session_id', models.CharField(blank=True, db_index=True, max_length=100)),
                ('session_duration', models.PositiveIntegerField(blank=True, help_text='Duration in seconds (for session/screen events).', null=True)),
                ('platform', models.CharField(blank=True, max_length=20)),
                ('app_version', models.CharField(blank=True, max_length=20)),
                ('os_version', models.CharField(blank=True, max_length=30)),
                ('device_model', models.CharField(blank=True, max_length=100)),
                ('screen_resolution', models.CharField(blank=True, max_length=20)),
                ('latitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)),
                ('longitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)),
                ('city', models.CharField(blank=True, max_length=100)),
                ('country', models.CharField(blank=True, max_length=50)),
                ('connection_type', models.CharField(blank=True, max_length=20)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('client_timestamp', models.DateTimeField(blank=True, null=True)),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='analytics_events', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'analytics_events',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['user', 'event_type', '-created_at'], name='analytics_e_user_id_64f223_idx'), models.Index(fields=['event_type', '-created_at'], name='analytics_e_event_t_bc280b_idx'), models.Index(fields=['device_id', '-created_at'], name='analytics_e_device__8571eb_idx'), models.Index(fields=['session_id', '-created_at'], name='analytics_e_session_c88a44_idx'), models.Index(fields=['screen_name', '-created_at'], name='analytics_e_screen__4e8c30_idx'), models.Index(fields=['target_type', 'target_id'], name='analytics_e_target__d9cd5d_idx')],
            },
        ),
    ]
