package com.ferienclub.beachclub.esb;

import java.util.Date;

import org.apache.log4j.Logger;
import org.mule.impl.RequestContext;
import org.mule.umo.UMOEventContext;
import org.mule.umo.UMOException;

import com.ferienclub.beachclub.esb.messages.OrderRequest;
import com.ferienclub.beachclub.esb.messages.Position;
import com.ferienclub.custadmin.beans.HistoryEntry;
import com.ferienclub.leisure.esb.messages.HistoryEntryRequest;

public class RFIDGateway {

	Logger log = Logger.getLogger(RFIDGateway.class);
	
	public void process(OrderRequest request){
		UMOEventContext context = RequestContext.getEventContext();
		log.info("Entering method process(OrderRequest request)");
		int x,y;
		x = (int)((Math.random() * 100) % 11);
		y = (int)((Math.random() * 100) % 11);
		Position pos = new Position(x,y);
		request.setPos(pos);
		try {
			log.info("Sending the order to the Beach Club.");
			context.sendEvent(request);
		} catch (UMOException e) {
			e.printStackTrace();
		}
		
		try {
			log.info("Sending HistoryEntry.");
			context.sendEvent(new HistoryEntryRequest(request.getUser().getUserId(),"BEACHCLUB","Ordered Drink No. " + request.getOrder().getName() + " -- " + request.getOrder().getPrice()));
		} catch (UMOException e) {
			e.printStackTrace();
		}
		log.info("Stopping MULE from further processing of messages.");
		context.setStopFurtherProcessing(true);
	}
	
}
