package com.bankaudit.rest.process.controller;

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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bankaudit.rest.process.service.RatingProcessingService;
import com.bankaudit.util.BankAuditUtil;
import com.bankaudit.util.ServiceStatus;



@RestController

@RequestMapping("/api/ratingProcessing")
public class RatingProcessingController {
	
	@Autowired
	RatingProcessingService ratingProcessingService;
	
	static final Logger logger = Logger.getLogger(RatingProcessingController.class);
	
	
@RequestMapping(value="/executeParameterRating/{legalEntityCode}/{auditId}/{auditTypeCode}/{unitId}/{userId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus executeParameterRating(@PathVariable("legalEntityCode")Integer legalEntityCode,
			@PathVariable("auditId") String auditId, 
			@PathVariable("auditTypeCode") String auditTypeCode,
			@PathVariable("unitId") String unitId,
			@PathVariable("userId") String userId){
		ServiceStatus serviceStatus=new ServiceStatus();
		if(legalEntityCode!=null && !BankAuditUtil.isEmptyString(auditId) && !BankAuditUtil.isEmptyString(auditTypeCode)
				 && !BankAuditUtil.isEmptyString(auditId) && !BankAuditUtil.isEmptyString(auditTypeCode) ){
			try {
			   Boolean execute=ratingProcessingService.executeParameterRating(legalEntityCode,auditId,auditTypeCode,unitId,userId);
			    serviceStatus.setResult(execute);
			    serviceStatus.setStatus("success");
			    serviceStatus.setMessage("successfully retrieved ");					
			} catch (Exception e) {
				e.printStackTrace();
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("failure");
			}			
		}else {
			serviceStatus.setStatus("failure");
			serviceStatus.setMessage("invalid payload ");
		}
		return serviceStatus;
	}
	
}
