--=============================================================================================================================
--Step 1: Create Template Table
--=============================================================================================================================

--Table CSDB_INSTR_DESC_FULL
 
	
 CREATE TABLE "CT_ET_TEMPLATES"."CSDB_INSTR_DESC_FULL" 
   ("A_KEY" NUMBER(38,0) NOT NULL ENABLE, 
	"A_WORKFLOW_HISTORY_KEY" NUMBER(38,0) NOT NULL ENABLE, 
	"IDIRINSTRUMENT" VARCHAR2(4000 CHAR) ,
	"ISIN" VARCHAR2(4000 CHAR) ,
	"MOO_INSTR_ID" VARCHAR2(4000 CHAR) ,
	"SNP_INSTR_ID" VARCHAR2(4000 CHAR) ,
	"FITCH_IDENTIFIER" VARCHAR2(4000 CHAR) ,
	"DBRS_IDENTIFIER" VARCHAR2(4000 CHAR) ,
	"EA_STATUS" VARCHAR2(4000 CHAR) ,
	"IS_TMS" VARCHAR2(4000 CHAR) ,
	"DBRS_COVERED_BOND_PROGRAM" VARCHAR2(4000 CHAR) ,
	"FITCH_PRG_IDENTIFIER" VARCHAR2(4000 CHAR) ,
	"MOO_DEAL_NUMBER" VARCHAR2(4000 CHAR) ,
	"SNP_PROGRAM_ID" VARCHAR2(4000 CHAR) ,
	"IDIRDEBTTYPE" VARCHAR2(4000 CHAR) ,
	"SNP_DEBT_TYPE" VARCHAR2(4000 CHAR) ,
	"MOODY_SENIORITY" VARCHAR2(4000 CHAR) ,
	"FITCH_DEBT_LEVEL_CODE" VARCHAR2(4000 CHAR) ,
	"DBRS_RANK_TYPE" VARCHAR2(4000 CHAR) ,
	"DBRS_SECURITY_TYPE" VARCHAR2(4000 CHAR) ,
	"SCO_DEBT_TYPE" VARCHAR2(4000 CHAR) ,
	"SCO_INSTR_ID" VARCHAR2(4000 CHAR) ,
	"SCO_COVERED_BOND_PROGRAM" VARCHAR2(4000 CHAR) ,
	"SCO_CATEGORY" VARCHAR2(4000 CHAR) ,
	"PLACEHOLDER15" VARCHAR2(4000 CHAR) ,
	"PLACEHOLDER16" VARCHAR2(4000 CHAR) ,
	"PLACEHOLDER17" VARCHAR2(4000 CHAR) ,
	"PLACEHOLDER18" VARCHAR2(4000 CHAR) ,
	"PLACEHOLDER19" VARCHAR2(4000 CHAR) ,
	"PLACEHOLDER20" VARCHAR2(4000 CHAR)  
   ) 
   ;	
   
--=============================================================================================================================
--Step 2: Create External Tables
--=============================================================================================================================

--Table CSDB_INSTR_DESC_FULL

--INBOX -For incoming files awaiting processing
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'CSDB_INSTR_DESC_FULL_INBOX',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_DESC_FULL',
        pPrefix => 'INBOX/CSDB/FullRatingsDissemination/CSDB_INSTR_DESC_FULL',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvInboxBucketUri
    );
END;

--ODS - for processed files in operational data store
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'CSDB_INSTR_DESC_FULL_ODS',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_DESC_FULL',
        pPrefix => 'ODS/CSDB/CSDB_INSTR_DESC_FULL',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvDataBucketUri
    );
END; 
 
--ARCHIVE - For historical/archived files
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'CSDB_INSTR_DESC_FULL_ARCHIVE',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_DESC_FULL',
        pPrefix => 'ARCHIVE/CSDB/CSDB_INSTR_DESC_FULL',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvArchiveBucketUri
    );
END;


--=============================================================================================================================
--Step 3: Configure file type for processing
--=============================================================================================================================

--Table CSDB_INSTR_DESC_FULL
CALL CT_MRDS.FILE_MANAGER.ADD_SOURCE_FILE_CONFIG(
    pSourceKey => 'CSDB',
    pSourceFileType => 'INPUT',
    pSourceFileId => 'FullRatingsDissemination',
    pSourceFileDesc => 'Table contains the identification codes and the rating codes (Moodys, S&P, Fitch, Scope, DBRS) for an instrument (not rating values).',
    pSourceFileNamePattern => '.*.csv',
    pTableId => 'CSDB_INSTR_DESC_FULL',
    pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_DESC_FULL',
    pContainerFileKey => NULL
);
   