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