SET @socail_media_data_group_id := NULL;

INSERT INTO `ohrm_token`(`name`, `display_name`, `class_name`, `entity_name`, `value_getters`, `data_group_id`, `is_date`, `localize`,`parameters`) VALUES
('directory.employeeFacebookContact', 'Employee Facebook Contact','CustomFacebookTokenGenerator', null, null, @socail_media_data_group_id, 0, 0,'visibility=> off,group=>employeeSocailMedia'),
('directory.employeeTwitterContact', 'Employee Twitter Contact','CustomTwitterTokenGenerator', null, null, @socail_media_data_group_id, 0, 0,'visibility=> on,group=>employeeSocailMedia'),
('directory.employeeLinkedinContact', 'Employee LinkedIn Contact','CustomLinkedinTokenGenerator', null, null, @socail_media_data_group_id, 0, 0,'visibility=> on,group=>employeeSocailMedia');


SET @first_token_id := (SELECT LAST_INSERT_ID());
SET @directory_module_id := (SELECT `id` FROM `ohrm_module` WHERE `name`='directory');

INSERT INTO `ohrm_restricted_module_token`(`token_id`, `restricted_module`)
SELECT  `id`, @directory_module_id FROM `ohrm_token` WHERE `id` >= @first_token_id;


-- Directory Config Setting screen

set @module_id := (SELECT id FROM ohrm_module WHERE name = 'admin');

INSERT INTO ohrm_screen (name, module_id, action_url, `route_name`) VALUES
('Update Directory TokenDetails', @module_id , 'updateDirectoryTokenDetails', NULL),
('Directory Configuration', @module_id , 'viewDirectoryConfig', 'admin_viewDirectoryConfig');

set @view_screen_id := (SELECT `id` FROM  `ohrm_screen` WHERE  `action_url` LIKE  'viewDirectoryConfig');
set @update_screen_id := (SELECT `id` FROM  `ohrm_screen` WHERE  `action_url` LIKE  'updateDirectoryTokenDetails');
set @admin_id := (SELECT `id` FROM  `ohrm_user_role` WHERE  `name` LIKE  'Admin');

SET @people_management_pillar_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'People Management' AND parent_id IS NULL AND level = 1);
SET @employee_management_module_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Employee Management' AND parent_id = @people_management_pillar_menu_id AND level = 2);
SET @configurations_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Configurations' AND parent_id = @employee_management_module_menu_id AND level = 3);

INSERT INTO ohrm_menu_item ( menu_title , menu_category, screen_id, parent_id, level, order_hint , url_extras, status ) VALUES
('Directory Configuration', NULL , @view_screen_id, @configurations_menu_id, 4, 600, null, 1);

set @user_role_id := (SELECT LAST_INSERT_ID());

INSERT INTO ohrm_user_role_screen ( `user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
(@admin_id, @view_screen_id, '1', '1', '1', '1'),
(@admin_id, @update_screen_id, '1', '1', '1', '1');


-- Create `hs_hr_emp_directory_email` table

CREATE TABLE `hs_hr_emp_directory_email`(
        `emp_number` int(7) ,
        `status` tinyint(1) DEFAULT FALSE ,
        PRIMARY KEY(emp_number)
)engine=innodb default charset=utf8;

ALTER TABLE hs_hr_emp_directory_email ADD CONSTRAINT fk_hs_hr_emp_directory_email_hs_hr_employee FOREIGN KEY (  `emp_number` ) REFERENCES hs_hr_employee(  `emp_number` ) ON DELETE CASCADE;
-- Table structure for table `hs_hr_emp_relation_catagory`

CREATE TABLE IF NOT EXISTS `hs_hr_emp_relation_catagory` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `display_name` varchar(255) NOT NULL,
  `class_name` varchar(100) NOT NULL,
  `enable` tinyint(1) NOT NULL DEFAULT '1',
  `listing_order` int(2) NOT NULL DEFAULT '10',
  `parameters` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- Dumping data for table `hs_hr_emp_relation_catagory`

INSERT INTO `hs_hr_emp_relation_catagory` (`id`, `display_name`, `class_name`, `enable`, `listing_order`, `parameters`) VALUES
(1, 'Your reporting manager details are as below and  so please ask for them.', 'SupervisorRelation', 0, 1, '{"allow_duplicate":"no","supervisor_chain_enabled": "yes","limit":2,"sortField":"firstName"}'),
(2, 'People in your location', 'LocationBasedRelation', 0, 10, '{"allow_duplicate":"no"}'),
(3, 'We thought it would be helpful if you got to know about some of your fellow team members.', 'RecentlyJoinedRelation', 1, 10, '{"allow_duplicate":"yes","excluded_job_title":["Vice President"]}'),
(4, 'Your Subordinates', 'SubordinateRelation', 0, 10, '{"allow_duplicate":"no","include_sub_chain":"yes","sortField":"firstName"}'),
(5, 'Vice President', 'DefaultRelation', 0, 10, '{"sql":"SELECT e.emp_number FROM hs_hr_employee e WHERE e.job_title_code in (SELECT id FROM ohrm_job_title j where j.job_title=:jobTitle)","sql_para":{":jobTitle":"Vice President"}}');

