-- Insert new OHS inspection and compliance forms

INSERT INTO forms (id, name, description, mapped_table, elements, tenant_id, branch_id)
SELECT 100, 'Workplace Safety Inspection Checklist', 'Checklist for routine workplace safety inspections', 'ohs_inspections',
'[
  {"label":"workplace_id","field_name":"workplace_id","data_column":"workplace_id","type_id":4,"options_table":"workplace_registrations","options_label_column":"company_name","options_value_column":"id","order_index":1},
  {"label":"inspection_id","field_name":"inspection_id","data_column":"inspection_id","type_id":16,"order_index":2},
  {"label":"Emergency Exits Clear","field_name":"emergency_exits","json_column":"form_data","type_id":5,"order_index":3},
  {"label":"Fire Extinguishers Serviced","field_name":"fire_extinguishers","json_column":"form_data","type_id":5,"order_index":4},
  {"label":"Walkways Clear","field_name":"walkways_clear","json_column":"form_data","type_id":5,"order_index":5}
]', NULL, NULL
WHERE NOT EXISTS (SELECT 1 FROM forms WHERE id = 100);

INSERT INTO forms (id, name, description, mapped_table, elements, tenant_id, branch_id)
SELECT 101, 'Occupational Health Services Audit Form', 'Audit of occupational health services and programs', 'ohs_inspections',
'[
  {"label":"workplace_id","field_name":"workplace_id","data_column":"workplace_id","type_id":4,"options_table":"workplace_registrations","options_label_column":"company_name","options_value_column":"id","order_index":1},
  {"label":"inspection_id","field_name":"inspection_id","data_column":"inspection_id","type_id":16,"order_index":2},
  {"label":"Wellness Programs Available","field_name":"wellness_programs","json_column":"form_data","type_id":5,"order_index":3},
  {"label":"First Aid Kits Stocked","field_name":"first_aid_kits","json_column":"form_data","type_id":5,"order_index":4},
  {"label":"PPE Provided","field_name":"ppe_provided","json_column":"form_data","type_id":5,"order_index":5},
  {"label":"Training Records Up To Date","field_name":"training_records","json_column":"form_data","type_id":5,"order_index":6}
]', NULL, NULL
WHERE NOT EXISTS (SELECT 1 FROM forms WHERE id = 101);

INSERT INTO forms (id, name, description, mapped_table, elements, tenant_id, branch_id)
SELECT 102, 'Compliance Certificate Verification Checklist', 'Verification of workplace compliance certificates', 'ohs_inspections',
'[
  {"label":"workplace_id","field_name":"workplace_id","data_column":"workplace_id","type_id":4,"options_table":"workplace_registrations","options_label_column":"company_name","options_value_column":"id","order_index":1},
  {"label":"inspection_id","field_name":"inspection_id","data_column":"inspection_id","type_id":16,"order_index":2},
  {"label":"Certificate Valid","field_name":"certificate_valid","json_column":"form_data","type_id":5,"order_index":3},
  {"label":"Permit Displayed","field_name":"permit_displayed","json_column":"form_data","type_id":5,"order_index":4},
  {"label":"Insurance Current","field_name":"insurance_current","json_column":"form_data","type_id":5,"order_index":5}
]', NULL, NULL
WHERE NOT EXISTS (SELECT 1 FROM forms WHERE id = 102);

SELECT setval('forms_id_seq', (SELECT MAX(id) FROM forms));
