module TD.Data.SponsoredChat
(SponsoredChat(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data
=
{ SponsoredChat -> Maybe Int
unique_id :: Maybe Int
, SponsoredChat -> Maybe Int
chat_id :: Maybe Int
, :: Maybe T.Text
, SponsoredChat -> Maybe Text
additional_info :: Maybe T.Text
}
deriving (SponsoredChat -> SponsoredChat -> Bool
(SponsoredChat -> SponsoredChat -> Bool)
-> (SponsoredChat -> SponsoredChat -> Bool) -> Eq SponsoredChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SponsoredChat -> SponsoredChat -> Bool
== :: SponsoredChat -> SponsoredChat -> Bool
$c/= :: SponsoredChat -> SponsoredChat -> Bool
/= :: SponsoredChat -> SponsoredChat -> Bool
Eq, Int -> SponsoredChat -> ShowS
[SponsoredChat] -> ShowS
SponsoredChat -> String
(Int -> SponsoredChat -> ShowS)
-> (SponsoredChat -> String)
-> ([SponsoredChat] -> ShowS)
-> Show SponsoredChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SponsoredChat -> ShowS
showsPrec :: Int -> SponsoredChat -> ShowS
$cshow :: SponsoredChat -> String
show :: SponsoredChat -> String
$cshowList :: [SponsoredChat] -> ShowS
showList :: [SponsoredChat] -> ShowS
Show)
instance I.ShortShow SponsoredChat where
shortShow :: SponsoredChat -> String
shortShow SponsoredChat
{ unique_id :: SponsoredChat -> Maybe Int
unique_id = Maybe Int
unique_id_
, chat_id :: SponsoredChat -> Maybe Int
chat_id = Maybe Int
chat_id_
, sponsor_info :: SponsoredChat -> Maybe Text
sponsor_info = Maybe Text
sponsor_info_
, additional_info :: SponsoredChat -> Maybe Text
additional_info = Maybe Text
additional_info_
}
= String
"SponsoredChat"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"unique_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
unique_id_
, String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
, String
"sponsor_info" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
sponsor_info_
, String
"additional_info" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
additional_info_
]
instance AT.FromJSON SponsoredChat where
parseJSON :: Value -> Parser SponsoredChat
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
"sponsoredChat" -> Value -> Parser SponsoredChat
parseSponsoredChat Value
v
String
_ -> Parser SponsoredChat
forall a. Monoid a => a
mempty
where
parseSponsoredChat :: A.Value -> AT.Parser SponsoredChat
parseSponsoredChat :: Value -> Parser SponsoredChat
parseSponsoredChat = String
-> (Object -> Parser SponsoredChat)
-> Value
-> Parser SponsoredChat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SponsoredChat" ((Object -> Parser SponsoredChat) -> Value -> Parser SponsoredChat)
-> (Object -> Parser SponsoredChat)
-> Value
-> Parser SponsoredChat
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
unique_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"unique_id"
Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
Maybe Text
sponsor_info_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sponsor_info"
Maybe Text
additional_info_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"additional_info"
SponsoredChat -> Parser SponsoredChat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SponsoredChat -> Parser SponsoredChat)
-> SponsoredChat -> Parser SponsoredChat
forall a b. (a -> b) -> a -> b
$ SponsoredChat
{ unique_id :: Maybe Int
unique_id = Maybe Int
unique_id_
, chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
, sponsor_info :: Maybe Text
sponsor_info = Maybe Text
sponsor_info_
, additional_info :: Maybe Text
additional_info = Maybe Text
additional_info_
}
parseJSON Value
_ = Parser SponsoredChat
forall a. Monoid a => a
mempty