import gleam/dynamic/decode.{type Decoder} import gleam/option.{type Option} import models/ship_symbol.{type ShipSymbol} import utils/decode as decode_utils pub type Cooldown { Cooldown( ship_symbol: ShipSymbol, total_seconds: Int, remaining_seconds: Int, expiration: Option(String), ) } pub fn decoder() -> Decoder(Cooldown) { use ship_symbol <- decode.field("shipSymbol", ship_symbol.decoder()) use total_seconds <- decode.field("totalSeconds", decode.int) use remaining_seconds <- decode.field("remainingSeconds", decode.int) use expiration <- decode_utils.field_key_value_optional( "expiration", decode.string, ) decode.success(Cooldown( ship_symbol:, total_seconds:, remaining_seconds:, expiration:, )) }