-- Update Safety Incident form label and modal column label

-- PostgreSQL
UPDATE forms
SET elements = REPLACE(elements::text, '"label":"File Path"', '"label":"Documents"')::jsonb
WHERE id = 97;

UPDATE ui_modals
SET config = jsonb_set(
    config,
    '{body,0,options,columnLabels}',
    '{"file_path":"Documents"}'::jsonb,
    true
)
WHERE name = 'Safety Incidents';

-- MySQL
UPDATE forms
SET elements = REPLACE(elements, '"label":"File Path"', '"label":"Documents"')
WHERE id = 97;

UPDATE ui_modals
SET config = JSON_SET(config, '$.body[0].options.columnLabels', JSON_OBJECT('file_path','Documents'))
WHERE name = 'Safety Incidents';

-- Ensure modal exists with updated configuration
INSERT INTO ui_modals (name, config, tenant_id, branch_id, icon, aria_label, description)
SELECT 'Safety Incidents', '{"title":"Safety Incidents","header":[{"type":"button","label":"Add Incident","formName":"Safety Incident"}],"body":[{"type":"table","options":{"tableName":"safety_incidents","showGlobalSearch":false,"addButton":false,"editFormId":97,"columnLabels":{"file_path":"Documents"}}}],"footer":[{"type":"button","label":"Close","onClick":"closeModal"}]}', NULL, NULL, 'fa-helmet-safety', 'Safety Incidents', 'Safety Incidents'
WHERE NOT EXISTS (SELECT 1 FROM ui_modals WHERE name = 'Safety Incidents');
