SET @notification_media_id := (SELECT `id` FROM `ohrm_notification_media` WHERE `name` = 'Email');

SET @notification_type_id := (SELECT `id` FROM `ohrm_notification_type` WHERE `name` = 'Action Based');
SET @module_id := (SELECT `id` FROM `ohrm_module` WHERE `name` = 'recruitment');

INSERT INTO `ohrm_notification` (`name`, `is_enable`,`type_id`, `generator_class`, `module_id`, `hidden`)
VALUES ('Vacancy Workflow Change', 0, @notification_type_id, NULL, @module_id, 1);

SET @notification_id := LAST_INSERT_ID();

INSERT INTO `ohrm_notification_supported_media` (`notification_id`, `media_id`)
VALUES (@notification_id, @notification_media_id);

INSERT INTO `ohrm_notification_subscriber_subscription_template` (`name`,`notification_id`,`media_id`,`locale`,
                                                                  `subject`,`body`)
VALUES ('Vacancy Workflow Change Template', @notification_id, @notification_media_id, 'en_US',
        'Candidate Notification - %candidateFirstName% %candidateLastName% for the %vacancyName% Vacancy - %candidateNewEvent%',
        'Hi %subscriberFirstName%,<br/><br/>Please note that candidate %candidateFirstName% %candidateLastName% is now in the %candidateNewEvent% stage for the %vacancyName% Vacancy.<br/><br/>The candidate was in the %candidateOldStateDescription% stage before.<br/><br/>Thank you.<br/>This is an automated notification.'),
       ('Vacancy Workflow Change Template Initial', @notification_id, @notification_media_id, 'en_US',
        'Candidate Notification - %candidateFirstName% %candidateLastName% for the %vacancyName% Vacancy - %candidateNewEvent%',
        'Hi %subscriberFirstName%,<br/><br/>Please note that candidate %candidateFirstName% %candidateLastName% is now in the %candidateNewEvent% stage for the %vacancyName% Vacancy.<br/><br/>Thank you.<br/>This is an automated notification.');

SET @max_position := (SELECT MAX(`position`) FROM `ohrm_event_listener`);

INSERT INTO `ohrm_event_listener` ( `event`, `listener_class`, `enabled`, `position`) VALUES
('recruitment.workflow_change', 'VacancyCandidateWorkflowChangeListener', 1, @max_position+1);
