package com.lingniu.ingest.gb32960app.actuator;

import com.lingniu.ingest.protocol.gb32960.inbound.Gb32960ConnectionDiagnostics;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Endpoint(id = "gb32960sessions")
public class Gb32960SessionsEndpoint {

    private final Gb32960ConnectionDiagnostics diagnostics;

    public Gb32960SessionsEndpoint(Gb32960ConnectionDiagnostics diagnostics) {
        this.diagnostics = diagnostics;
    }

    @ReadOperation
    public Map<String, Object> sessions() {
        var sessions = diagnostics.activeSessions();
        return Map.of(
                "activeCount", sessions.size(),
                "sessions", sessions);
    }
}
