package com.bankaudit.rest.process.controller;


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

import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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.bankaudit.dto.DataTableResponse;
import com.bankaudit.dto.process.AlertsDto;
import com.bankaudit.dto.process.AlertsResponseDto;
import com.bankaudit.process.model.AuditSchedule;
import com.bankaudit.process.model.AuditScheduleStagesStatusHst;
import com.bankaudit.process.model.TaskDetails;
import com.bankaudit.rest.process.service.AlertToDoService;
import com.bankaudit.rest.process.service.AuditLogService;
import com.bankaudit.util.BankAuditUtil;
import com.bankaudit.util.ServiceStatus;



@RestController

@RequestMapping("/api/auditLog")
public class AuditLogController {
	
	@Autowired
	AuditLogService auditLogService;
	
	static final Logger logger = Logger.getLogger(AuditLogController.class);
	
	
@RequestMapping(value="/getAuditLogByProcess",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getAuditLogByProcess(
			@RequestParam("legalEntityCode") Integer legalEntityCode,
			@RequestParam(value="auditId",required=true) String auditId,
			@RequestParam(value="userId",required=true) String userId,
			@RequestParam(value="role",required=false) String role,
			@RequestParam(value="process",required=false) String process,
			@RequestParam(value="code",required=false) String code){
		ServiceStatus serviceStatus=new ServiceStatus();
		
		if(legalEntityCode!=null && !BankAuditUtil.isEmptyString(userId) ){
			logger.info("Inside getAuditLogByProcess legalEntityCode.."+legalEntityCode+" userId.."+userId+" role.."+role+" process.. "+process);
			try {
				List<AuditScheduleStagesStatusHst> stgHstLst= auditLogService.getAuditLogByProcess(legalEntityCode, auditId, userId, role, process, code); 
				
				if(stgHstLst!=null){
					serviceStatus.setResult(stgHstLst);
					serviceStatus.setStatus("success");
					serviceStatus.setMessage("successfuly retrieved ");
				}else {
					serviceStatus.setStatus("failure");
					serviceStatus.setMessage("ids not found");
				}
				
			} catch (Exception e) {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("failure");
				e.printStackTrace();
			}
			
		}else {
			serviceStatus.setStatus("failure");
			serviceStatus.setMessage("invalid parameter");
		}
				return serviceStatus;
	}	
	
}
