// Path: spring-cloud-cloudfoundry-commons/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryService.java
// public class CloudFoundryService {
// 
// 	private final CloudFoundryOperations cloudFoundryOperations;
// 
// 	public CloudFoundryService(CloudFoundryOperations cloudFoundryOperations) {
// 		this.cloudFoundryOperations = cloudFoundryOperations;
// 	}
// 
// 	public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(String serviceId) {
// 		GetApplicationRequest applicationRequest = GetApplicationRequest.builder().name(serviceId).build();
// 		return this.cloudFoundryOperations.applications().get(applicationRequest).flatMapMany(applicationDetail -> {
// 			Flux<InstanceDetail> ids = Flux.fromStream(applicationDetail.getInstanceDetails().stream())
// 					.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
// 			Flux<ApplicationDetail> generate = Flux.generate(sink -> sink.next(applicationDetail));
// 			return generate.zipWith(ids);
// 		});
// 	}
// 
// }
// 
// Path: spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/SimpleDnsBasedDiscoveryClient.java
// @FunctionalInterface
// public interface ServiceIdToHostnameConverter {
// 
// 	String toHostname(String serviceId);
// 
// }


import org.springframework.context.annotation.Configuration;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
import org.springframework.cloud.cloudfoundry.discovery.SimpleDnsBasedDiscoveryClient.ServiceIdToHostnameConverter;
import org.springframework.context.annotation.Bean;
	public static class CloudFoundryDiscoveryClientConfig {

		@Bean
		@ConditionalOnMissingBean(DiscoveryClient.class)
		public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf,
				CloudFoundryService svc, CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
			return new CloudFoundryDiscoveryClient(cf, svc, cloudFoundryDiscoveryProperties);
		}

	}

	@Configuration(proxyBeanMethods = false)
	@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", havingValue = "true")
	public static class DnsBasedCloudFoundryDiscoveryClientConfig {

		@Bean
		@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "true")
		@ConditionalOnMissingBean(DiscoveryClient.class)
		public SimpleDnsBasedDiscoveryClient discoveryClient(ObjectProvider<ServiceIdToHostnameConverter> provider,
				CloudFoundryDiscoveryProperties properties) {
			ServiceIdToHostnameConverter converter = provider.getIfAvailable();
			return converter == null ? new SimpleDnsBasedDiscoveryClient(properties)
					: new SimpleDnsBasedDiscoveryClient(properties, converter);
		}

		@Bean
		@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "false",
				matchIfMissing = true)
		@ConditionalOnMissingBean(DiscoveryClient.class)
		public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf,
// Path: spring-cloud-cloudfoundry-commons/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryService.java
// public class CloudFoundryService {
// 
// 	private final CloudFoundryOperations cloudFoundryOperations;
// 
// 	public CloudFoundryService(CloudFoundryOperations cloudFoundryOperations) {
// 		this.cloudFoundryOperations = cloudFoundryOperations;
// 	}
// 
// 	public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(String serviceId) {
// 		GetApplicationRequest applicationRequest = GetApplicationRequest.builder().name(serviceId).build();
// 		return this.cloudFoundryOperations.applications().get(applicationRequest).flatMapMany(applicationDetail -> {
// 			Flux<InstanceDetail> ids = Flux.fromStream(applicationDetail.getInstanceDetails().stream())
// 					.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
// 			Flux<ApplicationDetail> generate = Flux.generate(sink -> sink.next(applicationDetail));
// 			return generate.zipWith(ids);
// 		});
// 	}
// 
// }
// 
// Path: spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/SimpleDnsBasedDiscoveryClient.java
// @FunctionalInterface
// public interface ServiceIdToHostnameConverter {
// 
// 	String toHostname(String serviceId);
// 
// }


// Path: spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java
import org.springframework.context.annotation.Configuration;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
import org.springframework.cloud.cloudfoundry.discovery.SimpleDnsBasedDiscoveryClient.ServiceIdToHostnameConverter;
import org.springframework.context.annotation.Bean;

	public static class CloudFoundryDiscoveryClientConfig {

		@Bean
		@ConditionalOnMissingBean(DiscoveryClient.class)
		public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf,
				CloudFoundryService svc, CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
			return new CloudFoundryDiscoveryClient(cf, svc, cloudFoundryDiscoveryProperties);
		}

	}

	@Configuration(proxyBeanMethods = false)
	@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", havingValue = "true")
	public static class DnsBasedCloudFoundryDiscoveryClientConfig {

		@Bean
		@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "true")
		@ConditionalOnMissingBean(DiscoveryClient.class)
		public SimpleDnsBasedDiscoveryClient discoveryClient(ObjectProvider<ServiceIdToHostnameConverter> provider,
				CloudFoundryDiscoveryProperties properties) {
			ServiceIdToHostnameConverter converter = provider.getIfAvailable();
			return converter == null ? new SimpleDnsBasedDiscoveryClient(properties)
					: new SimpleDnsBasedDiscoveryClient(properties, converter);
		}

		@Bean
		@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "false",
				matchIfMissing = true)
		@ConditionalOnMissingBean(DiscoveryClient.class)
		public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf,
				CloudFoundryService svc, CloudFoundryDiscoveryProperties properties) {