import gleam/dynamic/decode.{type Decoder} import gleam/option.{type Option} import models/contract_terms.{type ContractTerms} import utils/decode as decode_utils pub type Contract { Contract( id: String, faction_symbol: String, type_: String, terms: ContractTerms, accepted: Bool, fulfilled: Bool, deadline_to_accept: Option(String), ) } pub fn decoder() -> Decoder(Contract) { use id <- decode.field("id", decode.string) use faction_symbol <- decode.field("factionSymbol", decode.string) use type_ <- decode.field("type", decode.string) use terms <- decode.field("terms", contract_terms.decoder()) use accepted <- decode.field("accepted", decode.bool) use fulfilled <- decode.field("fulfilled", decode.bool) use deadline_to_accept <- decode_utils.field_key_value_optional( "deadlineToAccept", decode.string, ) decode.success(Contract( id:, faction_symbol:, type_:, terms:, accepted:, fulfilled:, deadline_to_accept:, )) }