-- Training Certificate form

INSERT INTO forms (id, name, description, mapped_table, elements, tenant_id, branch_id)
SELECT 72, 'Training Certificate', 'Employee training record', 'training_certificates',
'[
  {"label":"course_id","field_name":"course_id","data_column":"course_id","type_id":4,"options_table":"training_courses","options_label_column":"name","options_value_column":"id","order_index":1},
  {"label":"category_id","field_name":"category_id","data_column":"category_id","type_id":4,"options_table":"training_categories","options_label_column":"name","options_value_column":"id","order_index":2},
  {"label":"employee_id","field_name":"employee_id","data_column":"employee_id","type_id":4,"options_table":"employees","options_label_column":"name","options_value_column":"id","order_index":3},
  {"label":"issued_at","field_name":"issued_at","data_column":"issued_at","type_id":3,"order_index":4},
  {"label":"expiry_date","field_name":"expiry_date","data_column":"expiry_date","type_id":3,"order_index":5}
]', NULL, NULL
WHERE NOT EXISTS (SELECT 1 FROM forms WHERE id = 72);

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