namespace NATS.Server.Auth.Jwt;

internal static class JwtConnectionTypes
{
    public const string Standard = "STANDARD";
    public const string Websocket = "WEBSOCKET";
    public const string Leafnode = "LEAFNODE";
    public const string LeafnodeWs = "LEAFNODE_WS";
    public const string Mqtt = "MQTT";
    public const string MqttWs = "MQTT_WS";
    public const string InProcess = "INPROCESS";

    private static readonly HashSet<string> Known =
    [
        Standard, Websocket, Leafnode, LeafnodeWs, Mqtt, MqttWs, InProcess,
    ];

    public static (HashSet<string> Valid, bool HasUnknown) Convert(IEnumerable<string>? values)
    {
        var valid = new HashSet<string>(StringComparer.Ordinal);
        var hasUnknown = false;
        if (values is null) return (valid, false);

        foreach (var raw in values)
        {
            var up = (raw ?? string.Empty).Trim().ToUpperInvariant();
            if (up.Length == 0) continue;
            if (Known.Contains(up)) valid.Add(up);
            else hasUnknown = true;
        }

        return (valid, hasUnknown);
    }
}
