INSERT INTO `ohrm_event_listener` ( `event`, `listener_class`, `enabled`, `position`) VALUES ('onboarding.task_due_date_updated', 'OnboardingTaskUpdateEventListener', '1', '1');
INSERT INTO `ohrm_event_listener` ( `event`, `listener_class`, `enabled`, `position`) VALUES ('onboarding.task_deleted', 'OnboardingTaskDeletedEventListener', '1', '2');

-- Due date Changed email

SET @other_notification_type := (SELECT id FROM ohrm_notification_type where `name`='Other');
SET @email_media := (SELECT id FROM ohrm_notification_media WHERE `name` = 'Email');
SET @onboarding_module_id := (SELECT `id` FROM `ohrm_module` WHERE  `name` ='onboarding');
SET @admin_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'Admin');
SET @supervisor_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'Supervisor');
SET @task_owner_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'OhrmTaskOwner');

INSERT INTO `ohrm_notification`
(`name`, `is_enable`,`type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`,`module_id`, `hidden`) VALUES
    ('Onboarding - Task Due date Updated Notification', 1, @other_notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"OnBoardingTaskUpdateEmailProcessor"}', NULL, NULL,@onboarding_module_id, 0);
SET @notification_id := LAST_INSERT_ID();


INSERT INTO `ohrm_notification_subscriber_subscription_template`
(`notification_id`,`media_id`,`locale`,`name`,`subject`,`body`) VALUES
    (@notification_id, @email_media, 'en_US',
     'Task Timeline updated with New Due Date',
     'Task Timeline updated with New Due Date',
     '<p>Hi %recipientFirstName%,<br /><br />Following task’s timeline is updated with new due date.<br />Task Name: %taskName%<br /><br />Task Link: %taskURL%<br /><br />Existing Due Date: %oldDueDate%<br /><br />Updated Due Date: %newDueDate%<br /><br />Thank you.<br /><br />You are getting this email because you are a subscriber.<br />This is an automated notification.</p>');


SET @template_id := LAST_INSERT_ID();

INSERT INTO `ohrm_notification_subscription`
(notification_id,  workflow_item_id, hidden) VALUES
    (@notification_id,  NULL, 0);
SET @last_subscription_id := LAST_INSERT_ID();


INSERT INTO `ohrm_notification_subscriber`(media_id, parameters, type, name) VALUES
    (@email_media, '{"prevent_delete":true}', 'Custom','Task Owner');

SET @subscriber_id := LAST_INSERT_ID();

INSERT INTO `ohrm_notification_subscriber_subscription`(subscription_id, subscriber_id, template_id) SELECT
                                                                                                         s.id, @subscriber_id, @template_id FROM ohrm_notification_subscription s WHERE s.id >= @last_subscription_id;


-- Task remove notification

INSERT INTO `ohrm_notification`
(`name`, `is_enable`,`type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`,`module_id`, `hidden`) VALUES
    ('Onboarding - Task Cancellation Notification', 1, @other_notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"OnBoardingTaskDeleteEmailProcessor"}', NULL, NULL,@onboarding_module_id, 0);
SET @notification_id := LAST_INSERT_ID();


INSERT INTO `ohrm_notification_subscriber_subscription_template`
(`notification_id`,`media_id`,`locale`,`name`,`subject`,`body`) VALUES
    (@notification_id, @email_media, 'en_US',
     'Task Cancellation Notification',
     'Task Cancellation Notification - %taskName%',
     '<p>Hi %recipientFirstName%,<br /><br />Following task was cancelled/removed from %eventUrl%.<br />Task Name: %taskName%<br /><br />Please check OrangeHRM for more details.</br>
<br/>Thank you.<br/><br />This is an automated notification.</p>');


SET @template_id := LAST_INSERT_ID();

INSERT INTO `ohrm_notification_subscription`
(notification_id,  workflow_item_id, hidden) VALUES
    (@notification_id,  NULL, 0);
SET @last_subscription_id := LAST_INSERT_ID();


INSERT INTO `ohrm_notification_subscriber`(media_id, parameters, type, name) VALUES
    (@email_media, '{"prevent_delete":true}', 'Custom','Event Owner');

SET @subscriber_id := LAST_INSERT_ID();

INSERT INTO `ohrm_notification_subscriber_subscription`(subscription_id, subscriber_id, template_id) SELECT
                                                                                                         s.id, @subscriber_id, @template_id FROM ohrm_notification_subscription s WHERE s.id >= @last_subscription_id;

