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.ResponseBody;

import bean.AppVariables;
import common.controller.BaseController;
import dao.DelegheSepaDAO;
import dao.DisposizioneAeaDAO;
import sicura.entities.DisposizioniAea;

@Controller
@RequestMapping("deleghe")
public class DelegheRestController extends BaseController {

	@Autowired
	DisposizioneAeaDAO disposizioneAeaDAO;
	
	@RequestMapping(value="/listAea/{codiceClienteDebitore}/{start:[\\d]+}-{length:[\\d]+}")
	@ResponseBody
	private ResponseEntity<List<DisposizioniAea>> list(HttpServletRequest request, 
			@PathVariable("codiceClienteDebitore") String codiceClienteDebitore,
			@PathVariable("start") int startFrom, 
			@PathVariable("length") int length)  {
		try {
			setRequest(request);
			if(getUserData()==null)
				return new ResponseEntity<List<DisposizioniAea>>(HttpStatus.UNAUTHORIZED);
			else
				return new ResponseEntity<List<DisposizioniAea>>(disposizioneAeaDAO.list(codiceClienteDebitore, startFrom, length),HttpStatus.OK);
		} catch(Exception ex) {
			ex.printStackTrace();
			Logger.getRootLogger().error(ex);
			return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}
}
