-- Migration: Add Alesi user to Karunaratne Lawyers
-- Date: 2025-11-23
-- Description: Adds a new user with Member role (same as Roma) and hourly rate of 100
--              Organization: Karunaratne Lawyers (0194a8b2-5678-7123-8123-123456789abd)
--              Password: Alesi2025**

-- Add Alesi user
WITH alesi_user AS (
  SELECT '0194a8b2-444a-7123-8123-123456789ac3'::uuid AS user_id
), ins_user AS (
  INSERT INTO users (user_id, full_name, is_superadmin)
  VALUES ((SELECT user_id FROM alesi_user), 'Alesi', FALSE)
  ON CONFLICT DO NOTHING
  RETURNING user_id
), ins_email AS (
  INSERT INTO user_emails (user_id, email, is_primary)
  SELECT user_id, 'alesi@karunaratnelawyers.com.fj', true FROM alesi_user
  ON CONFLICT DO NOTHING
), ins_password AS (
  INSERT INTO user_passwords (user_id, password_hash, algo)
  SELECT user_id, '$2y$10$cw.hat.w092M2EpX5jpW3.EBuM.haJosdoOBP3UUujapQvvfQtYGO', 'bcrypt' FROM alesi_user
  ON CONFLICT DO NOTHING
), ins_membership AS (
  INSERT INTO user_org_memberships (user_id, org_id, role, options)
  SELECT 
    user_id, 
    '0194a8b2-5678-7123-8123-123456789abd'::uuid, 
    'Member',
    '{"hourly_rate": 100}'::jsonb
  FROM alesi_user
  ON CONFLICT DO NOTHING
)
SELECT 1;
