INSERT INTO `ohrm_event_listener` ( `event`, `listener_class`, `enabled`, `position`) VALUES ('requestTracker.request_approver_update', 'RequestDeskRequestApproverUpdateEventListener', '1', '12');
INSERT INTO `ohrm_event_listener` ( `event`, `listener_class`, `enabled`, `position`) VALUES ('requestTracker.request_approver_update', 'RequestDeskRequestApproverRemoveEventListener', '1', '15');

-- request approver update on request

SET @email_media := (SELECT id FROM ohrm_notification_media WHERE `name` = 'Email');
SET @notification_type := (SELECT id FROM ohrm_notification_type WHERE `name`='Other');
SET @rd_module_id := (SELECT `id` FROM `ohrm_module` WHERE name = 'Request Desk');


INSERT INTO `ohrm_notification`
(`name`, `is_enable`,`type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`,`module_id`, `hidden`) VALUES
    ('(General/Hiring) Request Desk: Request Approver Updated', 1, @notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"RequestTrackerRequestApproverEmailProcessor"}', NULL, NULL,@rd_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',
        'Request Approver Updated Notification sent to Approver',
        'You are Selected as an Approver of %requestType%: %title%',
        '<pre style=\"font-size:12.8px;font-family:  Arial, sans-serif\">Hi %recipientFullName%,

You are assigned for %requestType%: %title% as an approver.
Assigned By: %assignedBy%
Assigned On: %assignedDateTime%
Please login to Request desk instance, for more details.
Link: %link%
Thank you.
This is an automated notification. </pre>.
        ');


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','Request Approver');

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;
-- removing approver from a request

INSERT INTO `ohrm_notification`
(`name`, `is_enable`,`type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`,`module_id`, `hidden`) VALUES
    ('(General/Hiring) Request Desk: Request Approver Removed', 1, @notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"RequestTrackerRequestApproverRemoveEmailProcessor"}', NULL, NULL,@rd_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',
     'Request Approver Removed Notification sent to old approver',
     'Your Work on %requestType%: %title% Has Been Delegated',
     '<pre style=\"font-size:12.8px;font-family:  Arial, sans-serif\">Hi %recipientFullName%,

Your work as the approver of the %requestType%:%title% has been delegated to another user.
Delegated By: %assignedBy%
Delegated On: %assignedDateTime%
Thank you for taking part on the request.

Thank you.
This is an automated notification. </pre>.');


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','Request Approver');

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;
