module TD.Data.ChatJoinResult
(ChatJoinResult(..)) 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.WebAppUrl as WebAppUrl
data ChatJoinResult
= ChatJoinResultSuccess
{ ChatJoinResult -> Maybe Int
chat_id :: Maybe Int
}
| ChatJoinResultRequestSent
| ChatJoinResultGuardBotApprovalRequired
{ ChatJoinResult -> Maybe Int
bot_user_id :: Maybe Int
, ChatJoinResult -> Maybe WebAppUrl
url :: Maybe WebAppUrl.WebAppUrl
, ChatJoinResult -> Maybe Int
query_id :: Maybe Int
}
| ChatJoinResultDeclined
deriving (ChatJoinResult -> ChatJoinResult -> Bool
(ChatJoinResult -> ChatJoinResult -> Bool)
-> (ChatJoinResult -> ChatJoinResult -> Bool) -> Eq ChatJoinResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatJoinResult -> ChatJoinResult -> Bool
== :: ChatJoinResult -> ChatJoinResult -> Bool
$c/= :: ChatJoinResult -> ChatJoinResult -> Bool
/= :: ChatJoinResult -> ChatJoinResult -> Bool
Eq, Int -> ChatJoinResult -> ShowS
[ChatJoinResult] -> ShowS
ChatJoinResult -> String
(Int -> ChatJoinResult -> ShowS)
-> (ChatJoinResult -> String)
-> ([ChatJoinResult] -> ShowS)
-> Show ChatJoinResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatJoinResult -> ShowS
showsPrec :: Int -> ChatJoinResult -> ShowS
$cshow :: ChatJoinResult -> String
show :: ChatJoinResult -> String
$cshowList :: [ChatJoinResult] -> ShowS
showList :: [ChatJoinResult] -> ShowS
Show)
instance I.ShortShow ChatJoinResult where
shortShow :: ChatJoinResult -> String
shortShow ChatJoinResultSuccess
{ chat_id :: ChatJoinResult -> Maybe Int
chat_id = Maybe Int
chat_id_
}
= String
"ChatJoinResultSuccess"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
]
shortShow ChatJoinResult
ChatJoinResultRequestSent
= String
"ChatJoinResultRequestSent"
shortShow ChatJoinResultGuardBotApprovalRequired
{ bot_user_id :: ChatJoinResult -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
, url :: ChatJoinResult -> Maybe WebAppUrl
url = Maybe WebAppUrl
url_
, query_id :: ChatJoinResult -> Maybe Int
query_id = Maybe Int
query_id_
}
= String
"ChatJoinResultGuardBotApprovalRequired"
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
"url" String -> Maybe WebAppUrl -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe WebAppUrl
url_
, String
"query_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
query_id_
]
shortShow ChatJoinResult
ChatJoinResultDeclined
= String
"ChatJoinResultDeclined"
instance AT.FromJSON ChatJoinResult where
parseJSON :: Value -> Parser ChatJoinResult
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
"chatJoinResultSuccess" -> Value -> Parser ChatJoinResult
parseChatJoinResultSuccess Value
v
String
"chatJoinResultRequestSent" -> ChatJoinResult -> Parser ChatJoinResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatJoinResult
ChatJoinResultRequestSent
String
"chatJoinResultGuardBotApprovalRequired" -> Value -> Parser ChatJoinResult
parseChatJoinResultGuardBotApprovalRequired Value
v
String
"chatJoinResultDeclined" -> ChatJoinResult -> Parser ChatJoinResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatJoinResult
ChatJoinResultDeclined
String
_ -> Parser ChatJoinResult
forall a. Monoid a => a
mempty
where
parseChatJoinResultSuccess :: A.Value -> AT.Parser ChatJoinResult
parseChatJoinResultSuccess :: Value -> Parser ChatJoinResult
parseChatJoinResultSuccess = String
-> (Object -> Parser ChatJoinResult)
-> Value
-> Parser ChatJoinResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatJoinResultSuccess" ((Object -> Parser ChatJoinResult)
-> Value -> Parser ChatJoinResult)
-> (Object -> Parser ChatJoinResult)
-> Value
-> Parser ChatJoinResult
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
ChatJoinResult -> Parser ChatJoinResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatJoinResult -> Parser ChatJoinResult)
-> ChatJoinResult -> Parser ChatJoinResult
forall a b. (a -> b) -> a -> b
$ ChatJoinResultSuccess
{ chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
}
parseChatJoinResultGuardBotApprovalRequired :: A.Value -> AT.Parser ChatJoinResult
parseChatJoinResultGuardBotApprovalRequired :: Value -> Parser ChatJoinResult
parseChatJoinResultGuardBotApprovalRequired = String
-> (Object -> Parser ChatJoinResult)
-> Value
-> Parser ChatJoinResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatJoinResultGuardBotApprovalRequired" ((Object -> Parser ChatJoinResult)
-> Value -> Parser ChatJoinResult)
-> (Object -> Parser ChatJoinResult)
-> Value
-> Parser ChatJoinResult
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 WebAppUrl
url_ <- Object
o Object -> Key -> Parser (Maybe WebAppUrl)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
Maybe Int
query_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"query_id"
ChatJoinResult -> Parser ChatJoinResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatJoinResult -> Parser ChatJoinResult)
-> ChatJoinResult -> Parser ChatJoinResult
forall a b. (a -> b) -> a -> b
$ ChatJoinResultGuardBotApprovalRequired
{ bot_user_id :: Maybe Int
bot_user_id = Maybe Int
bot_user_id_
, url :: Maybe WebAppUrl
url = Maybe WebAppUrl
url_
, query_id :: Maybe Int
query_id = Maybe Int
query_id_
}
parseJSON Value
_ = Parser ChatJoinResult
forall a. Monoid a => a
mempty