-- Migration: User Dashboard Preferences
-- Allows users to customize dashboard layout, order, sizes, and collapsed state

CREATE TABLE IF NOT EXISTS user_dashboard_preferences (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    dashboard_name VARCHAR(50) NOT NULL COMMENT 'e.g., hr, accounting, crm, sales, etc.',
    widget_id VARCHAR(100) NOT NULL COMMENT 'Unique identifier for the widget/card',
    display_order INT DEFAULT 0 COMMENT 'Order in which widget appears',
    column_size INT DEFAULT 6 COMMENT 'Bootstrap column size: 3, 6, 9, or 12',
    is_collapsed TINYINT(1) DEFAULT 0 COMMENT '1 if minimized, 0 if expanded',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY unique_user_dashboard_widget (user_id, dashboard_name, widget_id),
    INDEX idx_user_dashboard (user_id, dashboard_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='Stores user-specific dashboard layout preferences';
