package com.armundia.app.utilities;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import com.armundia.app.AppInfo;
import com.armundia.v2.shared.exception.ArmundiaException;
import com.armundia.v2.shared.pojo.ComboItem;

@Path("utilities")
@Produces("application/json")
public class UtilitiesRest {
	//private static final Logger log = Logger.getLogger(UtilitiesRest.class.getName());

	@Inject
	private UtilitiesManager utilitiesManager;

	@GET
	@Path("version")
	public Response version() {
		return Response.ok(new ComboItem("version", AppInfo.getVersion())).build();
	}

	@POST
	@Path("load")
	public Response getUtilities(UtilitiesPojo auPojo) {
		return Response.ok(utilitiesManager.getUtilities(auPojo)).build();
	}

	@POST
	@Path("domini")
	public Response getDomains(UtilitiesPojo auPojo, @Context HttpServletRequest request) {
		return Response.ok(utilitiesManager.getDominiFromCache(auPojo.getCodiciDomini())).build();
	}

	//FIX WEBLOGIC - should have only one HTTP method designator. It currently has the following designators defined: [@javax.ws.rs.GET(), @javax.ws.rs.POST()]
	@GET
	@Path("reloadOpzioni")
	//http://localhost:8080/f2f/rest/utilities/reloadOpzioni
	public Response reloadOpzioniGET() throws ArmundiaException {
		utilitiesManager.reloadOpzioni();
		return Response.ok(new ComboItem("esito", "OK")).build();
	}

	//FIX WEBLOGIC - should have only one HTTP method designator. It currently has the following designators defined: [@javax.ws.rs.GET(), @javax.ws.rs.POST()]
	@POST
	@Path("reloadOpzioni")
	//http://localhost:8080/f2f/rest/utilities/reloadOpzioni
	public Response reloadOpzioniPOST() throws ArmundiaException {
		utilitiesManager.reloadOpzioni();
		return Response.ok(new ComboItem("esito", "OK")).build();
	}

	//FIX WEBLOGIC - should have only one HTTP method designator. It currently has the following designators defined: [@javax.ws.rs.GET(), @javax.ws.rs.POST()]
	@GET
	@Path("reloadI18N")
	//http://localhost:8080/f2f/rest/utilities/reloadI18N
	public Response reloadI18NGET() throws ArmundiaException {
		utilitiesManager.reloadI18N();
		return Response.ok(new ComboItem("esito", "OK")).build();
	}

	@POST
	@Path("reloadI18N")
	//http://localhost:8080/f2f/rest/utilities/reloadI18N
	public Response reloadI18NPOST() throws ArmundiaException {
		utilitiesManager.reloadI18N();
		return Response.ok(new ComboItem("esito", "OK")).build();
	}

	//FIX WEBLOGIC - should have only one HTTP method designator. It currently has the following designators defined: [@javax.ws.rs.GET(), @javax.ws.rs.POST()]
	@GET
	@Path("reloadDomini")
	//http://localhost:8080/f2f/rest/utilities/reloadDomini
	public Response reloadDominiGET() throws ArmundiaException {
		utilitiesManager.reloadDomini();
		return Response.ok(new ComboItem("esito", "OK")).build();
	}

	@POST
	@Path("reloadDomini")
	//http://localhost:8080/f2f/rest/utilities/reloadDomini
	public Response reloadDominiPOST() throws ArmundiaException {
		utilitiesManager.reloadDomini();
		return Response.ok(new ComboItem("esito", "OK")).build();
	}
}
