/*
main entry point for API calls Chiefsoft July 2017 */
#include "mobideliv_api_main.h"
#include "mobideliv_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"

long mobideliv_api_main(CVars in, CVars &out)
{
	logfmt( logINFO, "long mobideliv_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 == MEDTRANS_UPLOADS )
            {
                return medtrans_upload(in, out);
            }
            if ( action == MEDTRANS_DOWNLOAD )
            {
                return medtrans_download(in, out);
            }
          
		
		if ( action >=MEDTRANS_BKO_START && action <=MEDTRANS_BKO_END )
		{   
			return  backoffice_calls(in, out);
		}
		
		if ( action >=MEDTRANS_USER_START && action <=MEDTRANS_USER_END )
		{
			return  members_call(in, out);
		}

		if ( action >=MEDTRANS_INTERP_START && action <=MEDTRANS_INTERP_END )
		{
		}
		
		if ( action >=MEDTRANS_TRANSP_START && action <=MEDTRANS_TRANSP_END )
		{
			return trasnporter_call(in, out);
		}	

	        if ( action >=MEDTRANS_CRON_START && action <=MEDTRANS_CRON_END )
		{
			return cron_call(in, out);
		}	
		
		
		if ( action == MEDTRANS_STRIPE_CHARGE_ONE )
		{
			return stripe_one_time_charge(in, out);
		}
		if ( action == MEDTRANS_STRIPE_CHARGE_NEW )
		{
			return stripe_new_customer_charge(in, out);
		}
		if ( action == MEDTRANS_EMAIL_TEST )
		{
		  return email_test(in, out);
		}	
		
	}
	catch (bad_parameter) {
		logfmt( logINFO, "ERROR CALL long mobideliv_api_main(CVars in, CVars &out)");		
	}
  return retval;
	
}


