/* $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
                       := 'PageCreate';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Page Create'
    ,p_path               => 'page-create'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
    
         xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetSubMenus'
    ,p_description        => 'Get Sub Menus'
    ,p_path               => '{sub_menu_id}'
    ,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
                     ("submenu"
                     ,XMLForest
                       (p.sub_menu_id as "id"
                       ,p.prompt      as "label"
                       ,p.prompt      as "value"
                       )
                     )
                   )
                 )"data"
        FROM (select 9999 sub_menu_id, 'Root (top-level menu item)' prompt from dual
        UNION ALL
        select fme.sub_menu_id, fme.prompt
        FROM xxas_object_values ov, fnd_menu_entries_vl fme, fnd_menus fm
        WHERE upper(fm.menu_name) = upper({pathParam.sub_menu_id})
        and fm.menu_id = fme.menu_id
        and fme.sub_menu_id = ov.object_id )p
      ]'
    );
    
END;
/
COMMIT;
EXIT;