# Generated by Django 5.2.18 on 2026-11-15 13:19

import apps.core.ids
import django.db.models.deletion
import django.utils.timezone
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="JobLock",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=80, unique=True)),
                ("locked_at", models.DateTimeField(default=django.utils.timezone.now)),
                ("locked_by", models.CharField(blank=True, max_length=120)),
                ("expires_at", models.DateTimeField(db_index=True)),
            ],
        ),
        migrations.CreateModel(
            name="Sequence",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=apps.core.ids.uuid7,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("agency_id", models.UUIDField(db_index=True)),
                ("name", models.CharField(max_length=40)),
                ("year", models.PositiveIntegerField(default=0)),
                ("last_value", models.PositiveIntegerField(default=0)),
            ],
            options={
                "verbose_name": "séquence",
                "unique_together": {("agency_id", "name", "year")},
            },
        ),
        migrations.CreateModel(
            name="AuditLog",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=apps.core.ids.uuid7,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "occurred_at",
                    models.DateTimeField(
                        db_index=True, default=django.utils.timezone.now
                    ),
                ),
                ("actor_label", models.CharField(blank=True, max_length=160)),
                ("agency_id", models.UUIDField(blank=True, db_index=True, null=True)),
                ("action", models.CharField(db_index=True, max_length=80)),
                ("entity_type", models.CharField(blank=True, max_length=80)),
                ("entity_id", models.UUIDField(blank=True, null=True)),
                ("before", models.JSONField(blank=True, default=dict)),
                ("after", models.JSONField(blank=True, default=dict)),
                ("ip", models.GenericIPAddressField(blank=True, null=True)),
                ("user_agent", models.CharField(blank=True, max_length=255)),
                ("correlation_id", models.UUIDField(blank=True, null=True)),
                ("node_id", models.CharField(blank=True, max_length=64)),
                (
                    "actor",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "journal d'audit",
                "ordering": ["-occurred_at"],
                "indexes": [
                    models.Index(
                        fields=["entity_type", "entity_id"],
                        name="core_auditl_entity__244637_idx",
                    ),
                    models.Index(
                        fields=["agency_id", "occurred_at"],
                        name="core_auditl_agency__7d0514_idx",
                    ),
                ],
            },
        ),
    ]
