package org.yacos.web.chairman.controller;

import java.util.HashMap;
import java.util.Map;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.ModelAndViewDefiningException;
import org.springframework.web.servlet.mvc.AbstractWizardFormController;
import org.yacos.core.conferences.IConferenceManager;
import org.yacos.web.chairman.form.FormConference;

public class AddConferenceController extends AbstractWizardFormController {

	protected final Log logger = LogFactory.getLog(getClass());

	private IConferenceManager conferenceManager;

	public IConferenceManager getConferenceManager() {
		return conferenceManager;
	}
	public void setConferenceManager(IConferenceManager conferenceManager) {
		this.conferenceManager = conferenceManager;
	}
	
	public AddConferenceController() {
		setCommandName("formConference");
		setPages(new String[] {"addConference", "addConference2", "addConference3", "addConference4", "addConference5"});
	}
	
	protected Object formBackingObject(HttpServletRequest request) throws ModelAndViewDefiningException {		
		FormConference conference = new FormConference();
		return conference;
	}

	protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors, int page) {
		/*if (page == 0 && request.getParameter("shippingAddressRequired") == null) {
			OrderForm orderForm = (OrderForm) command;
			orderForm.setShippingAddressRequired(false);
		}*/
	}

	protected Map referenceData(HttpServletRequest request, int page) {
		/*if (page == 0) {
			List creditCardTypes = new ArrayList();
			creditCardTypes.add("Visa");
			creditCardTypes.add("MasterCard");
			creditCardTypes.add("American Express");
			Map model = new HashMap();
			model.put("creditCardTypes", creditCardTypes);
			return model;
		}*/
		return null;
		
	}

	/*protected int getTargetPage(HttpServletRequest request, Object command, Errors errors, int currentPage) {
		FormConference conference = (FormConference) command;
		if (currentPage == 0) {
			return 1;
		}
		else {
			return 2;
		}
	}*/

	protected void validatePage(Object command, Errors errors, int page) {
		FormConference conference = (FormConference) command;
		/*OrderValidator orderValidator = (OrderValidator) getValidator();
		errors.setNestedPath("order");
		switch (page) {
			case 0:
				orderValidator.validateCreditCard(orderForm.getOrder(), errors);
				orderValidator.validateBillingAddress(orderForm.getOrder(), errors);
				break;
			case 1:
				orderValidator.validateShippingAddress(orderForm.getOrder(), errors);
		}
		errors.setNestedPath("");*/
	}

	protected ModelAndView processFinish(
			HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
		FormConference conference = (FormConference) command;
		/*this.petStore.insertOrder(orderForm.getOrder());
		request.getSession().removeAttribute("sessionCart");
		Map model = new HashMap();
		model.put("order", orderForm.getOrder());
		model.put("message", "Thank you, your order has been submitted.");*/
		return new ModelAndView("main"/*, model*/);
	}

}
