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