-- === TOP_ALLOTMENT_MODIFICATION_HEADER

--=============================================================================================================================
--Step 1: Create Template Table
--=============================================================================================================================
--Table  TOP_ALLOTMENT_MODIFICATION_HEADER
   
CREATE TABLE "CT_ET_TEMPLATES"."TOP_ALLOTMENT_MODIFICATION_HEADER" 
   (	
    "A_KEY" NUMBER(38,0), 
	"A_WORKFLOW_HISTORY_KEY" NUMBER(38,0), 
	"REF_NO" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"OPERATION_CURRENCY" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"TIMESTAMP_" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"REVISION" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"TIMESTAMP_SENDER" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"ID" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"CHECKSUM" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP"
   )  ;
   
--=============================================================================================================================
--Step 2: Create External Tables
--=============================================================================================================================

--Table TOP_ALLOTMENT_MODIFICATION_HEADER

--INBOX -For incoming files awaiting processing
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'TOP_ALLOTMENT_MODIFICATION_HEADER_INBOX',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_HEADER',
        pPrefix => 'INBOX/TOP/TenderAllotmentModifications/TOP_ALLOTMENT_MODIFICATION_HEADER',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvInboxBucketUri
    );
END;

--ODS - for processed files in operational data store
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'TOP_ALLOTMENT_MODIFICATION_HEADER_ODS',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_HEADER',
        pPrefix => 'ODS/TOP/TOP_ALLOTMENT_MODIFICATION_HEADER',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvDataBucketUri
    );
END; 

--ARCHIVE - For historical/archived files
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'TOP_ALLOTMENT_MODIFICATION_HEADER_ARCHIVE',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_HEADER',
        pPrefix => 'ARCHIVE/TOP/TOP_ALLOTMENT_MODIFICATION_HEADER',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvArchiveBucketUri
    );
END;
   
  
    
--=============================================================================================================================
--Step 4: Configure file type for processing
--=============================================================================================================================

 call CT_MRDS.FILE_MANAGER.ADD_SOURCE_FILE_CONFIG(
         pSourceKey             => 'TOP'
        ,pSourceFileType        => 'INPUT'
        ,pSourceFileId          => 'TenderAllotmentModifications'
        ,pSourceFileDesc        => 'TOP source'
        ,pSourceFileNamePattern => '.*.csv'
        ,pTableId               => 'TOP_ALLOTMENT_MODIFICATION_HEADER'
        ,pTemplateTableName     => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_HEADER' 
        );
	   	    
		 
   -- TenderAllotmentModifications