-- Migration: Création de la table themes
-- Date: 2025-09-09
-- Description: Table pour la gestion des thèmes et personnalisation

CREATE TABLE `themes` (
    `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` varchar(255) NOT NULL,
    `slug` varchar(255) NOT NULL,
    `description` text NULL DEFAULT NULL,
    `version` varchar(50) NOT NULL DEFAULT '1.0.0',
    `author` varchar(255) NULL DEFAULT NULL,
    `is_active` tinyint(1) NOT NULL DEFAULT 0,
    `is_default` tinyint(1) NOT NULL DEFAULT 0,
    `config` json NULL DEFAULT NULL,
    `custom_css` longtext NULL DEFAULT NULL,
    `custom_js` longtext NULL DEFAULT NULL,
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `themes_slug_unique` (`slug`),
    KEY `themes_is_active_index` (`is_active`),
    KEY `themes_is_default_index` (`is_default`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table pour les variables de thème (couleurs, polices, etc.)
CREATE TABLE `theme_variables` (
    `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    `theme_id` bigint(20) UNSIGNED NOT NULL,
    `variable_key` varchar(255) NOT NULL,
    `variable_value` text NOT NULL,
    `variable_type` enum('color', 'font', 'size', 'image', 'text', 'number') NOT NULL DEFAULT 'text',
    `variable_group` varchar(100) NULL DEFAULT NULL,
    `sort_order` int(11) NOT NULL DEFAULT 0,
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `theme_variables_theme_key_unique` (`theme_id`, `variable_key`),
    KEY `theme_variables_variable_type_index` (`variable_type`),
    KEY `theme_variables_variable_group_index` (`variable_group`),
    FOREIGN KEY (`theme_id`) REFERENCES `themes` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;