-- Create severity lookup table
CREATE TABLE IF NOT EXISTS ohs_severities (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO ohs_severities (name, tenant_id, branch_id)
VALUES
  ('Minor', NULL, NULL),
  ('Moderate', NULL, NULL),
  ('Major', NULL, NULL),
  ('Severe', NULL, NULL),
  ('Critical', NULL, NULL)
ON CONFLICT DO NOTHING;

-- Update OHS Incident Classification form
UPDATE forms
SET elements = $json$[
    {"label":"Classification","field_name":"classification","data_column":"classification","type_id":4,"order_index":1,"options_table":"ohs_incident_types","options_label_column":"name","options_value_column":"name"},
    {"label":"Location","field_name":"location","data_column":"location","type_id":4,"order_index":2,"options_table":"locations","options_label_column":"name","options_value_column":"name","options":[{"display_text":"Other","value":"Other"}]},
    {"label":"Address","field_name":"address","data_column":"address","type_id":7,"order_index":3,"show_when":{"field":"location","value":"Other"}},
    {"label":"Severity","field_name":"severity","data_column":"severity","type_id":4,"order_index":4,"options_table":"ohs_severities","options_label_column":"name","options_value_column":"name"}
]$json$
WHERE id = 59;
