-- CSR Report Role Update Migration
-- Run this once in phpMyAdmin / cPanel SQL after uploading the updated code.

ALTER TABLE csr_users
  MODIFY role ENUM('csr','team_leader','csr_manager') NOT NULL DEFAULT 'csr';

-- Existing Team Leader accounts were previously saved as csr_manager.
UPDATE csr_users
SET role = 'team_leader'
WHERE id IN (SELECT manager_id FROM csr_teams);

-- Create the single CSR Manager account only if none exists yet.
-- Default login: csrmanager@example.com / password123
-- Change the password immediately after first login.
INSERT INTO csr_users (first_name, last_name, email, phone_number, password, is_active, max_active_chats, role)
SELECT 'CSR', 'Manager', 'csrmanager@example.com', NULL, '$2y$12$9meKllOEQQ5mDE5SzUjw6O2mg772hCXpos5rWUYySm8MBz3XkJ9.q', 1, 5, 'csr_manager'
WHERE NOT EXISTS (SELECT 1 FROM csr_users WHERE role = 'csr_manager');
