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