INSERT INTO ohrm_data_group (name, description, can_read, can_create, can_update, can_delete)
VALUES ('preboarding_qualifications', 'Preboarding - Stage 10: Qualifications', 1, 0, 1, 0);

SET @data_group_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'preboarding_qualifications');
SET @admin_user_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'Admin');
SET @supervisor_id := (SELECT id FROM ohrm_user_role where name = 'Supervisor');
SET @hod_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'HeadOfDepartment');
SET @hiring_manager_user_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'HiringManager');
SET @pre_boarding_event_manager_user_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'PreboardingEventManager');
SET @admin_user_role_type := (SELECT `id` FROM `ohrm_user_role_type` WHERE `name` = 'Admin');
SET @supervisor_role_type := (SELECT `id` FROM `ohrm_user_role_type` WHERE `name` = 'Supervisor');
SET @preboarding_new_hire_user_role_id = (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'PreboardingNewHire');
SET @ess_id := (SELECT id FROM ohrm_user_role where name = 'ESS');
SET @ess_role_type := (SELECT `id` FROM `ohrm_user_role_type` WHERE `name` = 'ESS');

INSERT INTO ohrm_user_role_data_group (user_role_id, data_group_id, can_read, can_create, can_update, can_delete, self, restriction_id) VALUES
    (@admin_user_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL),
    (@supervisor_id, @data_group_id, 1, 0, 1, 0, 0, NULL),
    (@hod_user_role, @data_group_id, 1, 0, 1, 0, 0, NULL),
    (@hiring_manager_user_role_id, @data_group_id, 1, 1, 0, 0, 0, NULL),
    (@pre_boarding_event_manager_user_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL),
    (@preboarding_new_hire_user_role_id, @data_group_id, 1, 0, 1, 0, 1, NULL),
    (@ess_id, @data_group_id, 1, 0, 1, 0, 1, NULL);

INSERT INTO ohrm_user_role_type_data_group (user_role_type_id, data_group_id, can_read, can_create, can_update, can_delete) VALUES
    (@admin_user_role_type, @data_group_id, 1, 0, 1, 0),
    (@supervisor_role_type, @data_group_id, 1, 0, 1, 0),
    (@ess_role_type, @data_group_id, 1, 0, 1, 0);

SET @system_user_id := (SELECT `id` FROM `ohrm_user` WHERE `user_name` = 'System');

-- Work Experience Child Form

INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Work Experience Record', 'Preboarding Work Experience Record', 'POST', 'preboarding-work-experience-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1);
SET @child_work_experience_dynamic_form_id := (SELECT `id`
                         FROM ohrm_dynamic_form
                         WHERE name = 'Preboarding Work Experience Record');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Work Experience Record', 'Preboarding Work Experience Record', 'POST', 'preboarding-work-experience-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1, @child_work_experience_dynamic_form_id);
SET @child_work_experience_dynamic_form_version_id := (SELECT `id`
                                 FROM ohrm_dynamic_form_version
                                 WHERE name = 'Preboarding Work Experience Record');

SET @child_work_experience_meta =  CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
    {
      "uid": "company_010",
      "name": "company",
      "widget": "textbox",
      "label": "Company",
      "attr": {
        "required": true,
        "rows": "1",
        "style": "min-height: 45px"
      },
      "validations": [
        "#required",
        "#length:0,100"
      ]
    },
    {
      "uid": "job_title_010",
      "name": "job_title",
      "widget": "textbox",
      "label": "Job Title",
      "attr": {
        "required": true,
        "rows": "1",
        "style": "min-height: 45px"
      },
      "validations": [
        "#required",
        "#length:0,100"
      ]
    },
    {
      "uid": "from_date_010",
      "name": "from_date",
      "widget": "datepicker",
      "label": "From",
      "validations": [
        "#date_format:yyyy-mm-dd",
        "#date",
        "#valid_past_date",
        "#equal_or_before_date:$to_date,From date should be before to date"
      ]
    },
    {
      "uid": "to_date_010",
      "name": "to_date",
      "widget": "datepicker",
      "label": "To",
      "validations": [
        "#date_format:yyyy-mm-dd",
        "#date",
        "#valid_past_date",
        "#equal_or_after_date:$from_date,To date should be after From date"
      ]
    },
    {
      "uid": "comment_010",
      "name": "comment",
      "label": "Comment",
      "widget": "textbox",
      "validations": [
        "#length:0,200"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form010",
      "action": "POST",
      "endpoint": "forms/010",
      "body": [
        {
          "uid": "form010_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 2,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form010_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "company_010"
                    }
                  ]
                }
              },
              {
                "uid": "form010_grid_item_2",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "job_title_010"
                    }
                  ]
                }
              },
              {
                "uid": "form010_grid_item_3",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "from_date_010"
                    }
                  ]
                }
              },
              {
                "uid": "form010_grid_item_4",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "to_date_010"
                    }
                  ]
                }
              },
              {
                "uid": "form010_grid_item_6",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "comment_010"
                    }
                  ]
                }
              }
            ]
          }
        }
      ],
      "model": {
        "company": "",
        "job_title": "",
        "from_date": "",
        "to_date": "",
        "comment": ""
      },
      "computed": [],
      "methods": {}
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @child_work_experience_meta WHERE id = @child_work_experience_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @child_work_experience_meta WHERE id = @child_work_experience_dynamic_form_version_id;


INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Work Experience', 'Preboarding Work Experience', 'POST',
        'preboarding-work-experience', null, @data_group_id, @system_user_id, @system_user_id, 'System', 1);

SET @work_experience_dynamic_form_id := (SELECT `id` FROM ohrm_dynamic_form WHERE name = 'Preboarding Work Experience');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Work Experience', 'Preboarding Work Experience', 'POST', 'preboarding-work-experience',
        null, @data_group_id, @system_user_id, @system_user_id, 'System', 1, @work_experience_dynamic_form_id);

SET @work_experience_dynamic_form_version_id := (SELECT `id` FROM ohrm_dynamic_form_version WHERE name = 'Preboarding Work Experience');

SET @work_experience_metadata := CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
    {
      "uid": "work_experience_0010",
      "name": "work_experience",
      "label": "Work Experience",
      "widget": "oxd-subform-widget",
      "attr": {
        "min": 1,
        "max": 3,
        "endpoint": "preboarding-work-experience-record"
      },
      "validations": [
        "#childForm:',@child_work_experience_dynamic_form_version_id,',1,3"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form0010",
      "action": "POST",
      "endpoint": "forms/10",
      "body": [
        {
          "uid": "form0010_header",
          "tag": "div",
          "props": {
            "style": "display: flex;"
          },
          "slots": {
            "default": [
              {
                "uid": "form0010_title",
                "tag": "oxd-text",
                "props": {
                  "type": "card-title"
                },
                "slots": {
                  "default": [
                    "Work Experience"
                  ]
                }
              },
              {
                "uid": "form0010_status",
                "tag": "oxd-status-chip",
                "props": {
                  "style": "margin-left: 10px;",
                  "status": "##advancedTask.status##"
                }
              }
            ]
          }
        },
        {
          "uid": "form0010_br",
          "tag": "br"
        },
        {
          "uid": "form0010_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 1,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form0010_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "work_experience_0010"
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "uid": "form0010_divider",
          "tag": "oxd-divider",
          "props": {
            "style": "margin-bottom: 1rem;"
          }
        },
        {
          "uid": "form0010_buttons",
          "tag": "div",
          "props": {
            "class": "orangehrm-form-actions"
          },
          "slots": {
            "default": [
              {
                "uid": "form0010_required_text",
                "tag": "oxd-required-text"
              },
              {
                "uid": "form0010_button_save",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Save",
                  "display-type": "secondary",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSaveButton"
                }
              },
              {
                "uid": "form0010_button_submit",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Submit",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSubmitButton"
                }
              },
              {
                "uid": "form0010_button_reject",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Reject",
                  "display-type": "label-feedback-reject",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickRejectButton"
                }
              },
              {
                "uid": "form0010_button_approve",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Approve",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickApproveButton"
                }
              }
            ]
          }
        }
      ],
      "model": {
        "work_experience": [
          {
            "company": "",
            "job_title": "",
            "from_date": "",
            "to_date": "",
            "comment": ""
          }
        ]
      },
      "computed": {},
      "methods": {
        "onClickSubmitButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Submit Work Experience Details",
            "message": "Please ensure the details provided are accurate.",
            "messageAlt": "The details cannot be edited after submission.",
            "confirmText": "Yes, Submit",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Submit"
          },
          "#toast": {
            "error": "Failed to Submit",
            "success": "Successfully Submitted"
          }
        },
        "onClickSaveButton": {
          "#validate": {},
          "#save": {
            "action": "Save"
          },
          "#toast": {
            "error": "Failed to Save",
            "success": "Successfully Saved"
          }
        },
        "onClickApproveButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Approve Work Experience Details",
            "message": "By approving, you confirm that all work experience details are accurate and satisfactory.",
            "confirmText": "Yes, Approve",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Approve",
            "skipFormData": true
          },
          "#toast": {
            "error": "Work Experience Details Approval Failed",
            "success": "Work Experience Details Has Been Approved"
          }
        },
        "onClickRejectButton": {
          "#validate": {},
          "#prompt": {
            "title": "Reject Work Experience Details",
            "message": "Rejecting the work experience details will prompt the new hire to resubmit the necessary details. The reason for rejection will be sent to the new hire.",
            "confirmDisplayType": "label-feedback-reject",
            "confirmText": "Yes, Reject",
            "cancelText": "No, Cancel",
            "inputType": "textarea",
            "inputLabel": "Comment"
          },
          "#save": {
            "action": "Reject",
            "skipFormData": true
          },
          "#toast": {
            "error": "Work Experience Details Rejection Failed",
            "success": "Work Experience Details Has Been Rejected"
          }
        }
      }
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @work_experience_metadata WHERE id = @work_experience_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @work_experience_metadata WHERE id = @work_experience_dynamic_form_version_id;

