/**
 * Assign First Admin User
 * 
 * Purpose: Quick script to make your first user an ADMIN after fresh setup
 * 
 * Usage:
 * 1. Replace YOUR_EMAIL below with your actual email
 * 2. Run: psql -d royal_enfield_workflow -f scripts/assign-admin-user.sql
 */

-- ============================================
-- UPDATE THIS EMAIL WITH YOUR ACTUAL EMAIL
-- ============================================

\echo 'Assigning ADMIN role to user...\n'

UPDATE users 
SET role = 'ADMIN'
WHERE email = 'YOUR_EMAIL@{{APP_DOMAIN}}'  -- ← CHANGE THIS
RETURNING 
  user_id,
  email, 
  display_name, 
  role,
  updated_at;

\echo '\n✅ Admin role assigned!\n'

-- Display all current admins
\echo 'Current ADMIN users:'
SELECT 
  email, 
  display_name, 
  department,
  role,
  created_at
FROM users 
WHERE role = 'ADMIN' AND is_active = true
ORDER BY email;

-- Display role summary
\echo '\nRole Summary:'
SELECT 
  role,
  COUNT(*) as count
FROM users 
WHERE is_active = true
GROUP BY role
ORDER BY 
  CASE role
    WHEN 'ADMIN' THEN 1
    WHEN 'MANAGEMENT' THEN 2
    WHEN 'USER' THEN 3
  END;

