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