module Model.InitResult ( InitResult(..) , initResultDecoder ) where import Json.Decode as Json exposing ((:=)) import Model.Init exposing (Init, initDecoder) type InitResult = InitEmpty | InitSuccess Init | InitError String initResultDecoder : Json.Decoder InitResult initResultDecoder = ("tag" := Json.string) `Json.andThen` initResultDecoderWithTag initResultDecoderWithTag : String -> Json.Decoder InitResult initResultDecoderWithTag tag = case tag of "InitEmpty" -> Json.succeed InitEmpty "InitSuccess" -> Json.map InitSuccess ("contents" := initDecoder) "InitError" -> Json.map InitError ("contents" := Json.string) _ -> Json.fail <| "got " ++ tag ++ " for InitResult"