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

--Table CSDB_INSTR_RAT_FULL
CREATE TABLE   "CT_ET_TEMPLATES"."CSDB_INSTR_RAT_FULL"
   (	"A_KEY" NUMBER(38,0) NOT NULL ENABLE, 
        "A_WORKFLOW_HISTORY_KEY" NUMBER(38,0) NOT NULL ENABLE, 
        "RDB_INSTR_ID" VARCHAR2(4000 CHAR), 
        "SOURCE" VARCHAR2(10 CHAR), 
        "RATING_SCHEME" VARCHAR2(32 CHAR), 
        "RATING" VARCHAR2(50 CHAR), 
        "RATING_DATE" VARCHAR2(4000 CHAR), 
        "TIME_HORIZON" VARCHAR2(2 CHAR), 
        "CURRENCY_TYPE" VARCHAR2(10 CHAR), 
        "NOTES" VARCHAR2(4000 CHAR), 
        "VALID_FROM" VARCHAR2(4000 CHAR), 
        "VALID_UNTIL" VARCHAR2(4000 CHAR), 
        "RDB_RATINGS_ID" VARCHAR2(4000 CHAR), 
        "WATCHLIST" VARCHAR2(50 CHAR), 
        "WATCHLIST_DATE" VARCHAR2(4000 CHAR), 
        "OUTLOOK" VARCHAR2(50 CHAR), 
        "OUTLOOK_DATE" VARCHAR2(4000 CHAR), 
        "RATING_ACTION" VARCHAR2(100 CHAR), 
        "RATING_ACTION_DATE" VARCHAR2(4000 CHAR), 
        "IS_PRELIMINARY" VARCHAR2(1 BYTE), 
        "RATING_RAW" VARCHAR2(50 CHAR), 
        "RATING_TYPE" VARCHAR2(4000 CHAR), 
        "ENDORSEMENT_INDICATOR" VARCHAR2(4000 CHAR), 
        "LAST_REVIEW_DATE" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER6" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER7" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER8" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER9" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER10" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER11" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER12" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER13" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER14" 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_RAT_FULL  

--INBOX -For incoming files awaiting processing
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'CSDB_INSTR_RAT_FULL_INBOX',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_RAT_FULL',
        pPrefix => 'INBOX/CSDB/FullRatingsDissemination/CSDB_INSTR_RAT_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_RAT_FULL_ODS',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_RAT_FULL',
        pPrefix => 'ODS/CSDB/CSDB_INSTR_RAT_FULL',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvDataBucketUri
    );
END; 

--ARCHIVE - For historical/archived files
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'CSDB_INSTR_RAT_FULL_ARCHIVE',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_RAT_FULL',
        pPrefix => 'ARCHIVE/CSDB/CSDB_INSTR_RAT_FULL',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvArchiveBucketUri
    );
END;

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

--Table CSDB_INSTR_RAT_FULL
CALL CT_MRDS.FILE_MANAGER.ADD_SOURCE_FILE_CONFIG(
    pSourceKey => 'CSDB',
    pSourceFileType => 'INPUT',
    pSourceFileId => 'FullRatingsDissemination',
    pSourceFileDesc => 'Table contains the actual ratings with current and historical values for an instrument.',
    pSourceFileNamePattern => '.*.csv',
    pTableId => 'CSDB_INSTR_RAT_FULL',
    pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_INSTR_RAT_FULL',
    pContainerFileKey => NULL
);