/*
 * OrangeHRM Enterprise is a closed sourced comprehensive Human Resource Management (HRM)
 * System that captures all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM Inc is the owner of the patent, copyright, trade secrets, trademarks and any
 * other intellectual property rights which subsist in the Licensed Materials. OrangeHRM Inc
 * is the owner of the media / downloaded OrangeHRM Enterprise software files on which the
 * Licensed Materials are received. Title to the Licensed Materials and media shall remain
 * vested in OrangeHRM Inc. For the avoidance of doubt title and all intellectual property
 * rights to any design, new software, new protocol, new interface, enhancement, update,
 * derivative works, revised screen text or any other items that OrangeHRM Inc creates for
 * Customer shall remain vested in OrangeHRM Inc. Any rights not expressly granted herein are
 * reserved to OrangeHRM Inc.
 *
 * Please refer http://www.orangehrm.com/Files/OrangeHRM_Commercial_License.pdf for the license which includes terms and conditions on using this software.
 *
 */

SET @module_id := (SELECT `id`
                               FROM `ohrm_module`
                               WHERE `name` = 'onboardingPro');

SET @copy_preboarding_forms_task_template_id := (SELECT id FROM ohrm_advanced_task_template WHERE name = 'Copy Preboarding Forms to Employee' LIMIT 1);


SET @wizard_screen_id := (SELECT id
                FROM `ohrm_wizard_screen`
                WHERE `title` = 'Personal Details');
SET @personal_wizard_section_id := (SELECT id
                FROM `ohrm_wizard_section`
                WHERE `wizard_screen_id` = @wizard_screen_id AND name = 'PimPersonalDetail');

SET @metadata := CONCAT('{
   "formName":"Preboarding Personal Details",
   "wizardDataTemplate":{
      "sectionId": "@section_id",
      "wizardSectionName": "employee",
      "data":{
         "employee":{
            "emp_marital_status":"${marital_status#id}",
            "emp_gender":"${gender#id}",
            "nation_code":"${nationality#id}",
            "firstName":"${first_name}",
            "middleName":"${middle_name}",
            "lastName":"${last_name}",
            "emp_birthday":"${date_of_birth}",
            "licenseNo":"${driver_license_number}",
            "emp_dri_lice_exp_date":"${license_expiry_date}"
         },
         "customFieldValue":{}
      }
   },
   "config":{
      "emptyValueMap": {
        "emp_marital_status": null,
        "emp_gender": null,
        "nation_code":null,
        "firstName":"",
        "middleName":"",
        "lastName":"",
        "emp_birthday": null,
        "licenseNo":"",
        "emp_dri_lice_exp_date": null
      }
   }
}');
SET @metadata = REPLACE(@metadata, '@section_id', @personal_wizard_section_id);

INSERT INTO `ohrm_advanced_task` (task_template_id, name, description, metadata)
VALUES (@copy_preboarding_forms_task_template_id, 'pre_add_candidate_as_employee',
        'task run at when candidate added as employee to copy preboarding form information to employee', @metadata);
