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

43 lines
1.1 KiB
Gleam

import gleam/dynamic/decode.{type Decoder}
import gleam/json.{type Json}
pub type WaypointModifierSymbol {
Stripped
Unstable
RadiationLeak
CriticalLimit
CivilUnrest
}
pub fn parse(value: String) -> Result(WaypointModifierSymbol, Nil) {
case value {
"STRIPPED" -> Ok(Stripped)
"UNSTABLE" -> Ok(Unstable)
"RADIATION_LEAK" -> Ok(RadiationLeak)
"CRITICAL_LIMIT" -> Ok(CriticalLimit)
"CIVIL_UNREST" -> Ok(CivilUnrest)
_ -> Error(Nil)
}
}
pub fn decoder() -> Decoder(WaypointModifierSymbol) {
use value <- decode.then(decode.string)
case parse(value) {
Ok(waypoint_modifier_symbol) -> decode.success(waypoint_modifier_symbol)
Error(Nil) -> decode.failure(Stripped, "WaypointModifierSymbol")
}
}
pub fn to_string(waypoint_modifier_symbol: WaypointModifierSymbol) -> String {
case waypoint_modifier_symbol {
Stripped -> "STRIPPED"
Unstable -> "UNSTABLE"
RadiationLeak -> "RADIATION_LEAK"
CriticalLimit -> "CRITICAL_LIMIT"
CivilUnrest -> "CIVIL_UNREST"
}
}
pub fn encode(waypoint_modifier_symbol: WaypointModifierSymbol) -> Json {
json.string(to_string(waypoint_modifier_symbol))
}