class KubernetesCatalogWatch implements ApplicationEventPublisherAware {

	private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesCatalogWatch.class));

	private final KubernetesCatalogWatchContext context;

	private Function<KubernetesCatalogWatchContext, List<EndpointNameAndNamespace>> stateGenerator;

	private volatile List<EndpointNameAndNamespace> catalogEndpointsState = null;

	private ApplicationEventPublisher publisher;

	KubernetesCatalogWatch(CoreV1Api coreV1Api, ApiClient apiClient, KubernetesDiscoveryProperties properties,
			KubernetesNamespaceProvider namespaceProvider) {
		context = new KubernetesCatalogWatchContext(coreV1Api, apiClient, properties, namespaceProvider);
	}

	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
		this.publisher = publisher;
	}

	@Scheduled(fixedDelayString = "${" + CATALOG_WATCH_PROPERTY_WITH_DEFAULT_VALUE + "}")
	void catalogServicesWatch() {
		try {

			List<EndpointNameAndNamespace> currentState = stateGenerator.apply(context);

			if (!currentState.equals(catalogEndpointsState)) {
				LOG.debug(() -> "Received endpoints update from kubernetesClient: " + currentState);
				publisher.publishEvent(new HeartbeatEvent(this, currentState));
			}

			catalogEndpointsState = currentState;
		}
		catch (Exception e) {
			LOG.error(e, () -> "Error watching Kubernetes Services");
		}
	}

	@PostConstruct
	void postConstruct() {
		stateGenerator = stateGenerator();
	}

	Function<KubernetesCatalogWatchContext, List<EndpointNameAndNamespace>> stateGenerator() {<FILL_FUNCTION_BODY>}

}


		Function<KubernetesCatalogWatchContext, List<EndpointNameAndNamespace>> localStateGenerator;

		if (context.properties().useEndpointSlices()) {
			// this emulates : 'kubectl api-resources | grep -i EndpointSlice'
			ApiClient apiClient = context.apiClient();
			CustomObjectsApi customObjectsApi = new CustomObjectsApi(apiClient);
			try {
				List<V1APIResource> resources = customObjectsApi.getAPIResources(DISCOVERY_GROUP, DISCOVERY_VERSION)
						.getResources();
				boolean found = resources.stream().map(V1APIResource::getKind).anyMatch(ENDPOINT_SLICE::equals);
				if (!found) {
					throw new IllegalArgumentException("EndpointSlices are not supported on the cluster");
				}
				else {
					localStateGenerator = new KubernetesEndpointSlicesCatalogWatch();
				}
			}
			catch (ApiException e) {
				throw new RuntimeException(e);
			}

		}
		else {
			localStateGenerator = new KubernetesEndpointsCatalogWatch();
		}

		LOG.debug(() -> "stateGenerator is of type: " + localStateGenerator.getClass().getSimpleName());

		return localStateGenerator;
	
<no_super_class>