# Generated by Django 5.1.6 on 2026-01-06 18:23

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


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0007_add_incident_and_report_models"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.RemoveField(
            model_name="pageviewevent",
            name="pgh_obj",
        ),
        migrations.RemoveField(
            model_name="pageviewevent",
            name="content_type",
        ),
        migrations.RemoveField(
            model_name="pageviewevent",
            name="pgh_context",
        ),
        migrations.CreateModel(
            name="ApprovalTransactionMetric",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                (
                    "submission_id",
                    models.CharField(db_index=True, help_text="ID of the content submission", max_length=255),
                ),
                (
                    "moderator_id",
                    models.CharField(
                        db_index=True, help_text="ID of the moderator who processed the submission", max_length=255
                    ),
                ),
                (
                    "submitter_id",
                    models.CharField(
                        db_index=True, help_text="ID of the user who submitted the content", max_length=255
                    ),
                ),
                (
                    "request_id",
                    models.CharField(
                        blank=True, db_index=True, help_text="Correlation request ID", max_length=255, null=True
                    ),
                ),
                ("success", models.BooleanField(db_index=True, help_text="Whether the approval was successful")),
                (
                    "duration_ms",
                    models.PositiveIntegerField(blank=True, help_text="Processing duration in milliseconds", null=True),
                ),
                ("items_count", models.PositiveIntegerField(default=1, help_text="Number of items processed")),
                (
                    "rollback_triggered",
                    models.BooleanField(default=False, help_text="Whether a rollback was triggered"),
                ),
                (
                    "error_code",
                    models.CharField(blank=True, help_text="Error code if failed", max_length=50, null=True),
                ),
                ("error_message", models.TextField(blank=True, help_text="Error message if failed", null=True)),
                ("error_details", models.TextField(blank=True, help_text="Detailed error information", null=True)),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, help_text="When this metric was recorded"),
                ),
            ],
            options={
                "verbose_name": "Approval Transaction Metric",
                "verbose_name_plural": "Approval Transaction Metrics",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(fields=["success", "created_at"], name="core_approv_success_9c326b_idx"),
                    models.Index(fields=["moderator_id", "created_at"], name="core_approv_moderat_ec41ba_idx"),
                ],
            },
        ),
        migrations.CreateModel(
            name="RequestMetadata",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                (
                    "request_id",
                    models.CharField(
                        db_index=True,
                        help_text="Unique request identifier for correlation",
                        max_length=255,
                        unique=True,
                    ),
                ),
                (
                    "trace_id",
                    models.CharField(
                        blank=True, db_index=True, help_text="Distributed tracing ID", max_length=255, null=True
                    ),
                ),
                (
                    "session_id",
                    models.CharField(
                        blank=True, db_index=True, help_text="User session identifier", max_length=255, null=True
                    ),
                ),
                (
                    "parent_request_id",
                    models.CharField(
                        blank=True, help_text="Parent request ID for nested requests", max_length=255, null=True
                    ),
                ),
                (
                    "action",
                    models.CharField(
                        blank=True, help_text="Action/operation being performed", max_length=255, null=True
                    ),
                ),
                (
                    "method",
                    models.CharField(blank=True, help_text="HTTP method (GET, POST, etc.)", max_length=10, null=True),
                ),
                (
                    "endpoint",
                    models.CharField(
                        blank=True, db_index=True, help_text="API endpoint or URL path", max_length=500, null=True
                    ),
                ),
                (
                    "request_method",
                    models.CharField(blank=True, help_text="HTTP request method", max_length=10, null=True),
                ),
                ("request_path", models.CharField(blank=True, help_text="Request URL path", max_length=500, null=True)),
                (
                    "affected_route",
                    models.CharField(blank=True, help_text="Frontend route affected", max_length=255, null=True),
                ),
                (
                    "http_status",
                    models.PositiveIntegerField(blank=True, db_index=True, help_text="HTTP status code", null=True),
                ),
                (
                    "status_code",
                    models.PositiveIntegerField(blank=True, help_text="Status code (alias for http_status)", null=True),
                ),
                (
                    "response_status",
                    models.PositiveIntegerField(blank=True, help_text="Response status code", null=True),
                ),
                (
                    "success",
                    models.BooleanField(
                        blank=True, db_index=True, help_text="Whether the request was successful", null=True
                    ),
                ),
                ("started_at", models.DateTimeField(auto_now_add=True, help_text="When the request started")),
                ("completed_at", models.DateTimeField(blank=True, help_text="When the request completed", null=True)),
                (
                    "duration_ms",
                    models.PositiveIntegerField(blank=True, help_text="Request duration in milliseconds", null=True),
                ),
                (
                    "response_time_ms",
                    models.PositiveIntegerField(blank=True, help_text="Response time in milliseconds", null=True),
                ),
                (
                    "error_type",
                    models.CharField(
                        blank=True, db_index=True, help_text="Type/class of error", max_length=100, null=True
                    ),
                ),
                ("error_message", models.TextField(blank=True, help_text="Error message", null=True)),
                ("error_stack", models.TextField(blank=True, help_text="Error stack trace", null=True)),
                (
                    "error_code",
                    models.CharField(
                        blank=True, db_index=True, help_text="Application error code", max_length=50, null=True
                    ),
                ),
                (
                    "error_origin",
                    models.CharField(blank=True, help_text="Where the error originated", max_length=100, null=True),
                ),
                ("component_stack", models.TextField(blank=True, help_text="React component stack trace", null=True)),
                (
                    "severity",
                    models.CharField(
                        choices=[
                            ("debug", "Debug"),
                            ("info", "Info"),
                            ("warning", "Warning"),
                            ("error", "Error"),
                            ("critical", "Critical"),
                        ],
                        db_index=True,
                        default="info",
                        help_text="Error severity level",
                        max_length=20,
                    ),
                ),
                (
                    "is_resolved",
                    models.BooleanField(db_index=True, default=False, help_text="Whether this error has been resolved"),
                ),
                ("resolved_at", models.DateTimeField(blank=True, help_text="When the error was resolved", null=True)),
                ("resolution_notes", models.TextField(blank=True, help_text="Notes about resolution", null=True)),
                ("retry_count", models.PositiveIntegerField(default=0, help_text="Number of retry attempts")),
                (
                    "retry_attempts",
                    models.PositiveIntegerField(blank=True, help_text="Total retry attempts made", null=True),
                ),
                ("user_agent", models.TextField(blank=True, help_text="User agent string", null=True)),
                (
                    "ip_address_hash",
                    models.CharField(
                        blank=True, db_index=True, help_text="Hashed IP address", max_length=64, null=True
                    ),
                ),
                (
                    "client_version",
                    models.CharField(blank=True, help_text="Client application version", max_length=50, null=True),
                ),
                ("timezone", models.CharField(blank=True, help_text="User timezone", max_length=50, null=True)),
                ("referrer", models.TextField(blank=True, help_text="HTTP referrer", null=True)),
                (
                    "entity_type",
                    models.CharField(
                        blank=True, db_index=True, help_text="Type of entity affected", max_length=50, null=True
                    ),
                ),
                (
                    "entity_id",
                    models.CharField(
                        blank=True, db_index=True, help_text="ID of entity affected", max_length=255, null=True
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, help_text="When this record was created"),
                ),
                (
                    "resolved_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="User who resolved this error",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="resolved_request_metadata",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        help_text="User who made the request",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="request_metadata",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Request Metadata",
                "verbose_name_plural": "Request Metadata",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="RequestBreadcrumb",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ("timestamp", models.DateTimeField(help_text="When this breadcrumb occurred")),
                (
                    "category",
                    models.CharField(
                        help_text="Breadcrumb category (e.g., 'http', 'navigation', 'console')", max_length=100
                    ),
                ),
                ("message", models.TextField(help_text="Breadcrumb message")),
                (
                    "level",
                    models.CharField(
                        blank=True, help_text="Log level (debug, info, warning, error)", max_length=20, null=True
                    ),
                ),
                ("sequence_order", models.PositiveIntegerField(default=0, help_text="Order within the request")),
                (
                    "request_metadata",
                    models.ForeignKey(
                        help_text="Parent request",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="request_breadcrumbs",
                        to="core.requestmetadata",
                    ),
                ),
            ],
            options={
                "verbose_name": "Request Breadcrumb",
                "verbose_name_plural": "Request Breadcrumbs",
                "ordering": ["sequence_order", "timestamp"],
            },
        ),
        migrations.DeleteModel(
            name="PageView",
        ),
        migrations.DeleteModel(
            name="PageViewEvent",
        ),
        migrations.AddIndex(
            model_name="requestmetadata",
            index=models.Index(fields=["error_type", "created_at"], name="core_reques_error_t_d384f1_idx"),
        ),
        migrations.AddIndex(
            model_name="requestmetadata",
            index=models.Index(fields=["severity", "created_at"], name="core_reques_severit_04b88d_idx"),
        ),
        migrations.AddIndex(
            model_name="requestmetadata",
            index=models.Index(fields=["is_resolved", "created_at"], name="core_reques_is_reso_614d34_idx"),
        ),
        migrations.AddIndex(
            model_name="requestmetadata",
            index=models.Index(fields=["user", "created_at"], name="core_reques_user_id_db6ee3_idx"),
        ),
        migrations.AddIndex(
            model_name="requestbreadcrumb",
            index=models.Index(fields=["request_metadata", "sequence_order"], name="core_reques_request_0e8be4_idx"),
        ),
    ]