-- Education

INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Education Record', 'Preboarding Education Record', 'POST', 'preboarding-education-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1);
SET @child_education_dynamic_form_id := (SELECT `id`
                         FROM ohrm_dynamic_form
                         WHERE name = 'Preboarding Education Record');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Education Record', 'Preboarding Education Record', 'POST', 'preboarding-education-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1, @child_education_dynamic_form_id);
SET @child_education_dynamic_form_version_id := (SELECT `id`
                                 FROM ohrm_dynamic_form_version
                                 WHERE name = 'Preboarding Education Record');

SET @child_education_meta =  CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
      {
          "uid": "level_0011",
          "name": "level",
          "label": "Level",
          "widget": "oxd-master-data-input",
          "attr": {
            "service": "Education",
            "required": true
          },
          "validations": [
            "#required",
            "#masterDataSelect:Education"
          ]
      },
    {
      "uid": "institute_011",
      "name": "institute",
      "widget": "textbox",
      "label": "Institute",
      "attr": {
        "rows": "1",
        "style": "min-height: 45px"
      },
      "validations": [
        "#length:0,100"
      ]
    },
    {
      "uid": "major_specialization_011",
      "name": "major_specialization",
      "widget": "textbox",
      "label": "Major/Specialization",
      "attr": {
        "rows": "1",
        "style": "min-height: 45px"
      },
      "validations": [
        "#length:0,100"
      ]
    },
    {
      "uid": "year_011",
      "name": "year",
      "widget": "textbox",
      "label": "Year",
      "attr": {
        "rows": "1",
        "style": "min-height: 45px"
      },
      "validations": [
        "#numericVal",
        "#min:1",
        "#max:9999"
      ]
    },
    {
      "uid": "gpa_score_011",
      "name": "gpa_score",
      "widget": "text",
      "label": "GPA/Score",
      "validations": [
        "#length:0,25"
      ]
    },
    {
      "uid": "start_date_011",
      "name": "start_date",
      "widget": "datepicker",
      "label": "Start Date",
      "validations": [
        "#date_format:yyyy-mm-dd",
        "#date"
      ]
    },
    {
      "uid": "end_date_011",
      "name": "end_date",
      "widget": "datepicker",
      "label": "End Date",
      "validations": [
        "#date_format:yyyy-mm-dd",
        "#date",
        "#equal_or_after_date:$start_date,End Date should be after start Date"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form011",
      "action": "POST",
      "endpoint": "forms/011",
      "body": [
        {
          "uid": "form011_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 2,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form011_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "level_0011"
                    }
                  ]
                }
              },
              {
                "uid": "form011_grid_item_2",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "institute_011"
                    }
                  ]
                }
              },
              {
                "uid": "form011_grid_item_3",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "major_specialization_011"
                    }
                  ]
                }
              },
              {
                "uid": "form011_grid_item_4",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "year_011"
                    }
                  ]
                }
              },
              {
                "uid": "form011_grid_item_5",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "gpa_score_011"
                    }
                  ]
                }
              },
              {
                "uid": "form011_grid_item_6",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "start_date_011"
                    }
                  ]
                }
              },
              {
                "uid": "form011_grid_item_7",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "end_date_011"
                    }
                  ]
                }
              }
            ]
          }
        }
      ],
      "model": {
        "level": "",
        "institute": "",
        "major_specialization": "",
        "year": "",
        "gpa_score": "",
        "start_date": "",
        "end_date": ""
      },
      "computed": [],
      "methods": {}
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @child_education_meta WHERE id = @child_education_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @child_education_meta WHERE id = @child_education_dynamic_form_version_id;


INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Education', 'Preboarding Education', 'POST',
        'preboarding-education', null, @data_group_id, @system_user_id, @system_user_id, 'System', 1);

SET @education_dynamic_form_id := (SELECT `id` FROM ohrm_dynamic_form WHERE name = 'Preboarding Education');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Education', 'Preboarding Education', 'POST', 'preboarding-education',
        null, @data_group_id, @system_user_id, @system_user_id, 'System', 1, @education_dynamic_form_id);

SET @education_dynamic_form_version_id := (SELECT `id` FROM ohrm_dynamic_form_version WHERE name = 'Preboarding Education');

