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

   
--Table CSDB_ISSUER_DESC_FULL   
CREATE TABLE "CT_ET_TEMPLATES"."CSDB_ISSUER_DESC_FULL" 
   (	"A_KEY" NUMBER(38,0) NOT NULL ENABLE, 
        "A_WORKFLOW_HISTORY_KEY" NUMBER(38,0) NOT NULL ENABLE, 
        "RDB_ISSUER_ID" VARCHAR2(4000 CHAR), 
        "ISSUERNAME" VARCHAR2(4000 CHAR), 
        "COUNTRY_DOMICILE" VARCHAR2(4000 CHAR), 
        "IS_SOVEREIGN" VARCHAR2(4000 CHAR), 
        "MOODY_IDENTIFIER" VARCHAR2(4000 CHAR), 
        "SNP_ISSUER_ID" VARCHAR2(4000 CHAR), 
        "FITCH_IDENTIFIER" VARCHAR2(4000 CHAR), 
        "DBRS_IDENTIFIER" VARCHAR2(4000 CHAR), 
        "LEI_ISSUER_ID" VARCHAR2(4000 CHAR), 
        "RIAD_CODE" VARCHAR2(4000 CHAR), 
        "RIAD_OUID" VARCHAR2(4000 CHAR), 
        "CLASH_GROUP_STATUS" VARCHAR2(4000 CHAR), 
        "SCO_ISSUER_ID" VARCHAR2(4000 CHAR), 
        "PLACEHOLDER5" 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_ISSUER_DESC_FULL
  
--INBOX -For incoming files awaiting processing
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'CSDB_ISSUER_DESC_FULL_INBOX',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_ISSUER_DESC_FULL',
        pPrefix => 'INBOX/CSDB/FullRatingsDissemination/CSDB_ISSUER_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_ISSUER_DESC_FULL_ODS',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_ISSUER_DESC_FULL',
        pPrefix => 'ODS/CSDB/CSDB_ISSUER_DESC_FULL',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvDataBucketUri
    );
END; 


--ARCHIVE - For historical/archived files
BEGIN
    ODS.FILE_MANAGER_ODS.CREATE_EXTERNAL_TABLE(
        pTableName => 'CSDB_ISSUER_DESC_FULL_ARCHIVE',
        pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_ISSUER_DESC_FULL',
        pPrefix => 'ARCHIVE/CSDB/CSDB_ISSUER_DESC_FULL',
        pBucketUri => CT_MRDS.ENV_MANAGER.gvArchiveBucketUri
    );
END; 
  
  
--=============================================================================================================================
--Step 3: Configure file type for processing
--=============================================================================================================================

 
--Table CSDB_ISSUER_DESC_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_ISSUER_DESC_FULL',
    pTemplateTableName => 'CT_ET_TEMPLATES.CSDB_ISSUER_DESC_FULL',
    pContainerFileKey => NULL
);