package com.jasamedika.medifirst2000.controller;

import java.util.Map;

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.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.service.HistoryLoginModulAplikasiService;
import com.jasamedika.medifirst2000.service.HistoryLoginUserService;
import com.jasamedika.medifirst2000.util.rest.RestUtil;

/*
 * 
 *  @author Syamsu
 */
@RestController
@RequestMapping({"/test-tanpa-auth/logging", "/logging"})
public class HistoryLoggingController {

	@Autowired
	HistoryLoginUserService historyLoginUserService;
	
	@Autowired
	HistoryLoginModulAplikasiService historyLoginModulAplikasiService;
	
	@RequestMapping(value = "/get-all-history-login-on-modul", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getAllHistoryModulAplikasi(
			@RequestParam("kdUser") String kdUser){
		Map<String, Object> hasil = historyLoginModulAplikasiService.findByHistoryLoginModulAplikasi(kdUser);
		return RestUtil.getJsonResponse(hasil, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/get-page-history-login-on-modul", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getPageHistoryModulAplikasi(
			@RequestParam("kdUser") String kdUser,
			@RequestParam("page") Integer page,
			@RequestParam("limit") Integer limit,
			@RequestParam("sort") String sort,
			@RequestParam("dir") String dir){
		Map<String, Object> hasil = historyLoginModulAplikasiService.findByHistoryLoginModulAplikasi(kdUser, page, limit, sort, dir);
		return RestUtil.getJsonResponse(hasil, HttpStatus.OK);
	}
	
	
	@RequestMapping(value = "/get-all-history-login-activity", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getAllHistoryLogin(
			@RequestParam("kdHistoryLogin") Integer kdHistoryLogin){
		Map<String, Object> hasil = historyLoginUserService.findByHistoryLoginId(kdHistoryLogin);
		return RestUtil.getJsonResponse(hasil, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/get-page-history-login-activity", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getPageHistoryLogin(
			@RequestParam("kdHistoryLogin") Integer kdHistoryLogin,
			@RequestParam("page") Integer page,
			@RequestParam("limit") Integer limit,
			@RequestParam("sort") String sort,
			@RequestParam("dir") String dir){
		Map<String, Object> hasil = historyLoginUserService.findByHistoryLoginId(kdHistoryLogin, page, limit, sort, dir);
		return RestUtil.getJsonResponse(hasil, HttpStatus.OK);
	}
}
