-- Migration 02: Add admin_logs table and debug_mode setting
-- Run this on your database to enable admin logging and debug toggle

-- Table pour les logs d'actions admin
CREATE TABLE IF NOT EXISTS `admin_logs` (
    `id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `user_id` INT UNSIGNED NULL,
    `brand_id` INT UNSIGNED NULL,
    `action` VARCHAR(100) NOT NULL,
    `entity` VARCHAR(100) NOT NULL,
    `details` JSON NULL,
    `ip_address` VARCHAR(45) NULL,
    `user_agent` TEXT NULL,
    `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX `idx_admin_logs_user` (`user_id`),
    INDEX `idx_admin_logs_brand` (`brand_id`),
    INDEX `idx_admin_logs_action` (`action`),
    INDEX `idx_admin_logs_entity` (`entity`),
    INDEX `idx_admin_logs_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Paramètre debug_mode
INSERT INTO `settings` (`setting_key`, `setting_value`, `setting_type`, `description`, `created_at`, `updated_at`)
VALUES ('debug_mode', '0', 'bool', 'Active le mode debug (affiche les erreurs détaillées)', NOW(), NOW())
ON DUPLICATE KEY UPDATE `updated_at` = NOW();

-- Dossier logs
-- Note: Le dossier admin-uri/logs/ doit être créé manuellement avec les permissions d'écriture
