  /* $Id$ */
  /*============================================================================*
   |                 Copyright (c) 2017 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
                         := 'CloudAnalytics';

  BEGIN

    xxas_com_sr_pkg.set_rest_service
      (p_service_name       => l_SERVICE
      ,p_description        => 'Cloud analytics'
      ,p_consumes           => 'application/json'
      ,p_produces           => 'application/json'
      );

    xxas_com_sr_pkg.set_rest_method
      (p_service_name       => l_SERVICE
      ,p_method_name        => 'GetCloudAnalytics'
      ,p_description        => 'Gets a blocks''s analytics from Applaud Cloud'
      ,p_path               => 'cloud-analytics/{blockId}'
      ,p_methods            => 'GET'
      ,p_sql                =>
      q'[SELECT xxas_http_response.ok()
               .entity_with_etag
                 (xxas_emp_view_ui_pkg.get_cloud_analytics
                   ({pathParam.blockId}
                   ,{requestParam.id})
                 ,''application/json'')
               .build() "httpResponse"
         FROM   dual
       ]' 
      );
      
    xxas_com_sr_pkg.set_rest_method
      (p_service_name       => l_SERVICE
      ,p_method_name        => 'GetCloudAnalyticsExport'
      ,p_description        => 'Export a blocks''s analytics from Applaud Cloud'
      ,p_path               => 'cloud-analytics-export/{blockName}'
      ,p_methods            => 'GET'
      ,p_sql                =>
      q'[SELECT xxas_http_response.ok()
               .entity_with_etag
                 (xxas_emp_view_ui_pkg.get_cloud_analytics_export
                   (xxas_com_sec_pkg.get_function_id({pathParam.blockName})
                   ,{requestParam.id})
                 ,''application/octet- stream''
                 ,''attachment; filename=export.csv'')
               .build() "httpResponse"
         FROM   dual
       ]' 
      );
      
  END;
  /
  COMMIT;
  EXIT;