package controller.rest;

import java.util.List;

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

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import bean.BeanSelect;
import common.controller.BaseController;
import dao.GenericComboDAO;

@Controller
@RequestMapping("combo")
public class ComboRestController extends BaseController {

	@Autowired
	GenericComboDAO genericComboDAO;
	

	@RequestMapping(value="/FacoltaStorno/{tipologia}", method=RequestMethod.GET)
	@ResponseBody
	private ResponseEntity<List<BeanSelect>> getFacoltaStorno(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
		try {
			setRequest(request);
			if (getUserData()==null)
				return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
			return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "FacoltàStorno"), HttpStatus.OK);
		} catch(Exception ex) {
			ex.printStackTrace();
			Logger.getRootLogger().error(ex);
			return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}

	@RequestMapping(value="/FacoltaStornoEsito/{tipologia}", method=RequestMethod.GET)
	@ResponseBody
	private ResponseEntity<List<BeanSelect>> getFacoltaStornoEsito(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
		try {
			setRequest(request);
			if (getUserData()==null)
				return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
			return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "FacoltàStornoEsito"), HttpStatus.OK);
		} catch(Exception ex) {
			ex.printStackTrace();
			Logger.getRootLogger().error(ex);
			return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}
	
	@RequestMapping(value="/{campo}/{tipologia}", method=RequestMethod.GET)
	@ResponseBody
	private ResponseEntity<List<BeanSelect>> getGenerico(HttpServletRequest request, @PathVariable("campo") String campo, @PathVariable("tipologia") String tipologia){
		try {
			setRequest(request);
			if (getUserData()==null)
				return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
			return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, campo), HttpStatus.OK);
		} catch(Exception ex) {
			ex.printStackTrace();
			Logger.getRootLogger().error(ex);
			return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}
	

	@RequestMapping(value="/CodiceStornoSEPA/{tipologia}/count", method=RequestMethod.GET)
	@ResponseBody
	private ResponseEntity<Integer> getCodiceStornoSEPACount(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
		try {
			setRequest(request);
			if (getUserData()==null)
				return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
			return new ResponseEntity<Integer>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "CodiceStornoSEPA").size(), HttpStatus.OK);
		} catch(Exception ex) {
			ex.printStackTrace();
			Logger.getRootLogger().error(ex);
			return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}
	
	@RequestMapping(value="/causaliEsiti", method=RequestMethod.GET)
	@ResponseBody
	private ResponseEntity<Object> getCausalieEsiti(HttpServletRequest request){
		try{
			setRequest(request);
			if (getUserData()==null)
				return new ResponseEntity<Object>(null, HttpStatus.UNAUTHORIZED);
			return new ResponseEntity<Object>(genericComboDAO.getCausaliEsiti(), HttpStatus.OK);
		} catch(Exception ex) {
			ex.printStackTrace();
			Logger.getRootLogger().error(ex);
			return new ResponseEntity<Object>(null, HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}
	
	
		
//	@RequestMapping(value="/Esiti/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getEsitiRid(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "Esito"), HttpStatus.OK);
//	}
//	
//	@RequestMapping(value="/TipoSequenza/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getTipoSequenza(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "TipoSequenza"), HttpStatus.OK);
//	}
//	
//	@RequestMapping(value="/TipoIncasso/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getTipoIncassoRid(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "Tipo_Incasso_Rid"), HttpStatus.OK);
//	}
//
//	@RequestMapping(value="/TipoCodice/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getTipoCodice(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "TipoCodice"), HttpStatus.OK);
//	}
//

	
//	@RequestMapping(value="/StatoAllineamento/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getStatoAllineamento(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "StatoAllineamento"), HttpStatus.OK);
//	}
//

//
//	@RequestMapping(value="/CausaleStorno/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getCausaleStorno(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "CausaleStorno"), HttpStatus.OK);
//	}
//
//	@RequestMapping(value="/CodiceStornoCBI/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getCodiceStornoCBI(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "CodiceStornoCBI"), HttpStatus.OK);
//	}
//
//	@RequestMapping(value="/CodiceStornoSEPA/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getCodiceStornoSEPA(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "CodiceStornoSEPA"), HttpStatus.OK);
//	}
//
//	@RequestMapping(value="/Causale/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getCausale(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "Causale"), HttpStatus.OK);
//	}
//
//	@RequestMapping(value="/ClassificazioneConto/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getClassificazioneConto(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "ClassificazioneConto"), HttpStatus.OK);
//	}
//
//	@RequestMapping(value="/TipoMandato/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getTipoMandato(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "TipoMandato"), HttpStatus.OK);
//	}
//
//	@RequestMapping(value="/EsitoSepaRsnCode/{tipologia}", method=RequestMethod.GET)
//	@ResponseBody
//	private ResponseEntity<List<BeanSelect>> getEsitoSepaRsnCode(HttpServletRequest request, @PathVariable("tipologia") String tipologia){
//		setRequest(request);
//		if (getUserData()==null)
//			return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
//		return new ResponseEntity<List<BeanSelect>>(genericComboDAO.getComboValues("Combo_Disposizioni", tipologia, "EsitoSepaRsnCode"), HttpStatus.OK);
//	}
//			
}
