create or replace PACKAGE BODY ODS.FILE_MANAGER_ODS
AS

   /**
    * CREATE_EXTERNAL_TABLE - Wrapper for CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE
    */
   PROCEDURE CREATE_EXTERNAL_TABLE (
      pTableName          IN VARCHAR2,
      pTemplateTableName  IN VARCHAR2,
      pPrefix             IN VARCHAR2,
      pBucketUri          IN VARCHAR2 DEFAULT CT_MRDS.ENV_MANAGER.gvInboxBucketUri,
      pFileName           IN VARCHAR2 DEFAULT NULL,
      pDelimiter          IN VARCHAR2 DEFAULT ','
   )
   IS
      vParameters CT_MRDS.A_PROCESS_LOG.PROCEDURE_PARAMETERS%TYPE;
   BEGIN
      -- Log the start of the procedure
      vParameters := CT_MRDS.ENV_MANAGER.FORMAT_PARAMETERS(
         SYS.ODCIVARCHAR2LIST(
            'pTableName => ''' || pTableName || '''',
            'pTemplateTableName => ''' || pTemplateTableName || '''',
            'pPrefix => ''' || pPrefix || '''',
            'pBucketUri => ''' || pBucketUri || '''',
            'pFileName => ''' || NVL(pFileName, 'NULL') || '''',
            'pDelimiter => ''' || pDelimiter || ''''
         )
      );

      CT_MRDS.ENV_MANAGER.LOG_PROCESS_EVENT('Start FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE', 'INFO', vParameters);

      -- Call the original CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE procedure
      -- This ensures all logic remains centralized in the original package
      -- and ODS wrapper simply delegates execution with DEFINER rights
      CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE(
         pTableName => pTableName,
         pTemplateTableName => pTemplateTableName,
         pPrefix => pPrefix,
         pBucketUri => pBucketUri,
         pFileName => pFileName,
         pDelimiter => pDelimiter
      );

      CT_MRDS.ENV_MANAGER.LOG_PROCESS_EVENT('End FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE', 'INFO', vParameters);

   EXCEPTION
      WHEN OTHERS THEN
         CT_MRDS.ENV_MANAGER.LOG_PROCESS_EVENT(
            'Error in ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE: ' || SQLERRM, 
            'ERROR', 
            vParameters
         );
         RAISE;
   END CREATE_EXTERNAL_TABLE;

   ----------------------------------------------------------------------------------------------------
   -- PACKAGE VERSION MANAGEMENT FUNCTIONS IMPLEMENTATION
   ----------------------------------------------------------------------------------------------------

   FUNCTION GET_VERSION
   RETURN VARCHAR2
   IS
   BEGIN
      RETURN PACKAGE_VERSION;
   END GET_VERSION;

   ----------------------------------------------------------------------------------------------------

   FUNCTION GET_BUILD_INFO
   RETURN VARCHAR2
   IS
   BEGIN
      RETURN CT_MRDS.ENV_MANAGER.GET_PACKAGE_VERSION_INFO(
         pPackageName => 'FILE_MANAGER_ODS',
         pVersion => PACKAGE_VERSION,
         pBuildDate => PACKAGE_BUILD_DATE,
         pAuthor => PACKAGE_AUTHOR
      );
   END GET_BUILD_INFO;

   ----------------------------------------------------------------------------------------------------

   FUNCTION GET_VERSION_HISTORY
   RETURN VARCHAR2
   IS
   BEGIN
      RETURN CT_MRDS.ENV_MANAGER.FORMAT_VERSION_HISTORY(
         pPackageName => 'FILE_MANAGER_ODS',
         pVersionHistory => VERSION_HISTORY
      );
   END GET_VERSION_HISTORY;

   ----------------------------------------------------------------------------------------------------

END FILE_MANAGER_ODS;
