/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2014 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
SET SCAN OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  --
  -- Local constants and variables
  --
  l_SERVICE CONSTANT xxas_com_service_repository.service_name%TYPE
                       := 'ApplicantStatuses';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'View available applicant satuses'
    ,p_path               => '/vacancies/{vacancyId}/applicants/{applicantId}/statuses'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
   
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetApplicantStatuses'
    ,p_description        => 'Get a list of allowed statuses for a given applicant'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
          SELECT XMLElement
                   ("data"
                   ,XMLAttributes
                     ('true' as "json:force-array"
                     ,'http://json.org/' as "xmlns:json")
                   ,XMLAgg
                     (XMLElement
                       ("status"
                       ,XMLForest
                         (rslt.assignment_status_type_id "id"
                         ,rslt.system_meaning "groupStatus"
                         ,rslt.customer_status "status"
                         ,xxas_com_rest_util_pkg.uri_from_path
                           ('/vacancies/' || {pathParam.vacancyId} || '/applicant-status-comms/' || rslt.assignment_status_type_id) "commsHref"
                         )
                       )
                     ORDER BY rslt.customer_status
                     )
                   ) AS "data"
          FROM   xxas_applicant_statuses_v rslt
          WHERE  rslt.assignment_id = {pathParam.applicantId}
          AND    {authFunctionPredicate.XXAS_APL_STAT_NEW_PERM}
      ]'
    );
    
END;
/
COMMIT;
EXIT;
