using System.Collections.Generic;
using System.Text.Json;
using System;

namespace Ablera.Serdica.Authority.Extensions;

public static class ImmutableDictionaryExtensions
{
    public static string GetStringOrThrow(this IDictionary<string, JsonElement> dict, string key, string clientId)
    {
        dict.TryGetValue(key, out var jsonElement);
        var s = jsonElement.GetString();
        if (string.IsNullOrWhiteSpace(s))
        {
            throw new InvalidOperationException($"No {key} property is defined for client with id '{clientId}'.");
        }
        return s;
    }
}
