gleam-spacetraders-sdk/src/models/agent.gleam
Lily Rose 64f3729d0c
Some checks are pending
test / test (push) Waiting to run
Refactoring and general tidying up
2025-06-17 19:04:29 +10:00

36 lines
1,017 B
Gleam

import gleam/dynamic/decode.{type Decoder}
import models/account_id.{type AccountId}
import models/agent_symbol.{type AgentSymbol}
import models/faction_symbol.{type FactionSymbol}
import models/waypoint_symbol.{type WaypointSymbol}
pub type Agent {
Agent(
account_id: AccountId,
symbol: AgentSymbol,
headquarters: WaypointSymbol,
credits: Int,
starting_faction: FactionSymbol,
ship_count: Int,
)
}
pub fn decoder() -> Decoder(Agent) {
use account_id <- decode.field("accountId", account_id.decoder())
use symbol <- decode.field("symbol", agent_symbol.decoder())
use headquarters <- decode.field("headquarters", waypoint_symbol.decoder())
use credits <- decode.field("credits", decode.int)
use starting_faction <- decode.field(
"startingFaction",
faction_symbol.decoder(),
)
use ship_count <- decode.field("shipCount", decode.int)
decode.success(Agent(
account_id:,
symbol:,
headquarters:,
credits:,
starting_faction:,
ship_count:,
))
}