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

34 lines
735 B
Gleam

import gleam/dynamic/decode.{type Decoder}
import gleam/json.{type Json}
pub type CrewRotation {
Strict
Relaxed
}
pub fn parse(value: String) -> Result(CrewRotation, Nil) {
case value {
"STRICT" -> Ok(Strict)
"RELAXED" -> Ok(Relaxed)
_ -> Error(Nil)
}
}
pub fn decoder() -> Decoder(CrewRotation) {
use value <- decode.then(decode.string)
case parse(value) {
Ok(crew_rotation) -> decode.success(crew_rotation)
Error(Nil) -> decode.failure(Strict, "CrewRotation")
}
}
pub fn to_string(crew_rotation: CrewRotation) -> String {
case crew_rotation {
Strict -> "STRICT"
Relaxed -> "RELAXED"
}
}
pub fn encode(crew_rotation: CrewRotation) -> Json {
json.string(to_string(crew_rotation))
}