import gleam/dynamic/decode.{type Decoder} import gleam/json.{type Json} import gleam/string pub opaque type ShipyardSymbol { ShipyardSymbol(String) } pub const min_length: Int = 1 pub fn parse(value: String) -> Result(ShipyardSymbol, Nil) { case string.length(value) >= min_length { True -> Ok(ShipyardSymbol(value)) False -> Error(Nil) } } pub fn decoder() -> Decoder(ShipyardSymbol) { use value <- decode.then(decode.string) case parse(value) { Ok(shipyard_symbol) -> decode.success(shipyard_symbol) Error(Nil) -> decode.failure(ShipyardSymbol("invalid"), "ShipyardSymbol") } } pub fn to_string(shipyard_symbol: ShipyardSymbol) -> String { let ShipyardSymbol(symbol) = shipyard_symbol symbol } pub fn encode(shipyard_symbol: ShipyardSymbol) -> Json { json.string(to_string(shipyard_symbol)) }