--Table TOP_ALLOTMENT

--=============================================================================================================================
--Step 1: Create Template Table
--=============================================================================================================================
--Table TOP_ALLOTMENT 
   
CREATE TABLE "CT_ET_TEMPLATES"."TOP_ALLOTMENT"
   (	
    "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", 
	"CURRENCY_INFO" 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", 
	"AMOUNT" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"NUMBER_BIDDERS" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"CUTOFF_LEVEL" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"AMNT_ALLOTED" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MIN_ALLOTMENT" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"PERC_ALLOTED" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MARGINAL_RATE_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MARGINAL_RATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MIN_RATE_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MIN_RATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MAX_RATE_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"MAX_RATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"AVG_RATE_TYPE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"AVG_RATE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"SPOT_RATE" 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", 
	"ISIN" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"REF_ENTITY" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"REF_ENTITY_VALUE" VARCHAR2(4000 CHAR) COLLATE "USING_NLS_COMP", 
	"SPOT_RATE_WITH_MARGIN" 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)
   ) ;
   
  --=============================================================================================================================
--Step 2: Create External Tables
--=============================================================================================================================

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

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