/**
 * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
 *
 * WSO2 LLC. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

@App:name("APIRawDataSubmissionApp")

@source(type='wso2event',  @map(type='wso2event'))
define stream APIInputStream(CONSENT_ID string, CONSUMER_ID string, CLIENT_ID string, USER_AGENT string,
                        STATUS_CODE int, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long, ELECTED_RESOURCE string,
                        API_NAME string, API_SPEC_VERSION string, TIMESTAMP long, MESSAGE_ID string);

@primaryKey('ID','ELECTED_RESOURCE')
@store(type='rdbms', datasource='OB_REPORTING_DB')
define table API_INVOCATION_RAW_DATA(ID string, CONSENT_ID string, CONSUMER_ID string, CLIENT_ID string,
                        USER_AGENT string, STATUS_CODE int, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long,
                        ELECTED_RESOURCE string, API_NAME string, API_SPEC_VERSION string, TIMESTAMP long,
                        MESSAGE_ID string);

from APIInputStream
select UUID() as ID, CONSENT_ID, CONSUMER_ID, CLIENT_ID, USER_AGENT, STATUS_CODE, HTTP_METHOD, RESPONSE_PAYLOAD_SIZE,
                        ELECTED_RESOURCE, API_NAME, API_SPEC_VERSION, TIMESTAMP, MESSAGE_ID
insert into API_INVOCATION_RAW_DATA;