SET @education_metadata = CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
    {
      "uid": "education_0011",
      "name": "education",
      "label": "Education",
      "widget": "oxd-subform-widget",
      "attr": {
        "min": 1,
        "max": 3,
        "endpoint": "preboarding-education-record"
      },
      "validations": [
        "#childForm:',@child_education_dynamic_form_version_id,',1,3"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form0011",
      "action": "POST",
      "endpoint": "forms/11",
      "body": [
        {
          "uid": "form0011_header",
          "tag": "div",
          "props": {
            "style": "display: flex;"
          },
          "slots": {
            "default": [
              {
                "uid": "form0011_title",
                "tag": "oxd-text",
                "props": {
                  "type": "card-title"
                },
                "slots": {
                  "default": [
                    "Education"
                  ]
                }
              },
              {
                "uid": "form0011_status",
                "tag": "oxd-status-chip",
                "props": {
                  "style": "margin-left: 10px;",
                  "status": "##advancedTask.status##"
                }
              }
            ]
          }
        },
        {
          "uid": "form0011_br",
          "tag": "br"
        },
        {
          "uid": "form0011_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 1,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form0011_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "education_0011"
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "uid": "form0011_divider",
          "tag": "oxd-divider",
          "props": {
            "style": "margin-bottom: 1rem;"
          }
        },
        {
          "uid": "form0011_buttons",
          "tag": "div",
          "props": {
            "class": "orangehrm-form-actions"
          },
          "slots": {
            "default": [
              {
                "uid": "form0011_required_text",
                "tag": "oxd-required-text"
              },
              {
                "uid": "form0011_button_save",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Save",
                  "display-type": "secondary",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSaveButton"
                }
              },
              {
                "uid": "form0011_button_submit",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Submit",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSubmitButton"
                }
              },
              {
                "uid": "form0011_button_reject",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Reject",
                  "display-type": "label-feedback-reject",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickRejectButton"
                }
              },
              {
                "uid": "form0011_button_approve",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Approve",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickApproveButton"
                }
              }
            ]
          }
        }
      ],
      "model": {
        "education": [
          {
            "level": "",
            "institute": "",
            "major_specialization": "",
            "year": "",
            "gpa_score": "",
            "start_date": "",
            "end_date": ""
          }
        ]
      },
      "computed": {},
      "methods": {
        "onClickSubmitButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Submit Education Details",
            "message": "Please ensure the details provided are accurate.",
            "messageAlt": "The details cannot be edited after submission.",
            "confirmText": "Yes, Submit",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Submit"
          },
          "#toast": {
            "error": "Failed to Submit",
            "success": "Successfully Submitted"
          }
        },
        "onClickSaveButton": {
          "#validate": {},
          "#save": {
            "action": "Save"
          },
          "#toast": {
            "error": "Failed to Save",
            "success": "Successfully Saved"
          }
        },
        "onClickApproveButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Approve Education Details",
            "message": "By approving, you confirm that all education details are accurate and satisfactory.",
            "confirmText": "Yes, Approve",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Approve",
            "skipFormData": true
          },
          "#toast": {
            "error": "Education Details Approval Failed",
            "success": "Education Details Has Been Approved"
          }
        },
        "onClickRejectButton": {
          "#validate": {},
          "#prompt": {
            "title": "Reject Education Details",
            "message": "Rejecting the education details will prompt the new hire to resubmit the necessary details. The reason for rejection will be sent to the new hire.",
            "confirmDisplayType": "label-feedback-reject",
            "confirmText": "Yes, Reject",
            "cancelText": "No, Cancel",
            "inputType": "textarea",
            "inputLabel": "Comment"
          },
          "#save": {
            "action": "Reject",
            "skipFormData": true
          },
          "#toast": {
            "error": "Education Details Rejection Failed",
            "success": "Education Details Has Been Rejected"
          }
        }
      }
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @education_metadata WHERE id = @education_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @education_metadata WHERE id = @education_dynamic_form_version_id;

-- Skill

INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Skills Record', 'Preboarding Skills Record', 'POST', 'preboarding-skill-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1);
SET @child_skill_dynamic_form_id := (SELECT `id`
                         FROM ohrm_dynamic_form
                         WHERE name = 'Preboarding Skills Record');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Skills Record', 'Preboarding Skills Record', 'POST', 'preboarding-skill-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1, @child_skill_dynamic_form_id);
SET @child_skill_dynamic_form_version_id := (SELECT `id`
                                 FROM ohrm_dynamic_form_version
                                 WHERE name = 'Preboarding Skills Record');

SET @child_skill_meta =  CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
      {
          "uid": "skill_012",
          "name": "skill",
          "label": "Skill",
          "widget": "oxd-master-data-input",
          "attr": {
            "service": "Skill",
            "required": true
          },
          "validations": [
            "#required",
            "#masterDataSelect:Skill"
          ]
      },
    {
      "uid": "years_of_experience_012",
      "name": "years_of_experience",
      "widget": "textbox",
      "label": "Years of Experience",
      "attr": {
        "rows": "1",
        "style": "min-height: 45px"
      },
      "validations": [
        "#decimal:1",
        "#min:0",
        "#max:99.9"
      ]
    },
    {
      "uid": "comment_012",
      "name": "comment",
      "label": "Comments",
      "widget": "textbox",
      "validations": [
        "#length:0,100"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form012",
      "action": "POST",
      "endpoint": "forms/012",
      "body": [
        {
          "uid": "form012_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 2,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form012_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "skill_012"
                    }
                  ]
                }
              },
              {
                "uid": "form012_grid_item_2",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "years_of_experience_012"
                    }
                  ]
                }
              },
              {
                "uid": "form012_grid_item_3",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "comment_012"
                    }
                  ]
                }
              }
            ]
          }
        }
      ],
      "model": {
        "skill": "",
        "years_of_experience": "",
        "comment": ""
      },
      "computed": [],
      "methods": {}
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @child_skill_meta WHERE id = @child_skill_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @child_skill_meta WHERE id = @child_skill_dynamic_form_version_id;

INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Skills', 'Preboarding Skills', 'POST',
        'preboarding-skills', null, @data_group_id, @system_user_id, @system_user_id, 'System', 1);

SET @skill_dynamic_form_id := (SELECT `id` FROM ohrm_dynamic_form WHERE name = 'Preboarding Skills');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Skills', 'Preboarding Skills', 'POST', 'preboarding-skills',
        null, @data_group_id, @system_user_id, @system_user_id, 'System', 1, @skill_dynamic_form_id);

SET @skill_dynamic_form_version_id := (SELECT `id` FROM ohrm_dynamic_form_version WHERE name = 'Preboarding Skills');

SET @skill_metadata = CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
    {
      "uid": "skill_0012",
      "name": "skill",
      "label": "skill",
      "widget": "oxd-subform-widget",
      "attr": {
        "min": 1,
        "max": 3,
        "endpoint": "preboarding-skill-record"
      },
      "validations": [
        "#childForm:',@child_skill_dynamic_form_version_id,',1,3"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form0012",
      "action": "POST",
      "endpoint": "forms/012",
      "body": [
        {
          "uid": "form0012_header",
          "tag": "div",
          "props": {
            "style": "display: flex;"
          },
          "slots": {
            "default": [
              {
                "uid": "form0012_title",
                "tag": "oxd-text",
                "props": {
                  "type": "card-title"
                },
                "slots": {
                  "default": [
                    "Skill"
                  ]
                }
              },
              {
                "uid": "form0012_status",
                "tag": "oxd-status-chip",
                "props": {
                  "style": "margin-left: 10px;",
                  "status": "##advancedTask.status##"
                }
              }
            ]
          }
        },
        {
          "uid": "form0012_br",
          "tag": "br"
        },
        {
          "uid": "form0012_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 1,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form0012_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "skill_0012"
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "uid": "form0012_divider",
          "tag": "oxd-divider",
          "props": {
            "style": "margin-bottom: 1rem;"
          }
        },
        {
          "uid": "form0012_buttons",
          "tag": "div",
          "props": {
            "class": "orangehrm-form-actions"
          },
          "slots": {
            "default": [
              {
                "uid": "form0012_required_text",
                "tag": "oxd-required-text"
              },
              {
                "uid": "form0012_button_save",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Save",
                  "display-type": "secondary",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSaveButton"
                }
              },
              {
                "uid": "form0012_button_submit",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Submit",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSubmitButton"
                }
              },
              {
                "uid": "form0012_button_reject",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Reject",
                  "display-type": "label-feedback-reject",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickRejectButton"
                }
              },
              {
                "uid": "form0012_button_approve",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Approve",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickApproveButton"
                }
              }
            ]
          }
        }
      ],
      "model": {
        "skill": [
          {
            "skill": "",
            "years_of_experience": "",
            "comment": ""
          }
        ]
      },
      "computed": {},
      "methods": {
        "onClickSubmitButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Submit Skill Details",
            "message": "Please ensure the details provided are accurate.",
            "messageAlt": "The details cannot be edited after submission.",
            "confirmText": "Yes, Submit",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Submit"
          },
          "#toast": {
            "error": "Failed to Submit",
            "success": "Successfully Submitted"
          }
        },
        "onClickSaveButton": {
          "#validate": {},
          "#save": {
            "action": "Save"
          },
          "#toast": {
            "error": "Failed to Save",
            "success": "Successfully Saved"
          }
        },
        "onClickApproveButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Approve Skill Details",
            "message": "By approving, you confirm that all skill details are accurate and satisfactory.",
            "confirmText": "Yes, Approve",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Approve",
            "skipFormData": true
          },
          "#toast": {
            "error": "Skill Details Approval Failed",
            "success": "Skill Details Has Been Approved"
          }
        },
        "onClickRejectButton": {
          "#validate": {},
          "#prompt": {
            "title": "Reject Skill Details",
            "message": "Rejecting the skill details will prompt the new hire to resubmit the necessary details. The reason for rejection will be sent to the new hire.",
            "confirmDisplayType": "label-feedback-reject",
            "confirmText": "Yes, Reject",
            "cancelText": "No, Cancel",
            "inputType": "textarea",
            "inputLabel": "Comment"
          },
          "#save": {
            "action": "Reject",
            "skipFormData": true
          },
          "#toast": {
            "error": "Skill Details Rejection Failed",
            "success": "Skill Details Has Been Rejected"
          }
        }
      }
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @skill_metadata WHERE id = @skill_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @skill_metadata WHERE id = @skill_dynamic_form_version_id;

