/* $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
                       := 'NoteTypes';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Manage note types'
    ,p_path               => 'note-types'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetAvailableNoteTypesByAssignment'
    ,p_description        => 'Gets available note types for an assignment'
    ,p_methods            => 'GET'
    ,p_path               => 'by-job/{assignmentId}'
    ,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
                     ("noteType"
                     ,XMLForest
                       (rslt.type_code "id"
                       ,rslt.type "value"
                       ,rslt.type "label")
                     )
                   )
                 ) "data"
        FROM   xxas_note_types_v rslt
        WHERE  rslt.assignment_id = {pathParam.assignmentId}
        AND    nvl({requestParam.id}, rslt.type_code) = rslt.type_code
        AND    {authFunctionPredicate.XXAS_SRV_Q_NOTE_TYPES_PERM}
        ]'
    );
    
END;
/
COMMIT;
EXIT;
