/*
main entry point for API calls Chiefsoft July 2020 */
#include "mermsemr_api_main.h"
#include "mermsemr_api.h"
#include "clog.h"
#include "input.h"
#include "pgsql.h"
#include "pgsql_wrapper.h"
/*Other medtrans functions*/
#include "medTrBackOffice.h"
#include "medTrMembers.h"
#include "medTrTransporter.h"
#include "stripe_charge.h"
#include "medTEmails.h"
#include "medTUpload.h"
#include "providers.h"


long mermsemr_api_main(CVars in, CVars &out) {
    logfmt(logINFO, "long mermsemr_api_main(CVars in, CVars &out)");
    long retval = PHP_API_BAD_PARAM;
    long action = REQ_LONG(in, "action", 0, -1);
    //REQ_LONG( in, "pid", 0, -1); // global implementation - who is calling
    try {

        if ( action == MERMS_TEST_EMAIL ){
            logfmt(logINFO, "long MERMSEMR_BKO_START(CVars in, CVars &out)-> JUST A TEST EMAIL *******************************************");
            return  test_email_calls( action,  in, out);

        }

        if (action >= MERMS_USER_START && action <= MERMS_USER_END) {
            return members_call(in, out);
        }

        if (action >= MERMS_PROVIDERS_START && action <= MERMS_PROVIDERS_END) {
            return providers_call(in, out);
        }

        if (action >= MERMSEMR_BKO_START && action <= MERMSEMR_BKO_END) {
            logfmt(logINFO, "long MERMSEMR_BKO_START(CVars in, CVars &out)*******************************************");
            return backoffice_calls(in, out);
        }


    } catch (bad_parameter) {
        logfmt(logINFO, "ERROR CALL long mermsemr_api_main(CVars in, CVars &out)");
    }
    return retval;

}


