-- Add QC_USER_2 role to existing database and update display names
-- This migration adds the new QC_USER_2 role with full QC status access

-- Update QC_USER display name to qc_user_1
UPDATE user_master 
SET role_display_name = 'qc_user_1',
    description = 'Quality control access with data verification permissions (Level 1)',
    "updatedAt" = NOW()
WHERE role_name = 'QC_USER';

-- Add or update QC_USER_2 role with display name qc_user_2
INSERT INTO user_master (id, role_name, role_display_name, description, permissions, is_active, sort_order, "createdAt", "updatedAt")
VALUES (
  7,
  'QC_USER_2',
  'qc_user_2',
  'Advanced quality control access with full QC status options including Level 2 Hold, Verified, and Rejected',
  '{"can_view_all_data": true, "can_verify_data": true, "can_set_level_2_hold": true, "can_verify_final": true, "can_reject": true}'::json,
  true,
  7,
  NOW(),
  NOW()
)
ON CONFLICT (role_name) DO UPDATE SET
  role_display_name = EXCLUDED.role_display_name,
  description = EXCLUDED.description,
  permissions = EXCLUDED.permissions,
  sort_order = EXCLUDED.sort_order,
  "updatedAt" = NOW();

-- Verify both roles
SELECT id, role_name, role_display_name, description, is_active, sort_order
FROM user_master
WHERE role_name IN ('QC_USER', 'QC_USER_2')
ORDER BY id;
