/* $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
                       := 'UserDevices';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Manage a user''s devices'
    ,p_path               => 'user-devices'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'RegisterDevice'
    ,p_description        => 'Registers a user''s device'
    ,p_methods            => 'POST'
    ,p_plsql              =>
      q'[
        DECLARE

          l_resp        xxas_http_resp_obj;
          l_xml         XMLType;
          l_request_xml XMLType;

        BEGIN

          l_request_xml := {requestBody};

          --
          -- Call xxas_user_devices_pkg.register_device
          -- Pass the required {requestHeader.headerName} parameters {requestHeader.deviceId} {requestHeader.deviceType}
          --
          xxas_user_devices_pkg.register_device(l_request_xml , NULL);

          l_resp := xxas_http_response.ok().build();

          {response} := l_resp;

        END
      ]'
    );

END;
/
COMMIT;
EXIT;
