# Generated by Django 5.2.11 on 2026-02-20 21:19

import django.db.models.deletion
import uuid
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="AuditLog",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("user_email", models.CharField(blank=True, max_length=255)),
                ("user_display_name", models.CharField(blank=True, max_length=255)),
                (
                    "action",
                    models.CharField(
                        choices=[
                            ("create", "Create"),
                            ("update", "Update"),
                            ("delete", "Delete"),
                            ("login", "Login"),
                            ("logout", "Logout"),
                            ("view", "View"),
                            ("export", "Export"),
                            ("import", "Import"),
                            ("custom", "Custom"),
                        ],
                        max_length=20,
                    ),
                ),
                ("resource_type", models.CharField(db_index=True, max_length=100)),
                ("resource_id", models.CharField(db_index=True, max_length=255)),
                ("resource_repr", models.CharField(blank=True, max_length=500)),
                ("module", models.CharField(blank=True, db_index=True, max_length=100)),
                (
                    "changes",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text='{"field_name": {"old": "...", "new": "..."}}',
                    ),
                ),
                ("ip_address", models.GenericIPAddressField(blank=True, null=True)),
                ("user_agent", models.TextField(blank=True)),
                ("metadata", models.JSONField(blank=True, default=dict)),
                ("tenant_schema", models.CharField(blank=True, max_length=100)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="audit_logs",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Audit Log",
                "verbose_name_plural": "Audit Logs",
                "db_table": "audit_logs",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["resource_type", "resource_id"],
                        name="audit_logs_resourc_bda8a6_idx",
                    ),
                    models.Index(
                        fields=["user", "created_at"],
                        name="audit_logs_user_id_fbfd51_idx",
                    ),
                    models.Index(
                        fields=["module", "action", "created_at"],
                        name="audit_logs_module_bb411e_idx",
                    ),
                ],
            },
        ),
    ]
