module TD.Data.LoginUrlInfo
(LoginUrlInfo(..)) 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 LoginUrlInfo
= LoginUrlInfoOpen
{ LoginUrlInfo -> Maybe Text
url :: Maybe T.Text
, LoginUrlInfo -> Maybe Bool
skip_confirmation :: Maybe Bool
}
| LoginUrlInfoRequestConfirmation
{ url :: Maybe T.Text
, LoginUrlInfo -> Maybe Text
domain :: Maybe T.Text
, LoginUrlInfo -> Maybe Int
bot_user_id :: Maybe Int
, LoginUrlInfo -> Maybe Bool
request_write_access :: Maybe Bool
}
deriving (LoginUrlInfo -> LoginUrlInfo -> Bool
(LoginUrlInfo -> LoginUrlInfo -> Bool)
-> (LoginUrlInfo -> LoginUrlInfo -> Bool) -> Eq LoginUrlInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LoginUrlInfo -> LoginUrlInfo -> Bool
== :: LoginUrlInfo -> LoginUrlInfo -> Bool
$c/= :: LoginUrlInfo -> LoginUrlInfo -> Bool
/= :: LoginUrlInfo -> LoginUrlInfo -> Bool
Eq, Int -> LoginUrlInfo -> ShowS
[LoginUrlInfo] -> ShowS
LoginUrlInfo -> String
(Int -> LoginUrlInfo -> ShowS)
-> (LoginUrlInfo -> String)
-> ([LoginUrlInfo] -> ShowS)
-> Show LoginUrlInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LoginUrlInfo -> ShowS
showsPrec :: Int -> LoginUrlInfo -> ShowS
$cshow :: LoginUrlInfo -> String
show :: LoginUrlInfo -> String
$cshowList :: [LoginUrlInfo] -> ShowS
showList :: [LoginUrlInfo] -> ShowS
Show)
instance I.ShortShow LoginUrlInfo where
shortShow :: LoginUrlInfo -> String
shortShow LoginUrlInfoOpen
{ url :: LoginUrlInfo -> Maybe Text
url = Maybe Text
url_
, skip_confirmation :: LoginUrlInfo -> Maybe Bool
skip_confirmation = Maybe Bool
skip_confirmation_
}
= String
"LoginUrlInfoOpen"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
, String
"skip_confirmation" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
skip_confirmation_
]
shortShow LoginUrlInfoRequestConfirmation
{ url :: LoginUrlInfo -> Maybe Text
url = Maybe Text
url_
, domain :: LoginUrlInfo -> Maybe Text
domain = Maybe Text
domain_
, bot_user_id :: LoginUrlInfo -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
, request_write_access :: LoginUrlInfo -> Maybe Bool
request_write_access = Maybe Bool
request_write_access_
}
= String
"LoginUrlInfoRequestConfirmation"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
, String
"domain" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
domain_
, String
"bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
, String
"request_write_access" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
request_write_access_
]
instance AT.FromJSON LoginUrlInfo where
parseJSON :: Value -> Parser LoginUrlInfo
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
"loginUrlInfoOpen" -> Value -> Parser LoginUrlInfo
parseLoginUrlInfoOpen Value
v
String
"loginUrlInfoRequestConfirmation" -> Value -> Parser LoginUrlInfo
parseLoginUrlInfoRequestConfirmation Value
v
String
_ -> Parser LoginUrlInfo
forall a. Monoid a => a
mempty
where
parseLoginUrlInfoOpen :: A.Value -> AT.Parser LoginUrlInfo
parseLoginUrlInfoOpen :: Value -> Parser LoginUrlInfo
parseLoginUrlInfoOpen = String
-> (Object -> Parser LoginUrlInfo) -> Value -> Parser LoginUrlInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LoginUrlInfoOpen" ((Object -> Parser LoginUrlInfo) -> Value -> Parser LoginUrlInfo)
-> (Object -> Parser LoginUrlInfo) -> Value -> Parser LoginUrlInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
Maybe Bool
skip_confirmation_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"skip_confirmation"
LoginUrlInfo -> Parser LoginUrlInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LoginUrlInfo -> Parser LoginUrlInfo)
-> LoginUrlInfo -> Parser LoginUrlInfo
forall a b. (a -> b) -> a -> b
$ LoginUrlInfoOpen
{ url :: Maybe Text
url = Maybe Text
url_
, skip_confirmation :: Maybe Bool
skip_confirmation = Maybe Bool
skip_confirmation_
}
parseLoginUrlInfoRequestConfirmation :: A.Value -> AT.Parser LoginUrlInfo
parseLoginUrlInfoRequestConfirmation :: Value -> Parser LoginUrlInfo
parseLoginUrlInfoRequestConfirmation = String
-> (Object -> Parser LoginUrlInfo) -> Value -> Parser LoginUrlInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LoginUrlInfoRequestConfirmation" ((Object -> Parser LoginUrlInfo) -> Value -> Parser LoginUrlInfo)
-> (Object -> Parser LoginUrlInfo) -> Value -> Parser LoginUrlInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
Maybe Text
domain_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"domain"
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 Bool
request_write_access_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"request_write_access"
LoginUrlInfo -> Parser LoginUrlInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LoginUrlInfo -> Parser LoginUrlInfo)
-> LoginUrlInfo -> Parser LoginUrlInfo
forall a b. (a -> b) -> a -> b
$ LoginUrlInfoRequestConfirmation
{ url :: Maybe Text
url = Maybe Text
url_
, domain :: Maybe Text
domain = Maybe Text
domain_
, bot_user_id :: Maybe Int
bot_user_id = Maybe Int
bot_user_id_
, request_write_access :: Maybe Bool
request_write_access = Maybe Bool
request_write_access_
}
parseJSON Value
_ = Parser LoginUrlInfo
forall a. Monoid a => a
mempty