// Path: spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/support/ZoneUtils.java
// public final class ZoneUtils {
// 
// 	private ZoneUtils() {
// 		throw new AssertionError("Must not instantiate utility class.");
// 	}
// 
// 	/**
// 	 * Approximates Eureka zones from a host name. This method approximates the zone to be
// 	 * everything after the first "." in the host name.
// 	 * @param host The host name to extract the host name from
// 	 * @return The approximate zone
// 	 */
// 	public static String extractApproximateZone(String host) {
// 		String[] split = StringUtils.split(host, ".");
// 		return split == null ? host : split[1];
// 	}
// 
// }
// 
// Path: spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/LoadBalancerEurekaAutoConfiguration.java
// public static final String LOADBALANCER_ZONE = "spring.cloud.loadbalancer.zone";


import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.EurekaClientConfig;
import jakarta.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cloud.loadbalancer.config.LoadBalancerZoneConfig;
import org.springframework.cloud.netflix.eureka.support.ZoneUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration.LOADBALANCER_ZONE;

	private final EurekaLoadBalancerProperties eurekaLoadBalancerProperties;

	public EurekaLoadBalancerClientConfiguration(@Autowired(required = false) EurekaClientConfig clientConfig,
			@Autowired(required = false) EurekaInstanceConfig eurekaInstanceConfig, LoadBalancerZoneConfig zoneConfig,
			EurekaLoadBalancerProperties eurekaLoadBalancerProperties) {
		this.clientConfig = clientConfig;
		this.eurekaConfig = eurekaInstanceConfig;
		this.zoneConfig = zoneConfig;
		this.eurekaLoadBalancerProperties = eurekaLoadBalancerProperties;
	}

	@PostConstruct
	public void postprocess() {
		if (!StringUtils.isEmpty(zoneConfig.getZone())) {
			return;
		}
		String zone = getZoneFromEureka();
		if (!StringUtils.isEmpty(zone)) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("Setting the value of '" + LOADBALANCER_ZONE + "' to " + zone);
			}
			zoneConfig.setZone(zone);
		}
	}

	private String getZoneFromEureka() {
		String zone;
		boolean approximateZoneFromHostname = eurekaLoadBalancerProperties.isApproximateZoneFromHostname();
		if (approximateZoneFromHostname && eurekaConfig != null) {
// Path: spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/support/ZoneUtils.java
// public final class ZoneUtils {
// 
// 	private ZoneUtils() {
// 		throw new AssertionError("Must not instantiate utility class.");
// 	}
// 
// 	/**
// 	 * Approximates Eureka zones from a host name. This method approximates the zone to be
// 	 * everything after the first "." in the host name.
// 	 * @param host The host name to extract the host name from
// 	 * @return The approximate zone
// 	 */
// 	public static String extractApproximateZone(String host) {
// 		String[] split = StringUtils.split(host, ".");
// 		return split == null ? host : split[1];
// 	}
// 
// }
// 
// Path: spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/LoadBalancerEurekaAutoConfiguration.java
// public static final String LOADBALANCER_ZONE = "spring.cloud.loadbalancer.zone";


// Path: spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfiguration.java
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.EurekaClientConfig;
import jakarta.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cloud.loadbalancer.config.LoadBalancerZoneConfig;
import org.springframework.cloud.netflix.eureka.support.ZoneUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration.LOADBALANCER_ZONE;


	private final EurekaLoadBalancerProperties eurekaLoadBalancerProperties;

	public EurekaLoadBalancerClientConfiguration(@Autowired(required = false) EurekaClientConfig clientConfig,
			@Autowired(required = false) EurekaInstanceConfig eurekaInstanceConfig, LoadBalancerZoneConfig zoneConfig,
			EurekaLoadBalancerProperties eurekaLoadBalancerProperties) {
		this.clientConfig = clientConfig;
		this.eurekaConfig = eurekaInstanceConfig;
		this.zoneConfig = zoneConfig;
		this.eurekaLoadBalancerProperties = eurekaLoadBalancerProperties;
	}

	@PostConstruct
	public void postprocess() {
		if (!StringUtils.isEmpty(zoneConfig.getZone())) {
			return;
		}
		String zone = getZoneFromEureka();
		if (!StringUtils.isEmpty(zone)) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("Setting the value of '" + LOADBALANCER_ZONE + "' to " + zone);
			}
			zoneConfig.setZone(zone);
		}
	}

	private String getZoneFromEureka() {
		String zone;
		boolean approximateZoneFromHostname = eurekaLoadBalancerProperties.isApproximateZoneFromHostname();
		if (approximateZoneFromHostname && eurekaConfig != null) {
			return ZoneUtils.extractApproximateZone(this.eurekaConfig.getHostName(false));