/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2016 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
                       := 'Directreports';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Rest service for Direct reports page' 
    ,p_path               => 'direct-reports'    
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
    
   xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetReporteesPDP'
    ,p_description        => 'Get reportees PDP for the given manager and plan'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => '{functionName}/{personId}/{perfPlanId}'
    ,p_sql                =>
      q'[
         SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                   , xxas_com_sec_pkg.get_obj_data_w_binds
          ({pathParam.functionName}
          ,xxas_com_varchar2_table('PERSON_ID = :PERSON_ID', 'PERF_PLAN_ID = :PERF_PLAN_ID')
          ,xxas_com_srv_param_varray
            (xxas_com_srv_param_value('PERSON_ID', {pathParam.personId})
            ,xxas_com_srv_param_value('PERF_PLAN_ID', {pathParam.perfPlanId}))
          , null -- p_rowset_tag_name 
          ,'item' -- p_row_tag_name 
          ,{requestParam.pageNumber}
          ,{requestParam.perPage})) "data"
      FROM dual
      ]'
    ); 
        
END;
/
COMMIT;
EXIT;
