module TD.Data.BotVerification
(BotVerification(..)) 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.FormattedText as FormattedText
data BotVerification
= BotVerification
{ BotVerification -> Maybe Int
bot_user_id :: Maybe Int
, BotVerification -> Maybe Int
icon_custom_emoji_id :: Maybe Int
, BotVerification -> Maybe FormattedText
custom_description :: Maybe FormattedText.FormattedText
}
deriving (BotVerification -> BotVerification -> Bool
(BotVerification -> BotVerification -> Bool)
-> (BotVerification -> BotVerification -> Bool)
-> Eq BotVerification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BotVerification -> BotVerification -> Bool
== :: BotVerification -> BotVerification -> Bool
$c/= :: BotVerification -> BotVerification -> Bool
/= :: BotVerification -> BotVerification -> Bool
Eq, Int -> BotVerification -> ShowS
[BotVerification] -> ShowS
BotVerification -> String
(Int -> BotVerification -> ShowS)
-> (BotVerification -> String)
-> ([BotVerification] -> ShowS)
-> Show BotVerification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BotVerification -> ShowS
showsPrec :: Int -> BotVerification -> ShowS
$cshow :: BotVerification -> String
show :: BotVerification -> String
$cshowList :: [BotVerification] -> ShowS
showList :: [BotVerification] -> ShowS
Show)
instance I.ShortShow BotVerification where
shortShow :: BotVerification -> String
shortShow BotVerification
{ bot_user_id :: BotVerification -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
, icon_custom_emoji_id :: BotVerification -> Maybe Int
icon_custom_emoji_id = Maybe Int
icon_custom_emoji_id_
, custom_description :: BotVerification -> Maybe FormattedText
custom_description = Maybe FormattedText
custom_description_
}
= String
"BotVerification"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
, String
"icon_custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
icon_custom_emoji_id_
, String
"custom_description" String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
custom_description_
]
instance AT.FromJSON BotVerification where
parseJSON :: Value -> Parser BotVerification
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
"botVerification" -> Value -> Parser BotVerification
parseBotVerification Value
v
String
_ -> Parser BotVerification
forall a. Monoid a => a
mempty
where
parseBotVerification :: A.Value -> AT.Parser BotVerification
parseBotVerification :: Value -> Parser BotVerification
parseBotVerification = String
-> (Object -> Parser BotVerification)
-> Value
-> Parser BotVerification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BotVerification" ((Object -> Parser BotVerification)
-> Value -> Parser BotVerification)
-> (Object -> Parser BotVerification)
-> Value
-> Parser BotVerification
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
bot_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"bot_user_id"
Maybe Int
icon_custom_emoji_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
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
"icon_custom_emoji_id"
Maybe FormattedText
custom_description_ <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"custom_description"
BotVerification -> Parser BotVerification
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BotVerification -> Parser BotVerification)
-> BotVerification -> Parser BotVerification
forall a b. (a -> b) -> a -> b
$ BotVerification
{ bot_user_id :: Maybe Int
bot_user_id = Maybe Int
bot_user_id_
, icon_custom_emoji_id :: Maybe Int
icon_custom_emoji_id = Maybe Int
icon_custom_emoji_id_
, custom_description :: Maybe FormattedText
custom_description = Maybe FormattedText
custom_description_
}
parseJSON Value
_ = Parser BotVerification
forall a. Monoid a => a
mempty