package com.jasamedika.medifirst2000.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jasamedika.medifirst2000.constants.Constants;
import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.core.web.WebConstants;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.StrukBuktiPengeluaranService;
import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.jasamedika.medifirst2000.vo.StrukPengeluaranVO;

@RestController
@RequestMapping("/struk-pengeluaran")
public class StrukBuktiPengeluaranController extends LocaleController<StrukPengeluaranVO> {
	
	@Autowired 
	private StrukBuktiPengeluaranService strukBuktiPengeluaranService;
	
	@RequestMapping(value = "/pengeluaran-umum", method = RequestMethod.POST, 
			consumes = MediaType.APPLICATION_JSON_VALUE, 
			produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> simpanPengeluaranUmum(@RequestBody StrukPengeluaranVO vo,
			HttpServletRequest request) {
		try {
			Map<String, Object> result = strukBuktiPengeluaranService.simpanPengeluaranUmum(vo);
			if (result != null) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			}
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
		} catch(ServiceVOException se) {
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, se.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch(JpaSystemException jse) {
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT);
		}
	}
	
	@RequestMapping(value = "/get-struk-bukti-pengeluaran", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public List<Map<String, Object>> getDaftarTagihanRekananVerifikasi(			
			@RequestParam(value = "startDate", required = false) String startDate,
			@RequestParam(value = "endDate", required = false) String endDate,
			@RequestParam(value = "ketLain", required = false) String ketLain,
			@RequestParam(value = "idPegawai", required = false) Integer idPegawai,
			@RequestParam(value = "noSBK", required = false) String noSBK,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String, Object>> resultPageMap = strukBuktiPengeluaranService.getStrukBuktiPengeluaran(startDate,endDate, ketLain, idPegawai, noSBK, idRuangan);

		return resultPageMap;
	}
	
//	@RequestMapping(value = "/pengeluaran-umum", method = RequestMethod.GET,
//			produces = MediaType.APPLICATION_JSON_VALUE)
//	public @ResponseBody Map<String, Object> getPengeluaranUmum(@RequestParam("norec") String norec) {
//		return strukBuktiPengeluaranService.ambilPengeluaranUmum(norec);
//	}
	
}
