package com.bankaudit.rest.process.controller;

import java.sql.Timestamp;
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.PathVariable;
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 org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.bankaudit.constants.BankAuditConstant;
import com.bankaudit.dto.DataTableResponse;
import com.bankaudit.dto.process.AuditReportDynamicTableDto;
import com.bankaudit.process.model.AuditLevelDocumentDetails;
import com.bankaudit.process.model.AuditSchedule;
import com.bankaudit.process.model.IfcEnsureBaasData;
import com.bankaudit.process.model.IfcRatingData;
import com.bankaudit.process.model.RiskSummaryDtls;
import com.bankaudit.rest.process.service.InterfaceParameterService;
import com.bankaudit.util.BankAuditUtil;
import com.bankaudit.util.ServiceStatus;



@RestController

@RequestMapping("/api/interfaceParameter")
public class InterfaceParameterController {
	
	@Autowired
	InterfaceParameterService interfaceParameterService;
	
	static final Logger logger = Logger.getLogger(InterfaceParameterController.class);
 
	
@RequestMapping(value="/getLatestParametersByAuditId/{legalEntityCode}/{auditId}/{unitId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getLatestParametersByAuditId(
			@PathVariable("legalEntityCode") Integer legalEntityCode,
			@PathVariable("auditId") String auditId,
			@PathVariable("unitId") String unitId){
		ServiceStatus serviceStatus=new ServiceStatus();
		
		if(legalEntityCode!=null && !BankAuditUtil.isEmptyString(auditId) ){
			try {
				List<IfcEnsureBaasData> ifcBaasDataLst=interfaceParameterService.getLatestParametersByAuditId(legalEntityCode,auditId, unitId); 
				if(ifcBaasDataLst!=null){
					serviceStatus.setResult(ifcBaasDataLst);
					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;
	}
	
	
@RequestMapping(value="/getProfileDetailsByAuditId/{legalEntityCode}/{auditId}/{unitId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getProfileDetailsByAuditId(
			@PathVariable("legalEntityCode") Integer legalEntityCode,
			@PathVariable("auditId") String auditId,
			@PathVariable("unitId") String unitId){
		ServiceStatus serviceStatus=new ServiceStatus();
		
		if(legalEntityCode!=null && !BankAuditUtil.isEmptyString(auditId) ){
			try {
				Map<String, String> ifcProfileMap=interfaceParameterService.getProfileDetailsByAuditId(legalEntityCode,auditId, unitId); 
				if(ifcProfileMap!=null){
					serviceStatus.setResult(ifcProfileMap);
					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;
	}
		
	/******************** ******************************/
	
@RequestMapping(value="/getInputValuesByAuditId/{legalEntityCode}/{auditId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getInputValuesByAuditId(
			@PathVariable("legalEntityCode") Integer legalEntityCode,
			@PathVariable("auditId") String auditId){
		ServiceStatus serviceStatus=new ServiceStatus();
		
		if(legalEntityCode!=null && !BankAuditUtil.isEmptyString(auditId) ){
			try {
				List<IfcRatingData> ifcRatingDataLst=interfaceParameterService.getInputValuesByAuditId(legalEntityCode,auditId); 
				if(ifcRatingDataLst!=null){
					serviceStatus.setResult(ifcRatingDataLst);
					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;
	}
	 
}
