START TRANSACTION;

-- Align template definitions with the relocated form files
UPDATE form_templates
SET form_url = 'forms/treatment_evaluation/form_fill_te.php'
WHERE id = 4 AND form_url = 'form_fill_te.php';

UPDATE form_templates
SET form_url = 'forms/skin_typing_consent/form_fill_skin_typing.php'
WHERE id = 6 AND form_url IN ('form_fill_ipl_c.php', 'form_fill_skin_typing.php');

UPDATE form_templates
SET form_url = 'forms/ipl_consent/form_fill_ipl_c.php'
WHERE id IN (5, 7, 8, 9, 10, 11, 12)
  AND form_url = 'form_fill_ipl_c.php';

-- Update client form instances that still point at legacy locations
UPDATE client_forms
SET form_url = CASE
    WHEN form_template_id = 4 THEN 'forms/treatment_evaluation/form_fill_te.php'
    WHEN form_template_id = 6 THEN 'forms/skin_typing_consent/form_fill_skin_typing.php'
    WHEN form_template_id IN (5, 7, 8, 9, 10, 11, 12) THEN 'forms/ipl_consent/form_fill_ipl_c.php'
    ELSE form_url
END
WHERE form_url IN ('form_fill_te.php', 'form_fill_ipl_c.php');

COMMIT;
