-- ================== TOP_ALLOTMENT_MODIFICATION_ITEM 

--=============================================================================================================================
--Step 1: Create Template Table
--=============================================================================================================================
--Table TOP_ALLOTMENT_MODIFICATION_ITEM 
   
CREATE TABLE "CT_ET_TEMPLATES"."TOP_ALLOTMENT_MODIFICATION_ITEM" 
   (	
    "A_KEY" NUMBER(38,0), 
	"A_ALL_MOD_FK" NUMBER(38,0) NOT NULL ENABLE, 
	"A_ETL_LOAD_SET_FK" NUMBER(38,0), 
	"SENDER_REFERENCE" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"BIDDER_ID" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"FLOW_TYPE" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"AMOUNT_ITEM" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"VALUE_DATE" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP", 
	"FREE_TEXT" VARCHAR2(4000 BYTE) COLLATE "USING_NLS_COMP"
   ) ;
   

--=============================================================================================================================
--Step 2: Create External Tables
--=============================================================================================================================

--Table TOP_ALLOTMENT_MODIFICATION_ITEM

--INBOX -For incoming files awaiting processing
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'TOP_ALLOTMENT_MODIFICATION_ITEM_INBOX',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_ITEM',
        pPrefix => 'INBOX/TOP/TenderAllotmentModifications/TOP_ALLOTMENT_MODIFICATION_ITEM',
        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_ITEM_ODS',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_ITEM',
        pPrefix => 'ODS/TOP/TOP_ALLOTMENT_MODIFICATION_ITEM',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvDataBucketUri
    );
END; 

--ARCHIVE - For historical/archived files
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'TOP_ALLOTMENT_MODIFICATION_ITEM_ARCHIVE',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_ITEM',
        pPrefix => 'ARCHIVE/TOP/TOP_ALLOTMENT_MODIFICATION_ITEM',
        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_ITEM'
        ,pTemplateTableName     => 'CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_ITEM' 
        );
	   	    
		 
   --    