<?xml version="1.0" encoding="UTF-8"?>
<api context="/snowflakeconnector" name="SnowflakeConnectorApi" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST" uri-template="/insertReservation">
        <inSequence>
            <property expression="json-eval($)" name="payload" scope="default" type="STRING"/>
            <snowflake.execute configKey="SNOWFLAKE_CONNECTION">
                <executeQuery>INSERT INTO HOTEL_DB.PUBLIC.RESERVATIONS (NICNUMBER, FIRSTNAME, LASTNAME, CHECKIN, CHECKOUT, ADULTS, CHILDREN, ROOMTYPE, SPECIALREQUESTS) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)</executeQuery>
                <payload>{$ctx:payload}</payload>
            </snowflake.execute>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
    <resource methods="GET" uri-template="/getReservationInfo">
        <inSequence>
            <snowflake.query configKey="SNOWFLAKE_CONNECTION">
                <query>SELECT * FROM HOTEL_DB.PUBLIC.RESERVATIONS</query>
            </snowflake.query>
            <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
    <resource methods="POST" uri-template="/insertReservationBatch">
        <inSequence>
            <property expression="json-eval($)" name="payload" scope="default" type="STRING"/>
            <snowflake.batchExecute configKey="SNOWFLAKE_CONNECTION">
                <executeQuery>INSERT INTO HOTEL_DB.PUBLIC.RESERVATIONS (NICNUMBER, FIRSTNAME, LASTNAME, CHECKIN, CHECKOUT, ADULTS, CHILDREN, ROOMTYPE, SPECIALREQUESTS) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)</executeQuery>
                <payload>{$ctx:payload}</payload>
            </snowflake.batchExecute>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
    <resource methods="DELETE" uri-template="/deleteReservation/{NICNUMBER}">
        <inSequence>
            <property expression="fn:concat('DELETE FROM HOTEL_DB.PUBLIC.RESERVATIONS WHERE NICNUMBER=',get-property('uri.var.NICNUMBER'))" name="deleteQuery" scope="default" type="STRING"/>
            <snowflake.execute configKey="SNOWFLAKE_CONNECTION">
                <executeQuery>{$ctx:deleteQuery}</executeQuery>
            </snowflake.execute>
            <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>