-- Language

INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Language Record', 'Preboarding Language Record', 'POST', 'preboarding-language-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1);
SET @child_language_dynamic_form_id := (SELECT `id`
                         FROM ohrm_dynamic_form
                         WHERE name = 'Preboarding Language Record');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Language Record', 'Preboarding Language Record', 'POST', 'preboarding-language-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1, @child_language_dynamic_form_id);
SET @child_language_dynamic_form_version_id := (SELECT `id`
                                 FROM ohrm_dynamic_form_version
                                 WHERE name = 'Preboarding Language Record');

SET @child_language_meta =  CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
      {
          "uid": "language_013",
          "name": "language",
          "label": "Language",
          "widget": "oxd-master-data-input",
          "attr": {
            "service": "Language",
            "required": true
          },
          "validations": [
            "#required",
            "#masterDataSelect:Language"
          ]
      },
    {
      "uid": "skill_013",
      "name": "skill",
      "widget": "dropdown",
      "label": "Skill",
      "attr": {
        "required": true,
        "choices": {
          "1": "Writing",
          "2": "Speaking",
          "3": "Reading"
        }
      },
      "validations": [
        "#required",
        "#select:[1,2,3]"
      ]
    },
    {
      "uid": "fluency_level_013",
      "name": "fluency_level",
      "widget": "dropdown",
      "label": "Fluency Level",
      "attr": {
        "required": true,
        "choices": {
          "1": "Poor",
          "2": "Basic",
          "3": "Good",
          "4": "Mother Tongue"
        }
      },
      "validations": [
        "#required",
        "#select:[1,2,3,4]"
      ]
    },
    {
      "uid": "comment_013",
      "name": "comment",
      "label": "Comments",
      "widget": "textbox",
      "validations": [
        "#length:0,100"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form013",
      "action": "POST",
      "endpoint": "forms/013",
      "body": [
        {
          "uid": "form013_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 2,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form013_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "language_013"
                    }
                  ]
                }
              },
              {
                "uid": "form013_grid_item_2",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "skill_013"
                    }
                  ]
                }
              },
              {
                "uid": "form013_grid_item_3",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "fluency_level_013"
                    }
                  ]
                }
              },
              {
                "uid": "form013_grid_item_4",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "comment_013"
                    }
                  ]
                }
              }
            ]
          }
        }
      ],
      "model": {
        "language": "",
        "skill": "",
        "fluency_level": "",
        "comment": ""
      },
      "computed": [],
      "methods": {}
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @child_language_meta WHERE id = @child_language_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @child_language_meta WHERE id = @child_language_dynamic_form_version_id;


INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding Language', 'Preboarding Language', 'POST',
        'preboarding-languages', null, @data_group_id, @system_user_id, @system_user_id, 'System', 1);

SET @language_dynamic_form_id := (SELECT `id` FROM ohrm_dynamic_form WHERE name = 'Preboarding Language');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding Language', 'Preboarding Language', 'POST', 'preboarding-languages',
        null, @data_group_id, @system_user_id, @system_user_id, 'System', 1, @language_dynamic_form_id);

SET @language_dynamic_form_version_id := (SELECT `id` FROM ohrm_dynamic_form_version WHERE name = 'Preboarding Language');

