class ASGInventoryUtil {

	public static Map<String,List<LaunchConfiguration>> fetchLaunchConfigurations(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){
		
		AmazonAutoScaling asgClient;
		Map<String,List<LaunchConfiguration>> launchConfigurationList = new LinkedHashMap<>();
		List<String> launchConfigurationNames = new ArrayList<>();
		
		String expPrefix = "{\"errcode\": \"NO_RES_REG\" ,\"accountId\": \""+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"ASG\" , \"region\":\"" ;
		for(Region region : RegionUtils.getRegions()){ 
			try{
				if(!skipRegions.contains(region.getName())){ //!skipRegions
					List<LaunchConfiguration> launchConfigurationListTemp = new ArrayList<>();
					asgClient = AmazonAutoScalingClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
					String nextToken = null;
					DescribeAutoScalingGroupsResult  describeResult ;
					do{
						describeResult =  asgClient.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withNextToken(nextToken).withMaxRecords(asgMaxRecord));
						for(AutoScalingGroup _asg : describeResult.getAutoScalingGroups()) {
							launchConfigurationNames.add(_asg.getLaunchConfigurationName());
						}
						nextToken = describeResult.getNextToken();
					}while(nextToken!=null);
					List<String> launchConfigurationNamesTemp = new ArrayList<>();
					
					for(int i =0 ; i<launchConfigurationNames.size();i++){
						launchConfigurationNamesTemp.add(launchConfigurationNames.get(i));
						if((i+1)%50==0 || i == launchConfigurationNames.size()-1){
							launchConfigurationListTemp.addAll(asgClient.describeLaunchConfigurations(new DescribeLaunchConfigurationsRequest().withLaunchConfigurationNames(launchConfigurationNamesTemp)).getLaunchConfigurations());
							launchConfigurationNamesTemp = new ArrayList<>();
						}
						
					}
					
					if(!launchConfigurationListTemp.isEmpty() ){
						log.debug("Account : " + accountId + " Type : ASG Launch Configurations "+region.getName()+" >> " + launchConfigurationListTemp.size());
						launchConfigurationList.put(accountId+delimiter+accountName+delimiter+region.getName(), launchConfigurationListTemp);
					}
			   	}
			}catch(Exception e){
				log.warn(expPrefix+ region.getName()+"\", \"cause\":\"" +e.getMessage()+"\"}");
				ErrorManageUtil.uploadError(accountId,region.getName(),"launchconfig",e.getMessage());
			}
		}
		return launchConfigurationList;
	}

	private  ASGInventoryUtil();

}