
package com.bankaudit.rest.controller;

import java.util.List;

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.MaintZoneMappingDto;
import com.bankaudit.model.ActivityProcessFindingMapping;
import com.bankaudit.service.MaintZoneMappingService;
import com.bankaudit.util.ServiceStatus;


/**
 * The Class {@link MaintZoneMappingController} provides the REST
 * services to manage the {@link ActivityProcessFindingMapping} class objects .
 *
 * @author amit.patel
 * @version 1.0
 */


@RestController

@RequestMapping("/api/zone")
public class MaintZoneMappingController { 
	
	@Autowired
	MaintZoneMappingService maintZoneMappingService;	
	
	/** The Constant logger is used to specify the log messages in log file . */
	static final Logger logger = Logger.getLogger(MaintZoneMappingController.class);
	 
	
@RequestMapping(value = "/getZoneByLegalEntityCode", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getZoneByLegalEntityCode(		 
			@RequestParam("legalEntityCode")Integer legalEntityCode,
			@RequestParam("userId")String userId){

		ServiceStatus serviceStatus=new ServiceStatus();		
		List<MaintZoneMappingDto> listData=null;
			try {  	
				listData = maintZoneMappingService.getZoneByLegalEntityCode(legalEntityCode, userId);		 
				if(listData!=null && !listData.isEmpty()){
					serviceStatus.setResult(listData);
					serviceStatus.setStatus("success");
					serviceStatus.setMessage("successfully got the result ");					
				}else {
					serviceStatus.setStatus("failure");
					serviceStatus.setMessage("No Data found ");
				}
			} catch (Exception e) {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("No Data found "); 
				logger.error(e.getStackTrace());
				
			}
		return serviceStatus;
	}
	
	
	
@RequestMapping(value = "/getRegionalOfficeByLegalEntityCode", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	ServiceStatus getRegionalOfficeByLegalEntityCode(	
			@RequestParam("legalEntityCode")Integer legalEntityCode,
			@RequestParam("userId")String userId){

		ServiceStatus serviceStatus=new ServiceStatus();		
		List<MaintZoneMappingDto> listData=null; 
		try {
			listData = maintZoneMappingService.getRegionalOfficeOfAllZones(legalEntityCode, userId);		
			if(listData!=null && !listData.isEmpty()){
				serviceStatus.setResult(listData);
				serviceStatus.setStatus("success");
				serviceStatus.setMessage("successfully got the result ");					
			}else {
				serviceStatus.setStatus("failure");
				serviceStatus.setMessage("No Data found ");
			}
		} catch (Exception e) {
			serviceStatus.setStatus("failure");
			serviceStatus.setMessage("No Data found "); 
			logger.error(e.getStackTrace());
		}		 

		return serviceStatus;
	}	 
	
}
