public record Pokemon(
[property: JsonPropertyName("abilities")] IReadOnlyList Abilities,
[property: JsonPropertyName("base_experience")] long BaseExperience,
[property: JsonPropertyName("forms")] IReadOnlyList Forms,
[property: JsonPropertyName("game_indices")] IReadOnlyList GameIndices,
[property: JsonPropertyName("height")] long Height,
[property: JsonPropertyName("held_items")] IReadOnlyList
public static BaseStats GetBaseStats(Pokemon pokemon)
{
ArgumentNullException.ThrowIfNull(pokemon);
if (pokemon.Stats is null || pokemon.Stats.Count == 0)
throw new InvalidOperationException("There are no valid stat entries");
Dictionary dict = pokemon.Stats.ToDictionary(s => s.StatValue.Name, s => (int)s.BaseStat, StringComparer.OrdinalIgnoreCase);
int Get(string key) => dict.TryGetValue(key, out var v) ? v : throw new KeyNotFoundException($"stat entry '{key}' in '{pokemon.Name}' was not found.");
return new BaseStats(
HP: Get("hp"),
Attack: Get("attack"),
Defense: Get("defense"),
SpAttack: Get("special-attack"),
SpDefense: Get("special-defense"),
Speed: Get("speed")
);
}