-- Add super_admin role to the users table role enum
-- Migration: 022_add_super_admin_role

-- Modify the role column to include super_admin
ALTER TABLE users 
MODIFY COLUMN role ENUM('admin', 'manager', 'member', 'super_admin') NOT NULL DEFAULT 'member';

-- Update the designation column to NOT be required (set as nullable)
-- This was causing issues where we couldn't create super admin without a designation
ALTER TABLE users 
MODIFY COLUMN designation ENUM('website_designer','website_developer','ui_ux_designer','project_manager','qa_tester','content_writer') NULL;

-- Create a super admin user if one doesn't exist
INSERT IGNORE INTO users (
    email, 
    password_hash, 
    full_name, 
    role, 
    email_verified, 
    is_active,
    organization_id
) VALUES (
    'superadmin@flochief.com',
    '$2a$12$LQv3c1yqBwlHb5vOBaKHkeSJDSDVYHmj5gV8rA1ZLd1VqKfFbGo1q', -- Password: SuperAdmin123!
    'Super Administrator',
    'super_admin',
    1,
    1,
    NULL  -- Super admin doesn't belong to any specific organization
);