--------------------------------------------------------
--  DDL for Package Body API_ENVX_OPER
--------------------------------------------------------

  CREATE OR REPLACE EDITIONABLE PACKAGE BODY "ENVX_OPER"."API_ENVX_OPER" AS

   ----------------------------------------------------
   -- Devuelve la lista de Repositorios Configurados --
   FUNCTION repository_config_list(
      js_parameters CLOB DEFAULT NULL
   ) RETURN CLOB
   IS
      v_json CLOB;
   BEGIN

      SELECT JSON_ARRAYAGG(
                JSON_OBJECT(
                   'id' VALUE to_number(r.id_repository),
                   'description' VALUE r.repository_description,
                   'alias' VALUE r.repository_name,
                   'host' VALUE r.repository_host,
                   'user' VALUE r.user_repo,
                   'password' VALUE r.pass_repo,
                   'name' VALUE r.repository_def_path,
                   'status' VALUE r.repository_status,
                   'tech' VALUE t.tech,
                   'port' VALUE TO_NUMBER(r.repository_port),
                   'protocol' VALUE r.repository_protocol,
                   'apiVersion' VALUE r.repository_api_version,
                   'repositoryOwner' VALUE r.repository_owner
                )
             )
        INTO v_json
        FROM version_repository r, (
                SELECT j.tech, j.idtech
                  FROM system_parameter sp,
                       JSON_TABLE(JSON(sp.parameter_value),
                          '$[*]' COLUMNS (idtech NUMBER       PATH '$.idTech',
                                          tech   VARCHAR(100) PATH '$.tech')
                       ) j
                 WHERE parameter_name = 'REPOSITORY_TECH'
             )                  t
       WHERE t.idtech = r.repository_tech;

      RETURN v_json;
   END;
   -- Devuelve la lista de Repositorios Configurados --
   ----------------------------------------------------

END api_envx_oper;

/

  GRANT EXECUTE ON "ENVX_OPER"."API_ENVX_OPER" TO "APEX_PUBLIC_USER";
  GRANT DEBUG ON "ENVX_OPER"."API_ENVX_OPER" TO "APEX_PUBLIC_USER";
  GRANT EXECUTE ON "ENVX_OPER"."API_ENVX_OPER" TO PUBLIC;
  GRANT DEBUG ON "ENVX_OPER"."API_ENVX_OPER" TO PUBLIC;
