module TD.Data.ReportOption
(ReportOption(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.ByteString as BS
import qualified Data.Text as T
data ReportOption
= ReportOption
{ ReportOption -> Maybe ByteString
_id :: Maybe BS.ByteString
, ReportOption -> Maybe Text
text :: Maybe T.Text
}
deriving (ReportOption -> ReportOption -> Bool
(ReportOption -> ReportOption -> Bool)
-> (ReportOption -> ReportOption -> Bool) -> Eq ReportOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReportOption -> ReportOption -> Bool
== :: ReportOption -> ReportOption -> Bool
$c/= :: ReportOption -> ReportOption -> Bool
/= :: ReportOption -> ReportOption -> Bool
Eq, Int -> ReportOption -> ShowS
[ReportOption] -> ShowS
ReportOption -> String
(Int -> ReportOption -> ShowS)
-> (ReportOption -> String)
-> ([ReportOption] -> ShowS)
-> Show ReportOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReportOption -> ShowS
showsPrec :: Int -> ReportOption -> ShowS
$cshow :: ReportOption -> String
show :: ReportOption -> String
$cshowList :: [ReportOption] -> ShowS
showList :: [ReportOption] -> ShowS
Show)
instance I.ShortShow ReportOption where
shortShow :: ReportOption -> String
shortShow ReportOption
{ _id :: ReportOption -> Maybe ByteString
_id = Maybe ByteString
_id_
, text :: ReportOption -> Maybe Text
text = Maybe Text
text_
}
= String
"ReportOption"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
_id_
, String
"text" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
text_
]
instance AT.FromJSON ReportOption where
parseJSON :: Value -> Parser ReportOption
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
"reportOption" -> Value -> Parser ReportOption
parseReportOption Value
v
String
_ -> Parser ReportOption
forall a. Monoid a => a
mempty
where
parseReportOption :: A.Value -> AT.Parser ReportOption
parseReportOption :: Value -> Parser ReportOption
parseReportOption = String
-> (Object -> Parser ReportOption) -> Value -> Parser ReportOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReportOption" ((Object -> Parser ReportOption) -> Value -> Parser ReportOption)
-> (Object -> Parser ReportOption) -> Value -> Parser ReportOption
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ByteString
_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
"id"
Maybe Text
text_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"text"
ReportOption -> Parser ReportOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReportOption -> Parser ReportOption)
-> ReportOption -> Parser ReportOption
forall a b. (a -> b) -> a -> b
$ ReportOption
{ _id :: Maybe ByteString
_id = Maybe ByteString
_id_
, text :: Maybe Text
text = Maybe Text
text_
}
parseJSON Value
_ = Parser ReportOption
forall a. Monoid a => a
mempty