-- Update Workplace Registration Review workflow for invoice preview modal
DELETE FROM workflow_steps
WHERE workflow_id = (SELECT id FROM workflows WHERE name='Workplace Registration Review')
  AND step_type = 'open_form';

INSERT INTO workflow_steps (workflow_id, step_order, step_type, config)
SELECT w.id, 4, 'open_modal', '{"modal":"Workplace Invoice Preview"}'
FROM workflows w
WHERE w.name='Workplace Registration Review'
  AND NOT EXISTS (
    SELECT 1 FROM workflow_steps ws
    WHERE ws.workflow_id = w.id AND ws.step_order = 4 AND ws.step_type='open_modal'
  );
