-- Migration: Create user_dashboard_config table
-- Date: 2025-12-08
-- Description: Stores user's customizable dashboard widget configuration as JSON

CREATE TABLE IF NOT EXISTS user_dashboard_config (
    id INT PRIMARY KEY AUTO_INCREMENT,
    user_id INT NOT NULL,
    config JSON NOT NULL COMMENT 'Dashboard widget configuration including order, visibility, and settings',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE,
    UNIQUE KEY unique_user_config (user_id),
    INDEX idx_user_id (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='Stores customizable dashboard configurations for each user';

-- Insert example default configuration for reference
-- INSERT INTO user_dashboard_config (user_id, config) VALUES 
-- (1, '{
--   "widgets": [
--     {"id": "hero_slider", "type": "hero", "enabled": true, "order": 0},
--     {"id": "quick_actions", "type": "actions", "enabled": true, "order": 1},
--     {"id": "stats", "type": "statistics", "enabled": true, "order": 2},
--     {"id": "enrolled_courses", "type": "courses", "enabled": true, "order": 3},
--     {"id": "superapp", "type": "superapp", "enabled": true, "order": 4},
--     {"id": "recent_activity", "type": "activity", "enabled": true, "order": 5}
--   ],
--   "theme": "default",
--   "layout": "grid"
-- }');
