# Generated by Django 5.2.2 on 2025-06-07 15:13

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="PageViewLog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "page_id",
                    models.PositiveIntegerField(
                        db_index=True,
                        help_text="ID of the viewed object",
                        verbose_name="Object ID",
                    ),
                ),
                (
                    "content_type",
                    models.CharField(
                        db_index=True,
                        help_text="Content type of the viewed object",
                        max_length=100,
                        verbose_name="Content Type",
                    ),
                ),
                (
                    "url",
                    models.CharField(
                        help_text="URL of the viewed object",
                        max_length=500,
                        verbose_name="URL",
                    ),
                ),
                (
                    "session_key",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="Session key of the visitor",
                        max_length=40,
                        null=True,
                        verbose_name="Session Key",
                    ),
                ),
                (
                    "ip_address",
                    models.GenericIPAddressField(
                        blank=True,
                        help_text="IP address of the visitor",
                        null=True,
                        verbose_name="IP Address",
                    ),
                ),
                (
                    "user_agent",
                    models.TextField(
                        blank=True,
                        help_text="User agent of the visitor",
                        null=True,
                        verbose_name="User Agent",
                    ),
                ),
                (
                    "referrer",
                    models.URLField(
                        blank=True,
                        help_text="Referrer URL",
                        max_length=500,
                        null=True,
                        verbose_name="Referrer",
                    ),
                ),
                (
                    "timestamp",
                    models.DateTimeField(
                        db_index=True,
                        default=django.utils.timezone.now,
                        help_text="When the object was viewed",
                        verbose_name="Timestamp",
                    ),
                ),
                (
                    "is_unique",
                    models.BooleanField(
                        default=False,
                        help_text="Whether this is a unique view for this session",
                        verbose_name="Is Unique",
                    ),
                ),
            ],
            options={
                "verbose_name": "Page View Log",
                "verbose_name_plural": "Page View Logs",
                "ordering": ["-timestamp"],
                "indexes": [
                    models.Index(
                        fields=["page_id", "timestamp"],
                        name="djinsight_p_page_id_a3ba77_idx",
                    ),
                    models.Index(
                        fields=["content_type", "timestamp"],
                        name="djinsight_p_content_7eddbf_idx",
                    ),
                    models.Index(
                        fields=["session_key", "page_id"],
                        name="djinsight_p_session_b10779_idx",
                    ),
                    models.Index(
                        fields=["timestamp"], name="djinsight_p_timesta_9d0cb4_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="PageViewSummary",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "page_id",
                    models.PositiveIntegerField(
                        db_index=True,
                        help_text="ID of the viewed object",
                        verbose_name="Object ID",
                    ),
                ),
                (
                    "content_type",
                    models.CharField(
                        help_text="Content type of the viewed object",
                        max_length=100,
                        verbose_name="Content Type",
                    ),
                ),
                (
                    "date",
                    models.DateField(
                        db_index=True,
                        help_text="Date of the summary",
                        verbose_name="Date",
                    ),
                ),
                (
                    "total_views",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Total views for this day",
                        verbose_name="Total Views",
                    ),
                ),
                (
                    "unique_views",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Unique views for this day",
                        verbose_name="Unique Views",
                    ),
                ),
            ],
            options={
                "verbose_name": "Page View Summary",
                "verbose_name_plural": "Page View Summaries",
                "ordering": ["-date"],
                "indexes": [
                    models.Index(
                        fields=["page_id", "date"],
                        name="djinsight_p_page_id_cd69db_idx",
                    ),
                    models.Index(
                        fields=["content_type", "date"],
                        name="djinsight_p_content_07ac79_idx",
                    ),
                    models.Index(fields=["date"], name="djinsight_p_date_fbf615_idx"),
                ],
                "unique_together": {("page_id", "date")},
            },
        ),
    ]
