import gleam/dynamic/decode.{type Decoder} import gleam/option.{type Option} import models/constellation.{type Constellation} import models/sector_symbol.{type SectorSymbol} import models/system_faction.{type SystemFaction} import models/system_symbol.{type SystemSymbol} import models/system_type.{type SystemType} import models/system_waypoint.{type SystemWaypoint} pub type System { System( constellation: Option(Constellation), symbol: SystemSymbol, sector_symbol: SectorSymbol, type_: SystemType, x: Int, y: Int, waypoints: List(SystemWaypoint), factions: List(SystemFaction), name: Option(String), ) } pub fn decoder() -> Decoder(System) { use constellation <- decode.optional_field( "constellation", option.None, decode.optional(constellation.decoder()), ) use symbol <- decode.field("symbol", system_symbol.decoder()) use sector_symbol <- decode.field("sectorSymbol", sector_symbol.decoder()) use type_ <- decode.field("type", system_type.decoder()) use x <- decode.field("x", decode.int) use y <- decode.field("y", decode.int) use waypoints <- decode.field( "waypoints", decode.list(system_waypoint.decoder()), ) use factions <- decode.field( "factions", decode.list(system_faction.decoder()), ) use name <- decode.optional_field( "name", option.None, decode.optional(decode.string), ) decode.success(System( constellation:, symbol:, sector_symbol:, type_:, x:, y:, waypoints:, factions:, name:, )) }