package com.rjconsultores.ventaboletos.rest;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.rjconsultores.ventaboletos.rest.bean.ParamsSincronizarTramo;
import com.rjconsultores.ventaboletos.rest.service.SincronizarTramoService;
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;

@Path("/sincronizarTramos")
public class SincronizarTramos {
	
	private static Logger log = LogManager.getLogger(SincronizarTramos.class);
	
	@POST
	@Consumes({ MediaType.APPLICATION_JSON })
	@RolesAllowed("EMBARCADA")
	@Produces({ MediaType.APPLICATION_JSON })
	public Response buscarTramos(ParamsSincronizarTramo params) throws Exception {
		SincronizarTramoService service = (SincronizarTramoService) AppContext.getApplicationContext().getBean("sincronizarTramoService");

		try {
			return Response.ok(service.buscarListaTramosPorListCorridas(params), MediaType.APPLICATION_JSON).build();
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
		}
	}
}
