gleam-spacetraders-sdk/src/spacetraders_models/shipyard_transaction.gleam

34 lines
1 KiB
Gleam

import gleam/dynamic/decode.{type Decoder}
import gleam/time/timestamp.{type Timestamp}
import spacetraders_models/agent_symbol.{type AgentSymbol}
import spacetraders_models/ship_type.{type ShipType}
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
import spacetraders_sdk/internal/time
pub type ShipyardTransaction {
ShipyardTransaction(
waypoint_symbol: WaypointSymbol,
ship_type: ShipType,
price: Int,
agent_symbol: AgentSymbol,
timestamp: Timestamp,
)
}
pub fn decoder() -> Decoder(ShipyardTransaction) {
use waypoint_symbol <- decode.field(
"waypointSymbol",
waypoint_symbol.decoder(),
)
use ship_type <- decode.field("shipType", ship_type.decoder())
use price <- decode.field("price", decode.int)
use agent_symbol <- decode.field("agentSymbol", agent_symbol.decoder())
use timestamp <- decode.field("timestamp", time.rfc3339_timestamp_decoder())
decode.success(ShipyardTransaction(
waypoint_symbol:,
ship_type:,
price:,
agent_symbol:,
timestamp:,
))
}