2023-01-10 02:22:46 +00:00
|
|
|
module Deck exposing (..)
|
|
|
|
|
2023-01-10 17:31:31 +00:00
|
|
|
import Card
|
2023-01-10 02:22:46 +00:00
|
|
|
import Json.Decode
|
|
|
|
import Json.Decode.Pipeline as JDP
|
|
|
|
|
|
|
|
|
|
|
|
type alias Deck =
|
|
|
|
{ id : Int
|
|
|
|
, name : String
|
2023-01-10 17:31:31 +00:00
|
|
|
, cards : List Card
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Card =
|
|
|
|
{ oracle : Card.Oracle
|
|
|
|
, quantity : Int
|
2023-01-10 02:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decode : Json.Decode.Decoder Deck
|
|
|
|
decode =
|
|
|
|
Json.Decode.succeed Deck
|
|
|
|
|> JDP.required "deck_id" Json.Decode.int
|
|
|
|
|> JDP.required "name" Json.Decode.string
|
2023-01-10 17:31:31 +00:00
|
|
|
|> JDP.required "cards" (Json.Decode.list decodeCard)
|
|
|
|
|
|
|
|
|
|
|
|
decodeCard : Json.Decode.Decoder Card
|
|
|
|
decodeCard =
|
|
|
|
Json.Decode.succeed Card
|
|
|
|
|> JDP.required "card" Card.decodeOracle
|
|
|
|
|> JDP.required "quantity" Json.Decode.int
|