package com.ferienclub.admin.actions;

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

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOMessage;

import com.ferienclub.admin.forms.AppointmentForm;

public class DeleteAppointmentAction extends Action {

	Logger log = Logger.getLogger(CreateAppointmentAction.class);
	
	public ActionForward perform(ActionMapping mapping,
			 ActionForm form,
			 HttpServletRequest request,
			 HttpServletResponse response){

		ActionErrors errors = new ActionErrors();
		AppointmentForm af = (AppointmentForm)form;
		String appointmentId = af.getAppointmentId();
		try {
			MuleClient client = new MuleClient();
			UMOMessage result = client.send("axis:http://localhost:8081/axis/services/UserManagementPM?method=deleteAppointment",appointmentId,null);
			int ok = ((Integer)result.getPayload()).intValue();
			if (ok < 0){
				log.info(this.getClass() + " : Could not delete new Appointment");
				errors.add("error inserting appointment",new ActionError("could.not.delete.appointment"));
				super.saveErrors(request,errors);
				return (new ActionForward(mapping.getInput()));
			} 
		} catch (Exception e){
			errors.add("technical Error",new ActionError("technical.error.mule"));
			super.saveErrors(request,errors);
			return (new ActionForward(mapping.getInput()));
		}
		return mapping.findForward("success");
	}
	
	
}
