class InventoryUtil {

	public static Map<String,List<EbsVH>> fetchEBSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) {

		Map<String,List<EbsVH>> ebs = new LinkedHashMap<>();

		String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"beanstalk\" , \"region\":\"" ;
		for(Region region : RegionUtils.getRegions()) {
			try{
				if(!skipRegions.contains(region.getName())){
					AWSElasticBeanstalk awsElasticBeanstalk  = AWSElasticBeanstalkClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
					List<ApplicationDescription> appDesList = awsElasticBeanstalk.describeApplications().getApplications();
					List<EbsVH> ebsList = new ArrayList<>();
					for(ApplicationDescription appDes : appDesList) {
						List<EnvironmentDescription> envDesList = awsElasticBeanstalk.describeEnvironments(new DescribeEnvironmentsRequest().withApplicationName(appDes.getApplicationName())).getEnvironments();
						if(envDesList.isEmpty()) {
							EbsVH ebsObj = new EbsVH();
							ebsObj.setApp(appDes);
							ebsList.add(ebsObj);
						}
						else {
							for(EnvironmentDescription envDes : envDesList) {
								EbsVH ebsObj = new EbsVH();
								ebsObj.setApp(appDes);
								ebsObj.setEnv(envDes);
								try{
								    ebsObj.setEnvResource(awsElasticBeanstalk.describeEnvironmentResources(new DescribeEnvironmentResourcesRequest().withEnvironmentId(envDes.getEnvironmentId())).getEnvironmentResources());
								}catch(Exception e){
								    log.debug("Error in fetching resources for enviroment",e);
								}
								ebsList.add(ebsObj);
							}
						}
					}
					if( !ebsList.isEmpty() ) {
						log.debug(InventoryConstants.ACCOUNT + accountId +" Type : beanstalk "+region.getName() + " >> "+ebsList.size());
						ebs.put(accountId+delimiter+accountName+delimiter+region.getName(),ebsList);
					}
				}
			}catch(Exception e){
				log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
				ErrorManageUtil.uploadError(accountId,region.getName(),"beanstalk",e.getMessage());
			}
		}
		return ebs;
	}

	private  InventoryUtil();

}