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

70 lines
1.7 KiB
Gleam

import gleam/dynamic/decode.{type Decoder}
import gleam/json.{type Json}
pub type MountDeposit {
QuartzSand
SiliconCrystals
PreciousStones
IceWater
AmmoniaIce
IronOre
CopperOre
SilverOre
AluminumOre
GoldOre
PlatinumOre
Diamonds
UraniteOre
MeritiumOre
}
pub fn parse(value: String) -> Result(MountDeposit, Nil) {
case value {
"QUARTZ_SAND" -> Ok(QuartzSand)
"SILICON_CRYSTALS" -> Ok(SiliconCrystals)
"PRECIOUS_STONES" -> Ok(PreciousStones)
"ICE_WATER" -> Ok(IceWater)
"AMMONIA_ICE" -> Ok(AmmoniaIce)
"IRON_ORE" -> Ok(IronOre)
"COPPER_ORE" -> Ok(CopperOre)
"SILVER_ORE" -> Ok(SilverOre)
"ALUMINUM_ORE" -> Ok(AluminumOre)
"GOLD_ORE" -> Ok(GoldOre)
"PLATINUM_ORE" -> Ok(PlatinumOre)
"DIAMONDS" -> Ok(Diamonds)
"URANITE_ORE" -> Ok(UraniteOre)
"MERITIUM_ORE" -> Ok(MeritiumOre)
_ -> Error(Nil)
}
}
pub fn decoder() -> Decoder(MountDeposit) {
use value <- decode.then(decode.string)
case parse(value) {
Ok(mount_deposit) -> decode.success(mount_deposit)
Error(Nil) -> decode.failure(QuartzSand, "MountDeposit")
}
}
pub fn to_string(mount_deposit: MountDeposit) -> String {
case mount_deposit {
QuartzSand -> "QUARTZ_SAND"
SiliconCrystals -> "SILICON_CRYSTALS"
PreciousStones -> "PRECIOUS_STONES"
IceWater -> "ICE_WATER"
AmmoniaIce -> "AMMONIA_ICE"
IronOre -> "IRON_ORE"
CopperOre -> "COPPER_ORE"
SilverOre -> "SILVER_ORE"
AluminumOre -> "ALUMINUM_ORE"
GoldOre -> "GOLD_ORE"
PlatinumOre -> "PLATINUM_ORE"
Diamonds -> "DIAMONDS"
UraniteOre -> "URANITE_ORE"
MeritiumOre -> "MERITIUM_ORE"
}
}
pub fn encode(mount_deposit: MountDeposit) -> Json {
json.string(to_string(mount_deposit))
}