-- Add notification settings for payout requests
-- First, check if the settings already exist
DO $$
BEGIN
  -- Try to update existing records first
  UPDATE "Setting" 
  SET "value" = 'true', "updatedAt" = NOW() 
  WHERE "key" = 'notify_admin_on_payout_request';
  
  -- If no row was updated, insert new record
  IF NOT FOUND THEN
    INSERT INTO "Setting" ("id", "key", "value", "createdAt", "updatedAt")
    VALUES (
      -- Using CUID pattern like Prisma does by default
      'cl' || SUBSTR(MD5(RANDOM()::TEXT), 1, 24),
      'notify_admin_on_payout_request',
      'true',
      NOW(),
      NOW()
    );
  END IF;

  -- Repeat for second setting
  UPDATE "Setting" 
  SET "value" = 'true', "updatedAt" = NOW() 
  WHERE "key" = 'notify_finance_on_payout_request';
  
  -- If no row was updated, insert new record
  IF NOT FOUND THEN
    INSERT INTO "Setting" ("id", "key", "value", "createdAt", "updatedAt")
    VALUES (
      -- Using CUID pattern like Prisma does by default
      'cl' || SUBSTR(MD5(RANDOM()::TEXT), 1, 24),
      'notify_finance_on_payout_request',
      'true',
      NOW(),
      NOW()
    );
  END IF;
END $$;