SET @language_metadata = CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
    {
      "uid": "language_0013",
      "name": "language",
      "label": "Language",
      "widget": "oxd-subform-widget",
      "attr": {
        "min": 1,
        "max": 3,
        "endpoint": "preboarding-language-record"
      },
      "validations": [
        "#childForm:',@child_language_dynamic_form_version_id,',1,3"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form013",
      "action": "POST",
      "endpoint": "forms/13",
      "body": [
        {
          "uid": "form013_header",
          "tag": "div",
          "props": {
            "style": "display: flex;"
          },
          "slots": {
            "default": [
              {
                "uid": "form013_title",
                "tag": "oxd-text",
                "props": {
                  "type": "card-title"
                },
                "slots": {
                  "default": [
                    "Language"
                  ]
                }
              },
              {
                "uid": "form013_status",
                "tag": "oxd-status-chip",
                "props": {
                  "style": "margin-left: 10px;",
                  "status": "##advancedTask.status##"
                }
              }
            ]
          }
        },
        {
          "uid": "form013_br",
          "tag": "br"
        },
        {
          "uid": "form013_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 1,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form013_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "language_0013"
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "uid": "form013_divider",
          "tag": "oxd-divider",
          "props": {
            "style": "margin-bottom: 1rem;"
          }
        },
        {
          "uid": "form013_buttons",
          "tag": "div",
          "props": {
            "class": "orangehrm-form-actions"
          },
          "slots": {
            "default": [
              {
                "uid": "form013_required_text",
                "tag": "oxd-required-text"
              },
              {
                "uid": "form013_button_save",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Save",
                  "display-type": "secondary",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSaveButton"
                }
              },
              {
                "uid": "form013_button_submit",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Submit",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSubmitButton"
                }
              },
              {
                "uid": "form013_button_reject",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Reject",
                  "display-type": "label-feedback-reject",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickRejectButton"
                }
              },
              {
                "uid": "form013_button_approve",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Approve",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickApproveButton"
                }
              }
            ]
          }
        }
      ],
      "model": {
        "language": [
          {
            "language": "",
            "skill": "",
            "fluency_level": "",
            "comment": ""
          }
        ]
      },
      "computed": {},
      "methods": {
        "onClickSubmitButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Submit Language Details",
            "message": "Please ensure the details provided are accurate.",
            "messageAlt": "The details cannot be edited after submission.",
            "confirmText": "Yes, Submit",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Submit"
          },
          "#toast": {
            "error": "Failed to Submit",
            "success": "Successfully Submitted"
          }
        },
        "onClickSaveButton": {
          "#validate": {},
          "#save": {
            "action": "Save"
          },
          "#toast": {
            "error": "Failed to Save",
            "success": "Successfully Saved"
          }
        },
        "onClickApproveButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Approve Language Details",
            "message": "By approving, you confirm that all language details are accurate and satisfactory.",
            "confirmText": "Yes, Approve",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Approve",
            "skipFormData": true
          },
          "#toast": {
            "error": "Language Details Approval Failed",
            "success": "Language Details Has Been Approved"
          }
        },
        "onClickRejectButton": {
          "#validate": {},
          "#prompt": {
            "title": "Reject Language Details",
            "message": "Rejecting the language details will prompt the new hire to resubmit the necessary details. The reason for rejection will be sent to the new hire.",
            "confirmDisplayType": "label-feedback-reject",
            "confirmText": "Yes, Reject",
            "cancelText": "No, Cancel",
            "inputType": "textarea",
            "inputLabel": "Comment"
          },
          "#save": {
            "action": "Reject",
            "skipFormData": true
          },
          "#toast": {
            "error": "Language Details Rejection Failed",
            "success": "Language Details Has Been Rejected"
          }
        }
      }
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @language_metadata WHERE id = @language_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @language_metadata WHERE id = @language_dynamic_form_version_id;

-- License

INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding License Record', 'Preboarding License Record', 'POST', 'preboarding-license-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1);
SET @child_license_dynamic_form_id := (SELECT `id`
                         FROM ohrm_dynamic_form
                         WHERE name = 'Preboarding License Record');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding License Record', 'Preboarding License Record', 'POST', 'preboarding-license-record', null, @data_group_id,
        @system_user_id, @system_user_id, 'System', 1, @child_license_dynamic_form_id);
SET @child_license_dynamic_form_version_id := (SELECT `id`
                                 FROM ohrm_dynamic_form_version
                                 WHERE name = 'Preboarding License Record');

SET @child_license_meta =  CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
      {
          "uid": "license_type_014",
          "name": "license_type",
          "label": "License Type",
          "widget": "oxd-master-data-input",
          "attr": {
            "service": "License",
            "required": true
          },
          "validations": [
            "#required",
            "#masterDataSelect:License"
          ]
      },
    {
      "uid": "license_number_014",
      "name": "license_number",
      "widget": "textbox",
      "label": "License Number",
      "attr": {
        "rows": "1",
        "style": "min-height: 45px"
      },
      "validations": [
        "#length:0,50"
      ]
    },
    {
      "uid": "issued_date_014",
      "name": "issued_date",
      "widget": "datepicker",
      "label": "Issued Date",
      "validations": [
        "#date_format:yyyy-mm-dd",
        "#date",
        "#equal_or_before_date:$expiry_date,Issued date should be before expiry date"
      ]
    },
    {
      "uid": "expiry_date_014",
      "name": "expiry_date",
      "widget": "datepicker",
      "label": "Expiry Date",
      "validations": [
        "#date_format:yyyy-mm-dd",
        "#date",
        "#equal_or_after_date:$issued_date,Expiry date should be after issued date"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form014",
      "action": "POST",
      "endpoint": "forms/014",
      "body": [
        {
          "uid": "form014_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 2,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form014_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "license_type_014"
                    }
                  ]
                }
              },{
                "uid": "form014_grid_item_2",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "license_number_014"
                    }
                  ]
                }
              },
              {
                "uid": "form014_grid_item_3",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "issued_date_014"
                    }
                  ]
                }
              },
              {
                "uid": "form014_grid_item_4",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "expiry_date_014"
                    }
                  ]
                }
              }
            ]
          }
        }
      ],
      "model": {
        "license_type": "",
        "license_number": "",
        "issued_date": "",
        "expiry_date": ""
      },
      "computed": [],
      "methods": {}
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @child_license_meta WHERE id = @child_license_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @child_license_meta WHERE id = @child_license_dynamic_form_version_id;

INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Preboarding License', 'Preboarding License', 'POST',
        'preboarding-license', null, @data_group_id, @system_user_id, @system_user_id, 'System', 1);

SET @license_dynamic_form_id := (SELECT `id` FROM ohrm_dynamic_form WHERE name = 'Preboarding License');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Preboarding License', 'Preboarding License', 'POST', 'preboarding-license',
        null, @data_group_id, @system_user_id, @system_user_id, 'System', 1, @license_dynamic_form_id);

SET @license_dynamic_form_version_id := (SELECT `id` FROM ohrm_dynamic_form_version WHERE name = 'Preboarding License');

SET @license_metadata = CONCAT('{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
    {
      "uid": "license_0014",
      "name": "license",
      "label": "License",
      "widget": "oxd-subform-widget",
      "attr": {
        "min": 1,
        "max": 3,
        "endpoint": "preboarding-license-record"
      },
      "validations": [
        "#childForm:',@child_license_dynamic_form_version_id,',1,3"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form014",
      "action": "POST",
      "endpoint": "forms/14",
      "body": [
        {
          "uid": "form014_header",
          "tag": "div",
          "props": {
            "style": "display: flex;"
          },
          "slots": {
            "default": [
              {
                "uid": "form014_title",
                "tag": "oxd-text",
                "props": {
                  "type": "card-title"
                },
                "slots": {
                  "default": [
                    "License"
                  ]
                }
              },
              {
                "uid": "form014_status",
                "tag": "oxd-status-chip",
                "props": {
                  "style": "margin-left: 10px;",
                  "status": "##advancedTask.status##"
                }
              }
            ]
          }
        },
        {
          "uid": "form014_br",
          "tag": "br"
        },
        {
          "uid": "form014_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 1,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form0011_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "license_0014"
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "uid": "form014_divider",
          "tag": "oxd-divider",
          "props": {
            "style": "margin-bottom: 1rem;"
          }
        },
        {
          "uid": "form014_buttons",
          "tag": "div",
          "props": {
            "class": "orangehrm-form-actions"
          },
          "slots": {
            "default": [
              {
                "uid": "form014_required_text",
                "tag": "oxd-required-text"
              },
              {
                "uid": "form014_button_save",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Save",
                  "display-type": "secondary",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSaveButton"
                }
              },
              {
                "uid": "form014_button_submit",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Submit",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickSubmitButton"
                }
              },
              {
                "uid": "form014_button_reject",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Reject",
                  "display-type": "label-feedback-reject",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickRejectButton"
                }
              },
              {
                "uid": "form014_button_approve",
                "tag": "oxd-button",
                "props": {
                  "type": "button",
                  "label": "Approve",
                  "style": "margin-left: 0.5rem;"
                },
                "events": {
                  "onClick": "#onClickApproveButton"
                }
              }
            ]
          }
        }
      ],
      "model": {
        "license": [
          {
            "license_type": "",
            "license_number": "",
            "issued_date": "",
            "expiry_date": ""
          }
        ]
      },
      "computed": {},
      "methods": {
        "onClickSubmitButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Submit License Details",
            "message": "Please ensure the details provided are accurate.",
            "messageAlt": "The details cannot be edited after submission.",
            "confirmText": "Yes, Submit",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Submit"
          },
          "#toast": {
            "error": "Failed to Submit",
            "success": "Successfully Submitted"
          }
        },
        "onClickSaveButton": {
          "#validate": {},
          "#save": {
            "action": "Save"
          },
          "#toast": {
            "error": "Failed to Save",
            "success": "Successfully Saved"
          }
        },
        "onClickApproveButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Approve License Details",
            "message": "By approving, you confirm that all license details are accurate and satisfactory.",
            "confirmText": "Yes, Approve",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Approve",
            "skipFormData": true
          },
          "#toast": {
            "error": "License Details Approval Failed",
            "success": "License Details Has Been Approved"
          }
        },
        "onClickRejectButton": {
          "#validate": {},
          "#prompt": {
            "title": "Reject License Details",
            "message": "Rejecting the license details will prompt the new hire to resubmit the necessary details. The reason for rejection will be sent to the new hire.",
            "confirmDisplayType": "label-feedback-reject",
            "confirmText": "Yes, Reject",
            "cancelText": "No, Cancel",
            "inputType": "textarea",
            "inputLabel": "Comment"
          },
          "#save": {
            "action": "Reject",
            "skipFormData": true
          },
          "#toast": {
            "error": "License Details Rejection Failed",
            "success": "License Details Has Been Rejected"
          }
        }
      }
    }
  }
}');

UPDATE ohrm_dynamic_form SET meta_data = @license_metadata WHERE id = @license_dynamic_form_id;
UPDATE ohrm_dynamic_form_version SET meta_data = @license_metadata WHERE id = @license_dynamic_form_version_id;
