// Baxxon - API responder for PageData requests
//
import path from "node:path";

export default async function( bx ){

	// parse request params
	const reqAction = bx.reqURL.searchParams.get( 'action' );
	// verify, validate and clean reqAction
	
	// get request body
	const reqBody = bx.server.req.body;
	// before acting on any of the content in the requestBody verify, validate and clean

	// Respond to requested Action
	// all function calls are async
	let resData = {};
	switch( reqAction ){

		case 'save':
			bx.log.note( 'Saving data according to api payload' );
			//doSomethingWithRequest( reqBody.records );
			resData = { action: 'save', req: reqBody, result: 'done' };
			break;

		default:
			bx.log.error( 'No action in request URI' );
			resData = { err: 'api action not defined' };
	}

	bx.render.JSON( resData );
}
