-- Add new task 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 - New Task Created Notification', 1, @other_notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"OnBoardingTaskEmailProcessor"}', 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',
     'New Task Created Notification Template',
     'New Tasks Notification - %recipientFirstName%',
     '<p>Hi %recipientFirstName%,<br /><br />New tasks were assigned to you.<br />%pendingTasks%<br /><br />Please check OrangeHRM for more details.<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','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;


-- Event added notification
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 @job_owner_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'OhrmJobOwner');

INSERT INTO `ohrm_notification`
(`name`, `is_enable`,`type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`,`module_id`, `hidden`) VALUES
    ('Onboarding - New Event Created Notification', 1, @other_notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"OnBoardingEmailProcessor"}', 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',
     'New Event Created Notification Template',
     'New Event Notification - %recipientFirstName%',
     '<p>Hi %recipientFirstName%,<br /><br />You are now the event owner for %eventName%, which is due on %dueDate%.<br />Please check OrangeHRM for further details.<br/>%eventUrl%<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;

-- reminder notification
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 @job_owner_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'OhrmJobOwner');

INSERT INTO `ohrm_notification`
(`name`, `is_enable`,`type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`,`module_id`, `hidden`) VALUES
    ('Onboarding - Reminder Task Notification', 1, @other_notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"OnBoardingTaskReminderEmailProcessor"}', 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',
     'Reminder Task Notification Template',
     'Reminder Task Notification - %recipientFirstName%',
     '<p>Hi,<br /><br />The following task is nearing its due-date<br /><br />Event: %event%<br />Task: %pendingTask%<br />Description: %description%<br />Task Owner: %taskowner%<br />Participant: %newHire%<br />Due Date: %dueDate%<br />Status: %status%<br />Priority: %priority%<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','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;


-- pending notification
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 @job_owner_user_role := (SELECT id FROM ohrm_user_role WHERE `name` = 'OhrmJobOwner');

INSERT INTO `ohrm_notification`
(`name`, `is_enable`,`type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`,`module_id`, `hidden`) VALUES
    ('Onboarding - Pending Task Notification', 1, @other_notification_type, 'LegacyEmailProcessorWrapperEventNotification',
     '{"email_processor":"OnBoardingPendingTaskReminderEmailProcessor"}', 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',
     'Pending Task Notification Template',
     'Pending Task Notification',
     'Hi,<br/><br/>

Pending Tasks as of: %date%<br/><br/>
%pendingTasks%
<br/>
Thank you.<br/>
<br/>
This is an automated notification');


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;


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;