package com.jasamedika.medifirst2000.controller;

import com.jasamedika.medifirst2000.entities.HistoryLoginModulAplikasi;
import com.jasamedika.medifirst2000.entities.HistoryLoginUser;
import com.jasamedika.medifirst2000.service.HistoryLoginModulAplikasiService;
import com.jasamedika.medifirst2000.service.HistoryLoginUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

/*
 * 
 *  @author Syamsu
 */
@RestController
@RequestMapping("/logging")
public class HistoryLoggingController {

	@Autowired
	HistoryLoginUserService<HistoryLoginUser> historyLoginUserService;

	@Autowired
	HistoryLoginModulAplikasiService<HistoryLoginModulAplikasi> historyLoginModulAplikasiService;

	@RequestMapping(value = "/get-all-history-login-on-modul", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getAllHistoryModulAplikasi(@RequestParam("kdUser") String kdUser) {
		Map<String, Object> hasil = historyLoginModulAplikasiService.findByHistoryLoginModulAplikasi(kdUser);
		return getJsonResponse(hasil, OK);
	}

	@RequestMapping(value = "/get-all-history-login-activity", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getAllHistoryLogin(
			@RequestParam("kdHistoryLogin") Integer kdHistoryLogin) {
		Map<String, Object> hasil = historyLoginUserService.findByHistoryLoginId(kdHistoryLogin);
		return getJsonResponse(hasil, OK);
	}

}
