package org.ofbiz.extended;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ofbiz.base.util.Debug;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;

public class HotelEvents {
	public static final String module = HotelEvents.class.getName();
	
//	public static String getHotelList(HttpServletRequest request, HttpServletResponse response) {
//		GenericValue party = (GenericValue) request.getSession().getAttribute("partyId");
//		String partyId = party.getString("partyId");
//		List hotelPartyIdList = new ArrayList();
//		//TODO get children parties
//		hotelPartyIdList.add(partyId);
//		request.setAttribute("partyIdList", hotelPartyIdList);
//		return "success";
//	}
	
	public static String getReservationsForHotelList(HttpServletRequest request, HttpServletResponse response) {
		String partyList = request.getParameter(("hotelList"));
		if(partyList == null || partyList.length() == 0){
			Debug.logInfo("partyIdList is null", module);
			return "success";
		}
		
		LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
		Map context = new HashMap();
		context.put("partyList", new ArrayList());
		
		try {
			Map result = dispatcher.runSync("getReservationsForHotelList", context);
			List reservations = (List) result.get("reservationsList");
			request.setAttribute("reservations", reservations);
			return "success";
		} catch (GenericServiceException e) {
			request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
			return "error";
		}
	}
}
