Extension methods for enums that return API-friendly string names. It maps specific enum types (Gamemode, ChessVariant, ChallengeDeniedReason) to Lichess API names via LichessEnumNames.ToApiName, and falls back to a lowercase ToString for other enums.
#nullable enable annotations
using LichessNET.Entities.Enumerations;
using LichessNET.Internal;
namespace LichessNET.Extensions;
internal static class EnumExtensions
{
public static string ToApiName<T>(this T value) where T : Enum
{
return GetApiName(value);
}
public static string GetApiName<T>(this T enumValue) where T : Enum
{
return enumValue switch
{
Gamemode value => LichessEnumNames.ToApiName(value),
ChessVariant value => LichessEnumNames.ToApiName(value),
ChallengeDeniedReason value => LichessEnumNames.ToApiName(value),
_ => enumValue.ToString().ToLowerInvariant()
};
}
}