INSERT INTO ohrm_data_group (name, description, can_read, can_create, can_update, can_delete)
VALUES ('recruitment_preboarding_disclosure_and_barring_service_details', 'Recruitment (ATS) - Onboarding - Disclosure and Barring Service Details', 1, 0, 1, 0);

SET @data_group_id := (SELECT `id`
                       FROM `ohrm_data_group`
                       WHERE `name` = 'recruitment_preboarding_disclosure_and_barring_service_details');
SET @candidate_role_id := (SELECT `id`
                            FROM `ohrm_user_role`
                            WHERE `name` = 'CandidateUser');
SET @admin_user_role_id := (SELECT `id`
                            FROM `ohrm_user_role`
                            WHERE `name` = 'Admin');
SET @hiring_manager_user_role_id := (SELECT `id`
                                     FROM `ohrm_user_role`
                                     WHERE `name` = 'HiringManager');
SET @preboarding_event_manager_user_role_id := (SELECT `id`
                                     FROM `ohrm_user_role`
                                     WHERE `name` = 'PreboardingEventManager');


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),
(@hiring_manager_user_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL),
(@candidate_user_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL),
(@hiring_manager_user_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL),
(@preboarding_event_manager_user_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL);

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


INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Disclosure and Barring Service Details', 'Disclosure and Barring Service Details', 'POST',
        'preboarding-dbs', null, @data_group_id, @system_user_id, @system_user_id, 'System', 1);

SET @dynamic_form_id := (SELECT `id`
                         FROM ohrm_dynamic_form
                         WHERE name = 'Disclosure and Barring Service Details');

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 ('Disclosure and Barring Service Details', 'Disclosure and Barring Service Details', 'POST', 'preboarding-dbs',
        null, @data_group_id, @system_user_id, @system_user_id, 'System', 1, @dynamic_form_id);

SET @dynamic_form_version_id := (SELECT `id`
                                 FROM ohrm_dynamic_form_version
                                 WHERE name = 'Disclosure and Barring Service Details');

SET @metadata = '{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [],
  "views": {
    "form": {
      "uid": "form007",
      "action": "POST",
      "endpoint": "forms/7",
      "body": [
        {
          "uid": "form007_title",
          "tag": "oxd-text",
          "props": {
            "type": "card-title",
            "style": "margin-bottom: 30px;"
          },
          "slots": {
            "default": [
              "Disclosure and Barring Service Details"
            ]
          }
        },
        {
          "uid": "form007_text001",
          "tag": "oxd-text",
          "props": {
            "type": "p",
            "style": "margin-bottom: 10px;"
          },
          "slots": {
            "default": [
              "To request a basic DBS check, please follow these steps:"
            ]
          }
        },
        {
          "uid": "form007_text002",
          "tag": "oxd-text",
          "props": {
            "type": "p",
            "style": "margin-bottom: 10px;"
          },
          "slots": {
            "default": [
              "1. Visit the ",
                {
                  "uid": "form007_text002",
                  "tag": "a",
                  "props": {
                    "style": "font-weight: 700;",
                    "href": "https://www.w3schools.com",
                    "target": "_blank"
                  },
                  "slots": {
                    "default": [
                        "[DBS website]"
                    ]
                  }
                },
                " to initiate the basic DBS check process."
            ]
          }
        },
        {
          "uid": "form007_text003",
          "tag": "oxd-text",
          "props": {
            "type": "p",
            "style": "margin-bottom: 10px;"
          },
          "slots": {
            "default": [
              "2. If you are enrolled in the DBS update service, you do not need to follow step 1. Instead, please ensure a copy of your certificate is provided to the Home."
            ]
          }
        },
        {
          "uid": "form007_text003",
          "tag": "oxd-text",
          "props": {
            "type": "p",
            "style": "margin-bottom: 10px;"
          },
          "slots": {
            "default": [
                "Once the DBS details are received, the recruitment team at Colten Care will review and process them promptly."
            ]
          }
        },
        {
          "uid": "form007_br",
          "tag": "br"
        },
        {
          "uid": "form007_divider",
          "tag": "oxd-divider",
          "props": {
            "style": "margin-bottom: 1rem;"
          }
        },
        {
          "uid": "form007_buttons",
          "tag": "div",
          "props": {
            "style": "display: flex; justify-content: space-between; margin-top: 1rem; float: right;"
          },
          "slots": {
              "default": [
                {
                  "uid": "form007_button_submit",
                  "tag": "oxd-button",
                  "props": {
                    "type": "button",
                    "label": "Proceed",
                    "style": "margin-left: 0.5rem;"
                  },
                  "events": {
                    "onClick": "#onClickSubmitButton"
                  }
                },
                {
                  "uid": "form007_button_reject",
                  "tag": "oxd-button",
                  "props": {
                    "type": "button",
                    "label": "Reject",
                    "display-type": "danger",
                    "style": "margin-left: 0.5rem;"
                  },
                  "events": {
                    "onClick": "#onClickRejectButton"
                  }
                },
                {
                  "uid": "form007_button_approve",
                  "tag": "oxd-button",
                  "props": {
                    "type": "button",
                    "label": "Approve",
                    "style": "margin-left: 0.5rem;"
                  },
                  "events": {
                    "onClick": "#onClickApproveButton"
                  }
                }
              ]
            }
        }
      ],
      "model": {},
      "computed": {},
      "methods": {
        "onClickSubmitButton": {
          "#confirmation": {
            "message": "Disclosure and Barring Service Details will be Submitted.",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Submit"
          },
          "#toast": {
            "error": "Failed to Submit",
            "success": "Successfully Submitted"
          }
        },
        "onClickApproveButton": {
          "#confirmation": {
            "message": "Disclosure and Barring Service Details will be Approved.",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Approve"
          },
          "#toast": {
            "error": "Failed to Approve",
            "success": "Disclosure and Barring Service Details has been Approved"
          }
        },
        "onClickRejectButton": {
          "#prompt": {
            "title": "Rejection Confirmation",
            "confirmDisplayType": "label-feedback-danger",
            "confirmText": "Reject",
            "inputType": "textarea",
            "inputLabel": "Comment"
          },
          "#save": {
            "action": "Reject"
          },
          "#toast": {
            "error": "Failed to Reject",
            "success": "Disclosure and Barring Service Details has been Rejected"
          }
        }
      }
    }
  }
}';

UPDATE ohrm_dynamic_form
SET meta_data = @metadata
WHERE id = @dynamic_form_id;

UPDATE ohrm_dynamic_form_version
SET meta_data = @metadata
WHERE id = @dynamic_form_version_id;
