gleam-spacetraders-sdk/src/models/ship_nav_flight_mode.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

40 lines
909 B
Gleam

import gleam/dynamic/decode.{type Decoder}
import gleam/json.{type Json}
pub type ShipNavFlightMode {
Drift
Stealth
Cruise
Burn
}
pub fn parse(value: String) -> Result(ShipNavFlightMode, Nil) {
case value {
"DRIFT" -> Ok(Drift)
"STEALTH" -> Ok(Stealth)
"CRUISE" -> Ok(Cruise)
"BURN" -> Ok(Burn)
_ -> Error(Nil)
}
}
pub fn decoder() -> Decoder(ShipNavFlightMode) {
use value <- decode.then(decode.string)
case parse(value) {
Ok(ship_nav_flight_mode) -> decode.success(ship_nav_flight_mode)
Error(Nil) -> decode.failure(Drift, "ShipNavFlightMode")
}
}
pub fn to_string(ship_nav_flight_mode: ShipNavFlightMode) -> String {
case ship_nav_flight_mode {
Drift -> "DRIFT"
Stealth -> "STEALTH"
Cruise -> "CRUISE"
Burn -> "BURN"
}
}
pub fn encode(ship_nav_flight_mode: ShipNavFlightMode) -> Json {
json.string(to_string(ship_nav_flight_mode))
}