-- ================== TOP_ANNOUNCEMENT

--=============================================================================================================================
--Step 1: Create Template Table
--=============================================================================================================================
--Table TOP_ANNOUNCEMENT 
   
CREATE TABLE "CT_ET_TEMPLATES"."TOP_ANNOUNCEMENT" 
 (
    "A_KEY" NUMBER(38,0) NOT NULL ENABLE, 
	"A_ETL_LOAD_SET_FK" NUMBER(38,0) NOT NULL ENABLE, 
	"REF_NO" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"CURRENCYINFO" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"SENDER_REF" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"USER_REF" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"TIMESTAMP" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"VERSION" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"OPERATION_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"PROCEDURE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"TRANSACTION_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"OPERATION_NAME" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"AUCTION_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"ALL_METHOD" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"QUOTATION" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"BUSINESS_VALUE_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"BUSINESS_VALUE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"ALLOTMENT_DATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"VALUE_DATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MATURITY_DATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"DURATION_OF_OPERATION" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"SPOT_RATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"OTHER_CURRENCY" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"OPERATION_CURRENCY_LEG" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MIN_BID_AMT" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MAX_BID_AMT" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"INTENDED_VOLUME" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MIN_ALLOTMENT" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MIN_ALLOTMENT_RATIO" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"DEADLINE_CP" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"DEADLINE_NCB" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"PUBLIC_ANNOUNCEMENT" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"FREE_TEXT" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"CHECKSUM" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"PRINT_DATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"OPER_CURRENCY" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"ISIN" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"REF_ENTITY" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"SPOT_RATE_WITH_MARGIN" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MAX_BIDS_COUNTER_PARTY" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"EXACT_DENOMINATION" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"BID_CURRENCY" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"TIMESTAMP_SENDER" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"ID" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"REPAID_REF_NO" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"REVISION" NUMBER(*,0), 
	"OPERATION_CATEGORY" VARCHAR2(50 CHAR) 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_ANNOUNCEMENT_INBOX',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ANNOUNCEMENT',
        pPrefix => 'INBOX/TOP/AnnouncementPublicationC2D/TOP_ANNOUNCEMENT',
        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_ANNOUNCEMENT_ODS',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ANNOUNCEMENT',
        pPrefix => 'ODS/TOP/TOP_ANNOUNCEMENT',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvDataBucketUri
    );
END; 

--ARCHIVE - For historical/archived files
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'TOP_ANNOUNCEMENT_ARCHIVE',
        pTemplateTableName => 'CT_ET_TEMPLATES.TOP_ANNOUNCEMENT',
        pPrefix => 'ARCHIVE/TOP/TOP_ANNOUNCEMENT',
        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          => 'AnnouncementPublicationC2D'
        ,pSourceFileDesc        => 'TOP source'
        ,pSourceFileNamePattern => '.*.csv'
        ,pTableId               => 'TOP_ANNOUNCEMENT'
        ,pTemplateTableName     => 'CT_ET_TEMPLATES.TOP_ANNOUNCEMENT' 
        );
	   	    
		 
   