# Generated by Django 4.2.5 on 2025-09-10 13:27

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("contenttypes", "0002_remove_content_type_name"),
    ]

    operations = [
        migrations.CreateModel(
            name="SystemConfiguration",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Identifiant unique UUID",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Date et heure de création"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Date et heure de dernière modification",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True, help_text="Indique si l'enregistrement est actif"
                    ),
                ),
                (
                    "key",
                    models.CharField(
                        help_text="Clé de configuration", max_length=100, unique=True
                    ),
                ),
                ("value", models.TextField(help_text="Valeur de configuration")),
                (
                    "description",
                    models.TextField(
                        blank=True, help_text="Description de ce paramètre"
                    ),
                ),
                (
                    "is_sensitive",
                    models.BooleanField(
                        default=False,
                        help_text="Valeur sensible (masquée dans l'admin)",
                    ),
                ),
                (
                    "is_system",
                    models.BooleanField(
                        default=False,
                        help_text="Paramètre système (non modifiable via l'interface)",
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant créé cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant modifié cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "5.1 - System Config.",
                "verbose_name_plural": "5.1 - System Config.",
                "db_table": "system_configuration",
                "ordering": ["key"],
            },
        ),
        migrations.CreateModel(
            name="MediaFile",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Identifiant unique UUID",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Date et heure de création"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Date et heure de dernière modification",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True, help_text="Indique si l'enregistrement est actif"
                    ),
                ),
                ("title", models.CharField(max_length=200, verbose_name="Titre")),
                (
                    "description",
                    models.TextField(blank=True, verbose_name="Description"),
                ),
                (
                    "media_type",
                    models.CharField(
                        choices=[
                            ("document", "Document"),
                            ("image", "Image"),
                            ("video", "Vidéo"),
                            ("audio", "Audio"),
                            ("archive", "Archive"),
                            ("other", "Autre"),
                        ],
                        default="document",
                        max_length=20,
                        verbose_name="Type de média",
                    ),
                ),
                (
                    "file",
                    models.FileField(
                        help_text="Fichier stocké localement",
                        upload_to=apps.core.storage_backend.get_media_upload_path,
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant créé cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant modifié cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "5.5 - Fichier média",
                "verbose_name_plural": "5.5 - Fichiers média",
                "db_table": "core_media_file",
                "ordering": ["-created_at"],
            },
            bases=(models.Model, apps.core.storage_backend.StorageBackendMixin),
        ),
        migrations.CreateModel(
            name="Document",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Identifiant unique UUID",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Date et heure de création"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Date et heure de dernière modification",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True, help_text="Indique si l'enregistrement est actif"
                    ),
                ),
                (
                    "title",
                    models.CharField(
                        blank=True,
                        help_text="Titre du document (généré automatiquement à partir du fichier si vide)",
                        max_length=200,
                        verbose_name="Titre",
                    ),
                ),
                (
                    "description",
                    models.TextField(blank=True, verbose_name="Description"),
                ),
                (
                    "file",
                    models.FileField(
                        help_text="Fichier stocké localement",
                        upload_to=apps.core.storage_backend.get_document_upload_path,
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant créé cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant modifié cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "5.4 - Document",
                "verbose_name_plural": "5.4 - Documents",
                "db_table": "core_document",
                "ordering": ["-created_at"],
            },
            bases=(models.Model, apps.core.storage_backend.StorageBackendMixin),
        ),
        migrations.CreateModel(
            name="Notification",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Identifiant unique UUID",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Date et heure de création"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Date et heure de dernière modification",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True, help_text="Indique si l'enregistrement est actif"
                    ),
                ),
                (
                    "title",
                    models.CharField(
                        help_text="Titre de la notification", max_length=200
                    ),
                ),
                ("message", models.TextField(help_text="Message de la notification")),
                (
                    "notification_type",
                    models.CharField(
                        choices=[
                            ("info", "Information"),
                            ("warning", "Avertissement"),
                            ("error", "Erreur"),
                            ("success", "Succès"),
                            ("critical", "Critique"),
                        ],
                        default="info",
                        max_length=10,
                    ),
                ),
                (
                    "priority",
                    models.CharField(
                        choices=[
                            ("low", "Basse"),
                            ("normal", "Normale"),
                            ("high", "Haute"),
                            ("urgent", "Urgente"),
                        ],
                        default="normal",
                        max_length=10,
                    ),
                ),
                (
                    "is_read",
                    models.BooleanField(default=False, help_text="Notification lue"),
                ),
                (
                    "read_at",
                    models.DateTimeField(
                        blank=True, help_text="Date de lecture", null=True
                    ),
                ),
                (
                    "action_url",
                    models.URLField(blank=True, help_text="URL d'action associée"),
                ),
                (
                    "action_text",
                    models.CharField(
                        blank=True, help_text="Texte du bouton d'action", max_length=100
                    ),
                ),
                (
                    "expires_at",
                    models.DateTimeField(
                        blank=True, help_text="Date d'expiration", null=True
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant créé cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "recipient",
                    models.ForeignKey(
                        help_text="Destinataire de la notification",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant modifié cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "5.3 - Notification",
                "verbose_name_plural": "5.3 - Notifications",
                "db_table": "notifications",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["recipient", "is_read"],
                        name="notificatio_recipie_583549_idx",
                    ),
                    models.Index(
                        fields=["created_at", "priority"],
                        name="notificatio_created_1df743_idx",
                    ),
                    models.Index(
                        fields=["expires_at"], name="notificatio_expires_66996e_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="AuditLog",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Identifiant unique UUID",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Date et heure de création"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Date et heure de dernière modification",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True, help_text="Indique si l'enregistrement est actif"
                    ),
                ),
                (
                    "action_type",
                    models.CharField(
                        choices=[
                            ("create", "Création"),
                            ("update", "Modification"),
                            ("delete", "Suppression"),
                            ("login", "Connexion"),
                            ("logout", "Déconnexion"),
                            ("transaction", "Transaction"),
                            ("approval", "Approbation"),
                            ("rejection", "Rejet"),
                            ("suspension", "Suspension"),
                            ("activation", "Activation"),
                            ("password_change", "Changement Mot de Passe"),
                            ("export", "Export de Données"),
                            ("import", "Import de Données"),
                            ("rental_action", "Action de Location"),
                            ("assigned", "Assignation"),
                            ("started", "Démarrage"),
                            ("completed", "Terminaison"),
                            ("cancelled", "Annulation"),
                            ("validation_requested", "Demande de validation"),
                            ("approved", "Approbation"),
                            ("rejected", "Rejet"),
                            ("attachment_added", "Pièce jointe ajoutée"),
                            ("attachment_removed", "Pièce jointe supprimée"),
                            ("comment_added", "Commentaire ajouté"),
                            ("notification_sent", "Notification envoyée"),
                            ("scheduled", "Planification"),
                            ("rescheduled", "Reprogrammation"),
                            ("cost_updated", "Coût mis à jour"),
                        ],
                        help_text="Type d'action effectuée",
                        max_length=50,
                    ),
                ),
                ("object_id", models.CharField(blank=True, max_length=50)),
                (
                    "description",
                    models.TextField(help_text="Description détaillée de l'action"),
                ),
                (
                    "ip_address",
                    models.GenericIPAddressField(
                        blank=True, help_text="Adresse IP de l'utilisateur", null=True
                    ),
                ),
                (
                    "user_agent",
                    models.TextField(blank=True, help_text="User Agent du navigateur"),
                ),
                (
                    "metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Données supplémentaires (JSON)",
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant créé cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "object_type",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant modifié cet enregistrement",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        help_text="Utilisateur ayant effectué l'action (NULL pour les actions système)",
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="audit_logs",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "5.2 - Log d'Audit",
                "verbose_name_plural": "5.2 - Logs d'Audit",
                "db_table": "audit_log",
                "indexes": [
                    models.Index(
                        fields=["user", "action_type"],
                        name="audit_log_user_id_a29c19_idx",
                    ),
                    models.Index(
                        fields=["object_type", "object_id"],
                        name="audit_log_object__2c3174_idx",
                    ),
                    models.Index(
                        fields=["created_at"], name="audit_log_created_5a7975_idx"
                    ),
                    models.Index(
                        fields=["action_type", "created_at"],
                        name="audit_log_action__8aa0c0_idx",
                    ),
                ],
            },
        ),
    ]
