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