INSERT INTO ohrm_data_group (name, description, can_read, can_create, can_update, can_delete)
VALUES ('preboarding_self_introduction', 'Preboarding - Stage 02: Self Introduction', 1, 0, 1, 0);

SET @data_group_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'preboarding_self_introduction');
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 @ess_id := (SELECT id FROM ohrm_user_role where name = 'ESS');
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 @preboarding_new_hire_user_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'PreboardingNewHire');
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 @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, 0, 1, 0, 0, NULL),
    (@pre_boarding_event_manager_user_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL),
    (@ess_id, @data_group_id, 1, 0, 1, 0, 1, NULL),
    (@preboarding_new_hire_user_role_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');


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

SET @dynamic_form_id := (SELECT `id` FROM ohrm_dynamic_form WHERE name = 'Preboarding Self Introduction');

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 Self Introduction', 'Preboarding Self Introduction', 'POST', 'preboarding-self-introduction',
        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 = 'Preboarding Self Introduction');

SET @metadata = '{
  "version": {
    "schema-version": "1.0.0"
  },
  "fields": [
    {
      "uid": "favourite_movies_002",
      "name": "favourite_movies",
      "widget": "textbox",
      "label": "Your favorite movies of all time",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "playing_now_002",
      "name": "playing_now",
      "widget": "textbox",
      "label": "Playing in your car/home right now",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "wish_002",
      "name": "wish",
      "widget": "textbox",
      "label": "If you had one wish, it would be",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "favourite_meal_002",
      "name": "favourite_meal",
      "widget": "textbox",
      "label": "If you were stuck on a deserted island and could only have one meal, it would be",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "cannot_live_without_002",
      "name": "cannot_live_without",
      "widget": "textbox",
      "label": "You absolutely CANNOT live without",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "next_year_plan_002",
      "name": "next_year_plan",
      "widget": "textbox",
      "label": "In the next year, you are most looking forward to",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "greatest_advice_002",
      "name": "greatest_advice",
      "widget": "textbox",
      "label": "The greatest advice anyone has ever given you",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "one_thing_to_know_002",
      "name": "one_thing_to_know",
      "widget": "textbox",
      "label": "Lastly, one thing others should definitely know about yourself is",
      "attr": {
      	"rows": 1,
      	"style": "min-height: 45px;"
      },
      "validations": [
        "#required",
        "#length:0,250"
      ]
    },
    {
      "uid": "self_introduction_video_002",
      "name": "self_introduction_video",
      "widget": "oxd-url-input",
      "label": "Link to self introduction video",
      "attr":{
        "tooltip": "Upload a short intro video (e.g. Google Drive) and paste the link here",
        "tooltip-position": "top-right"
      },
      "validations": [
        "#required",
        "#url",
        "#length:0,250"
      ]
    }
  ],
  "views": {
    "form": {
      "uid": "form002",
      "action": "POST",
      "endpoint": "forms/2",
      "body": [
        {
          "uid": "form002_header",
          "tag": "div",
          "props": {
            "style":"display: flex;"
          },
          "slots": {
            "default": [
              {
                "uid": "form002_title",
                "tag": "oxd-text",
                "props": {
                  "type": "card-title"
                },
                "slots": {
                  "default": [
                    "Self Introduction"
                  ]
                }
              },
              {
                "uid":"form002_status",
                "tag":"oxd-status-chip",
                "props":{
                   "style":"margin-left: 10px;",
                   "status":"##advancedTask.status##"
                }
              }
            ]
          }
        },
        {
          "uid": "form002_br",
          "tag": "br"
        },
        {
          "uid": "form002_grid",
          "tag": "oxd-grid",
          "props": {
            "cols": 2,
            "style": "margin-left: -10px;margin-right: -10px;"
          },
          "slots": {
            "default": [
              {
                "uid": "form002_grid_item_1",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "favourite_movies_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_2",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "playing_now_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_3",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "wish_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_4",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "favourite_meal_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_5",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "cannot_live_without_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_6",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "next_year_plan_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_7",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "greatest_advice_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_8",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "one_thing_to_know_002"
                    }
                  ]
                }
              },
              {
                "uid": "form002_grid_item_9",
                "tag": "oxd-grid-item",
                "slots": {
                  "default": [
                    {
                      "field": "self_introduction_video_002"
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "uid": "form007_divider",
          "tag": "oxd-divider",
          "props": {
            "style": "margin-bottom: 1rem;"
          }
        },
        {
          "uid": "form002_buttons",
          "tag": "div",
          "props": {
            "class": "orangehrm-form-actions"
          },
          "slots": {
              "default": [
                {
                  "uid": "form001_required_text",
                  "tag": "oxd-required-text"
                },
                {
                  "uid": "form002_button_submit",
                  "tag": "oxd-button",
                  "props": {
                    "type": "button",
                    "label": "Submit",
                    "style": "margin-left: 0.5rem; float: right;"
                  },
                  "events": {
                    "onClick": "#onClickSubmitButton"
                  }
                },
                {
                  "uid": "form002_button_save",
                  "tag": "oxd-button",
                  "props": {
                    "type": "button",
                    "label": "Proceed",
                    "style": "margin-left: 0.5rem; float: right;"
                  },
                  "events": {
                    "onClick": "#onClickSaveButton"
                  }
                }
              ]
            }
        }
      ],
      "model": {
        "favourite_movies": "",
        "playing_now": "",
        "wish": "",
        "favourite_meal": "",
        "cannot_live_without": "",
        "next_year_plan": "",
        "greatest_advice": "",
        "one_thing_to_know": "",
        "self_introduction_video": ""
      },
      "computed": {},
      "methods": {
        "onClickSubmitButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Submit Self Introduction",
            "message": "You are about to submit Self Introduction. Do you wish to proceed?",
            "messageAlt": "Please review the details carefully before submitting, as they cannot be modified afterward.",
            "confirmText": "Yes, Submit",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Submit"
          },
          "#toast": {
            "error": "Failed to Submit",
            "success": "Successfully Submitted"
          }
        },
        "onClickSaveButton": {
          "#validate": {},
          "#confirmation": {
            "title": "Confirm New Hire''s Introduction Details",
            "message": "You are about to confirm the Self-Introduction details of the new hire. Are you sure you want to continue?",
            "messageAlt": "Please review the details carefully before proceeding, as they cannot be modified afterward.",
            "confirmText": "Yes, Proceed",
            "confirmDisplayType": "label-feedback-success"
          },
          "#save": {
            "action": "Save"
          },
          "#toast": {
            "error": "Failed to Update",
            "success": "Successfully Updated"
          }
        }
      }
    }
  }
}';

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;
