DROP TABLE IF EXISTS `ohrm_audittrail_on_off_boarding_task_type_trail`;
CREATE TABLE `ohrm_audittrail_on_off_boarding_task_type_trail` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `action_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `action_owner_id` VARCHAR(6),
    `action_owner_name` TEXT,
    `version_id` BIGINT,
    `affected_entity_id` VARCHAR(20),
    `affected_entity_name` TEXT,
    `action` VARCHAR(255),
    `action_description` LONGTEXT,
    PRIMARY KEY(`id`)
) ENGINE = INNODB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `ohrm_audittrail_on_off_boarding_event_trail`;
CREATE TABLE `ohrm_audittrail_on_off_boarding_event_trail` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `action_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `action_owner_id` VARCHAR(6),
    `action_owner_name` TEXT,
    `version_id` BIGINT,
    `affected_entity_id` VARCHAR(20),
    `affected_entity_name` TEXT,
    `action` VARCHAR(255),
    `action_description` TEXT,
    PRIMARY KEY(`id`)
) ENGINE = INNODB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `ohrm_audittrail_on_off_boarding_task_trail`;
CREATE TABLE `ohrm_audittrail_on_off_boarding_task_trail` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `action_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `action_owner_id` VARCHAR(6),
    `action_owner_name` TEXT,
    `version_id` BIGINT,
    `affected_entity_id` VARCHAR(20),
    `affected_entity_name` TEXT,
    `action` VARCHAR(255),
    `action_description` LONGTEXT,
    PRIMARY KEY(`id`)
) ENGINE = INNODB DEFAULT CHARSET=utf8;

INSERT INTO `ohrm_audittrail_module` (`name`) VALUES('On/Offboarding');
SET @onboarding_module_id := (SELECT `id` FROM `ohrm_audittrail_module` WHERE `name`='On/Offboarding');

INSERT INTO `ohrm_audittrail_section` (`name`, `description`, `affected_entity`, `module_id`) VALUES
('OnOffBoardingTaskType', 'Configure Task', 'Task', @onboarding_module_id),
('OnOffBoardingEvent', 'Event/Template', 'Event', @onboarding_module_id),
('OnOffBoardingTask', 'Employee Task', 'Employee', @onboarding_module_id);

SET @task_type_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='OnOffBoardingTaskType');
INSERT INTO `ohrm_audittrail_section_actions` (`section_id` ,`action` ,`description`) VALUES
(@task_type_section_id, 'ADD TASK TYPE', 'Add Task Type'),
(@task_type_section_id, 'DELETE TASK TYPE', 'Delete Task Type'),
(@task_type_section_id, 'UPDATE TASK TYPE', 'Update Task Type');

SET @event_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='OnOffBoardingEvent');
INSERT INTO `ohrm_audittrail_section_actions` (`section_id` ,`action` ,`description`) VALUES
(@event_section_id, 'ADD EVENT', 'Add Event'),
(@event_section_id, 'DELETE EVENT', 'Delete Event'),
(@event_section_id, 'UPDATE EVENT', 'Update Event');

SET @task_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='OnOffBoardingTask');
INSERT INTO `ohrm_audittrail_section_actions` (`section_id` ,`action` ,`description`) VALUES
(@task_section_id, 'ADD EMPLOYEE TASK', 'Add Employee Task'),
(@task_section_id, 'DELETE EMPLOYEE TASK', 'Delete Employee Task'),
(@task_section_id, 'UPDATE EMPLOYEE TASK', 'Update Employee Task');


INSERT INTO `ohrm_event_listener` (`event`, `listener_class`, `enabled`, `position`) VALUES
('onboarding.task_type_add', 'OnBoardingTaskTypeAddListener', 1, 1),
('onboarding.task_type_update', 'OnBoardingTaskTypeUpdateListener', 1, 2),
('onboarding.task_type_delete', 'OnBoardingTaskTypeDeleteListener', 1, 3),
('onboarding.event_add', 'OnBoardingEventAddListener', 1, 4),
('onboarding.event_update', 'OnBoardingEventUpdateListener', 1, 5),
('onboarding.event_delete', 'OnBoardingEventDeleteListener', 1, 6),
('onboarding.task_add', 'OnBoardingTaskAddListener', 1, 7),
('onboarding.task_update', 'OnBoardingTaskUpdateListener', 1, 8),
('onboarding.task_delete', 'OnBoardingTaskDeleteListener', 1, 9);