module TD.Data.ReportStoryResult
(ReportStoryResult(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.ReportOption as ReportOption
import qualified Data.ByteString as BS
data ReportStoryResult
= ReportStoryResultOk
| ReportStoryResultOptionRequired
{ ReportStoryResult -> Maybe Text
title :: Maybe T.Text
, ReportStoryResult -> Maybe [ReportOption]
options :: Maybe [ReportOption.ReportOption]
}
| ReportStoryResultTextRequired
{ ReportStoryResult -> Maybe ByteString
option_id :: Maybe BS.ByteString
, ReportStoryResult -> Maybe Bool
is_optional :: Maybe Bool
}
deriving (ReportStoryResult -> ReportStoryResult -> Bool
(ReportStoryResult -> ReportStoryResult -> Bool)
-> (ReportStoryResult -> ReportStoryResult -> Bool)
-> Eq ReportStoryResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReportStoryResult -> ReportStoryResult -> Bool
== :: ReportStoryResult -> ReportStoryResult -> Bool
$c/= :: ReportStoryResult -> ReportStoryResult -> Bool
/= :: ReportStoryResult -> ReportStoryResult -> Bool
Eq, Int -> ReportStoryResult -> ShowS
[ReportStoryResult] -> ShowS
ReportStoryResult -> String
(Int -> ReportStoryResult -> ShowS)
-> (ReportStoryResult -> String)
-> ([ReportStoryResult] -> ShowS)
-> Show ReportStoryResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReportStoryResult -> ShowS
showsPrec :: Int -> ReportStoryResult -> ShowS
$cshow :: ReportStoryResult -> String
show :: ReportStoryResult -> String
$cshowList :: [ReportStoryResult] -> ShowS
showList :: [ReportStoryResult] -> ShowS
Show)
instance I.ShortShow ReportStoryResult where
shortShow :: ReportStoryResult -> String
shortShow ReportStoryResult
ReportStoryResultOk
= String
"ReportStoryResultOk"
shortShow ReportStoryResultOptionRequired
{ title :: ReportStoryResult -> Maybe Text
title = Maybe Text
title_
, options :: ReportStoryResult -> Maybe [ReportOption]
options = Maybe [ReportOption]
options_
}
= String
"ReportStoryResultOptionRequired"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"options" String -> Maybe [ReportOption] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ReportOption]
options_
]
shortShow ReportStoryResultTextRequired
{ option_id :: ReportStoryResult -> Maybe ByteString
option_id = Maybe ByteString
option_id_
, is_optional :: ReportStoryResult -> Maybe Bool
is_optional = Maybe Bool
is_optional_
}
= String
"ReportStoryResultTextRequired"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"option_id" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
option_id_
, String
"is_optional" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_optional_
]
instance AT.FromJSON ReportStoryResult where
parseJSON :: Value -> Parser ReportStoryResult
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"reportStoryResultOk" -> ReportStoryResult -> Parser ReportStoryResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReportStoryResult
ReportStoryResultOk
String
"reportStoryResultOptionRequired" -> Value -> Parser ReportStoryResult
parseReportStoryResultOptionRequired Value
v
String
"reportStoryResultTextRequired" -> Value -> Parser ReportStoryResult
parseReportStoryResultTextRequired Value
v
String
_ -> Parser ReportStoryResult
forall a. Monoid a => a
mempty
where
parseReportStoryResultOptionRequired :: A.Value -> AT.Parser ReportStoryResult
parseReportStoryResultOptionRequired :: Value -> Parser ReportStoryResult
parseReportStoryResultOptionRequired = String
-> (Object -> Parser ReportStoryResult)
-> Value
-> Parser ReportStoryResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReportStoryResultOptionRequired" ((Object -> Parser ReportStoryResult)
-> Value -> Parser ReportStoryResult)
-> (Object -> Parser ReportStoryResult)
-> Value
-> Parser ReportStoryResult
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe [ReportOption]
options_ <- Object
o Object -> Key -> Parser (Maybe [ReportOption])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"options"
ReportStoryResult -> Parser ReportStoryResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReportStoryResult -> Parser ReportStoryResult)
-> ReportStoryResult -> Parser ReportStoryResult
forall a b. (a -> b) -> a -> b
$ ReportStoryResultOptionRequired
{ title :: Maybe Text
title = Maybe Text
title_
, options :: Maybe [ReportOption]
options = Maybe [ReportOption]
options_
}
parseReportStoryResultTextRequired :: A.Value -> AT.Parser ReportStoryResult
parseReportStoryResultTextRequired :: Value -> Parser ReportStoryResult
parseReportStoryResultTextRequired = String
-> (Object -> Parser ReportStoryResult)
-> Value
-> Parser ReportStoryResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReportStoryResultTextRequired" ((Object -> Parser ReportStoryResult)
-> Value -> Parser ReportStoryResult)
-> (Object -> Parser ReportStoryResult)
-> Value
-> Parser ReportStoryResult
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ByteString
option_id_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"option_id"
Maybe Bool
is_optional_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_optional"
ReportStoryResult -> Parser ReportStoryResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReportStoryResult -> Parser ReportStoryResult)
-> ReportStoryResult -> Parser ReportStoryResult
forall a b. (a -> b) -> a -> b
$ ReportStoryResultTextRequired
{ option_id :: Maybe ByteString
option_id = Maybe ByteString
option_id_
, is_optional :: Maybe Bool
is_optional = Maybe Bool
is_optional_
}
parseJSON Value
_ = Parser ReportStoryResult
forall a. Monoid a => a
mempty