package de.accso.flexinale.besucherportal.infrastructure;

import de.accso.flexinale.besucherportal.application.services.FKKsVTInMemoryCache;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Profile({ "!testdata-backoffice & !testdata-ticketing" })
@Endpoint(id = "besucherportalCacheContents")
public class ActuatorEndpointCache {

    private final FKKsVTInMemoryCache cache;

    public ActuatorEndpointCache(final FKKsVTInMemoryCache cache) {
        this.cache = cache;
    }

    @ReadOperation
    public List<?> cacheContents() {
        return List.of(
                    cache.filme(),
                    cache.kinos(),
                    cache.vorfuehrungen(),
                    cache.tickets()
               );
    }

    @ReadOperation
    public List<?> cacheContentsFilteredBy(@Selector String contentType) {
        return switch (contentType) {
            case "filme" -> cache.filme();
            case "kinos" -> cache.kinos();
            case "vorfuehrungen" -> cache.vorfuehrungen();
            case "tickets" -> cache.tickets();
            default -> throw new UnsupportedOperationException("type %s not supported".formatted(contentType));
        };
    }
}
