-- Add vishal@saventh.com and prateek@saventh.com for access to all 5 projects
-- CRM: users | Corporate: corp_representatives | Learn/Investor: allow all authenticated

-- CRM: Ensure both have Admin role
INSERT INTO users (role, full_name, email)
SELECT ur.id, 'Vishal', 'vishal@saventh.com' FROM user_roles ur WHERE ur.name = 'Admin' LIMIT 1
ON CONFLICT (email) DO UPDATE SET role = (SELECT id FROM user_roles WHERE name = 'Admin' LIMIT 1), full_name = 'Vishal';

INSERT INTO users (role, full_name, email)
SELECT ur.id, 'Prateek', 'prateek@saventh.com' FROM user_roles ur WHERE ur.name = 'Admin' LIMIT 1
ON CONFLICT (email) DO UPDATE SET role = (SELECT id FROM user_roles WHERE name = 'Admin' LIMIT 1), full_name = 'Prateek';

-- Corporate: Add as representatives (requires corp_master to exist)
INSERT INTO corp_representatives (corp_id, name, email, role)
SELECT 
  (SELECT id FROM corp_master ORDER BY created_at LIMIT 1),
  'Vishal',
  'vishal@saventh.com',
  'representative'
WHERE NOT EXISTS (SELECT 1 FROM corp_representatives WHERE email = 'vishal@saventh.com')
  AND EXISTS (SELECT 1 FROM corp_master LIMIT 1);

INSERT INTO corp_representatives (corp_id, name, email, role)
SELECT 
  (SELECT id FROM corp_master ORDER BY created_at LIMIT 1),
  'Prateek',
  'prateek@saventh.com',
  'representative'
WHERE NOT EXISTS (SELECT 1 FROM corp_representatives WHERE email = 'prateek@saventh.com')
  AND EXISTS (SELECT 1 FROM corp_master LIMIT 1);
