load("lib/integrationservices/javascript/log.js");
load("lib/integrationservices/javascript/xmutil.js");
load("lib/integrationservices/javascript/apxml.js");
load("lib/integrationservices/javascript/xmio.js");

function apia_input(apxml)
{
	IALOG.info("Event.js: Entering apia_input.");
	IALOG.debug("\tapxml is: \n {0}", apxml );
	if (XMUtil.deduplicator.isDuplicate(apxml)) {
		IALOG.info("Event.js: Marking the message as duplicate and discarding.");
		XMUtil.deduplicate(apxml);
		return;
	}

	var eventObj = XMUtil.createEventTemplate();
    var newKeys = (typeof apia_remapped_data === 'function') ? apia_remapped_data() : null;
    IALOG.debug("\tConverting apxml to JSON object");
    var apxmlAsObj = APXML.toEventJs(apxml, eventObj, newKeys);
    var obj = apia_event(apxmlAsObj);
    if (obj) {
		IALOG.debug("\tPosting data to xMatters");
	    XMIO.post(JSON.stringify(obj));
	    XMUtil.deduplicator.incrementCount(apxml);
    }
}

function apia_response(apxml) {
	IALOG.info("Event.js: Entering apia_response...");
	IALOG.debug("\tapxml is: \n {0}", apxml );
    var apxmlAsObj = APXML.toResponseJs(apxml);
    var obj = apia_callback(apxmlAsObj);
}