-- Create Training and Compliance document categories and modals

-- Insert categories if they do not already exist
INSERT INTO document_categories (name)
SELECT 'Training'
WHERE NOT EXISTS (SELECT 1 FROM document_categories WHERE name = 'Training');

INSERT INTO document_categories (name)
SELECT 'Compliance'
WHERE NOT EXISTS (SELECT 1 FROM document_categories WHERE name = 'Compliance');

-- Training Documents modal
INSERT INTO ui_modals (name, config, tenant_id, branch_id, icon, aria_label, description)
SELECT 'Training Documents',
       jsonb_build_object(
           'title', 'Training Documents',
           'body', jsonb_build_array(
               jsonb_build_object('type','documents','options', jsonb_build_object('category_id', id, 'scope','tenant'))
           ),
           'footer', jsonb_build_array(jsonb_build_object('type','button','label','Close','onClick','closeModal'))
       ),
       NULL, NULL, 'fa-folder-open', 'Training Documents', 'Training Documents'
FROM document_categories
WHERE name = 'Training'
  AND NOT EXISTS (SELECT 1 FROM ui_modals WHERE name = 'Training Documents');

-- Compliance Documents modal
INSERT INTO ui_modals (name, config, tenant_id, branch_id, icon, aria_label, description)
SELECT 'Compliance Documents',
       jsonb_build_object(
           'title', 'Compliance Documents',
           'body', jsonb_build_array(
               jsonb_build_object('type','documents','options', jsonb_build_object('category_id', id, 'scope','tenant','showExpiry', true))
           ),
           'footer', jsonb_build_array(jsonb_build_object('type','button','label','Close','onClick','closeModal'))
       ),
       NULL, NULL, 'fa-folder-open', 'Compliance Documents', 'Compliance Documents'
FROM document_categories
WHERE name = 'Compliance'
  AND NOT EXISTS (SELECT 1 FROM ui_modals WHERE name = 'Compliance Documents');
