module TD.Data.AuthorizationState
(AuthorizationState(..)) 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.EmailAddressAuthenticationCodeInfo as EmailAddressAuthenticationCodeInfo
import qualified TD.Data.EmailAddressResetState as EmailAddressResetState
import qualified TD.Data.AuthenticationCodeInfo as AuthenticationCodeInfo
import qualified Data.Text as T
import qualified TD.Data.TermsOfService as TermsOfService
data AuthorizationState
= AuthorizationStateWaitTdlibParameters
| AuthorizationStateWaitPhoneNumber
| AuthorizationStateWaitEmailAddress
{ AuthorizationState -> Maybe Bool
allow_apple_id :: Maybe Bool
, AuthorizationState -> Maybe Bool
allow_google_id :: Maybe Bool
}
| AuthorizationStateWaitEmailCode
{ allow_apple_id :: Maybe Bool
, allow_google_id :: Maybe Bool
, AuthorizationState -> Maybe EmailAddressAuthenticationCodeInfo
code_info :: Maybe EmailAddressAuthenticationCodeInfo.EmailAddressAuthenticationCodeInfo
, AuthorizationState -> Maybe EmailAddressResetState
email_address_reset_state :: Maybe EmailAddressResetState.EmailAddressResetState
}
| AuthorizationStateWaitCode
{ AuthorizationState -> Maybe AuthenticationCodeInfo
_code_info :: Maybe AuthenticationCodeInfo.AuthenticationCodeInfo
}
| AuthorizationStateWaitOtherDeviceConfirmation
{ AuthorizationState -> Maybe Text
link :: Maybe T.Text
}
| AuthorizationStateWaitRegistration
{ AuthorizationState -> Maybe TermsOfService
terms_of_service :: Maybe TermsOfService.TermsOfService
}
| AuthorizationStateWaitPassword
{ AuthorizationState -> Maybe Text
password_hint :: Maybe T.Text
, AuthorizationState -> Maybe Bool
has_recovery_email_address :: Maybe Bool
, AuthorizationState -> Maybe Bool
has_passport_data :: Maybe Bool
, AuthorizationState -> Maybe Text
recovery_email_address_pattern :: Maybe T.Text
}
| AuthorizationStateReady
| AuthorizationStateLoggingOut
| AuthorizationStateClosing
| AuthorizationStateClosed
deriving (AuthorizationState -> AuthorizationState -> Bool
(AuthorizationState -> AuthorizationState -> Bool)
-> (AuthorizationState -> AuthorizationState -> Bool)
-> Eq AuthorizationState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AuthorizationState -> AuthorizationState -> Bool
== :: AuthorizationState -> AuthorizationState -> Bool
$c/= :: AuthorizationState -> AuthorizationState -> Bool
/= :: AuthorizationState -> AuthorizationState -> Bool
Eq, Int -> AuthorizationState -> ShowS
[AuthorizationState] -> ShowS
AuthorizationState -> String
(Int -> AuthorizationState -> ShowS)
-> (AuthorizationState -> String)
-> ([AuthorizationState] -> ShowS)
-> Show AuthorizationState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AuthorizationState -> ShowS
showsPrec :: Int -> AuthorizationState -> ShowS
$cshow :: AuthorizationState -> String
show :: AuthorizationState -> String
$cshowList :: [AuthorizationState] -> ShowS
showList :: [AuthorizationState] -> ShowS
Show)
instance I.ShortShow AuthorizationState where
shortShow :: AuthorizationState -> String
shortShow AuthorizationState
AuthorizationStateWaitTdlibParameters
= String
"AuthorizationStateWaitTdlibParameters"
shortShow AuthorizationState
AuthorizationStateWaitPhoneNumber
= String
"AuthorizationStateWaitPhoneNumber"
shortShow AuthorizationStateWaitEmailAddress
{ allow_apple_id :: AuthorizationState -> Maybe Bool
allow_apple_id = Maybe Bool
allow_apple_id_
, allow_google_id :: AuthorizationState -> Maybe Bool
allow_google_id = Maybe Bool
allow_google_id_
}
= String
"AuthorizationStateWaitEmailAddress"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"allow_apple_id" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_apple_id_
, String
"allow_google_id" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_google_id_
]
shortShow AuthorizationStateWaitEmailCode
{ allow_apple_id :: AuthorizationState -> Maybe Bool
allow_apple_id = Maybe Bool
allow_apple_id_
, allow_google_id :: AuthorizationState -> Maybe Bool
allow_google_id = Maybe Bool
allow_google_id_
, code_info :: AuthorizationState -> Maybe EmailAddressAuthenticationCodeInfo
code_info = Maybe EmailAddressAuthenticationCodeInfo
code_info_
, email_address_reset_state :: AuthorizationState -> Maybe EmailAddressResetState
email_address_reset_state = Maybe EmailAddressResetState
email_address_reset_state_
}
= String
"AuthorizationStateWaitEmailCode"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"allow_apple_id" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_apple_id_
, String
"allow_google_id" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_google_id_
, String
"code_info" String -> Maybe EmailAddressAuthenticationCodeInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe EmailAddressAuthenticationCodeInfo
code_info_
, String
"email_address_reset_state" String -> Maybe EmailAddressResetState -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe EmailAddressResetState
email_address_reset_state_
]
shortShow AuthorizationStateWaitCode
{ _code_info :: AuthorizationState -> Maybe AuthenticationCodeInfo
_code_info = Maybe AuthenticationCodeInfo
_code_info_
}
= String
"AuthorizationStateWaitCode"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_code_info" String -> Maybe AuthenticationCodeInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AuthenticationCodeInfo
_code_info_
]
shortShow AuthorizationStateWaitOtherDeviceConfirmation
{ link :: AuthorizationState -> Maybe Text
link = Maybe Text
link_
}
= String
"AuthorizationStateWaitOtherDeviceConfirmation"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"link" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
link_
]
shortShow AuthorizationStateWaitRegistration
{ terms_of_service :: AuthorizationState -> Maybe TermsOfService
terms_of_service = Maybe TermsOfService
terms_of_service_
}
= String
"AuthorizationStateWaitRegistration"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"terms_of_service" String -> Maybe TermsOfService -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TermsOfService
terms_of_service_
]
shortShow AuthorizationStateWaitPassword
{ password_hint :: AuthorizationState -> Maybe Text
password_hint = Maybe Text
password_hint_
, has_recovery_email_address :: AuthorizationState -> Maybe Bool
has_recovery_email_address = Maybe Bool
has_recovery_email_address_
, has_passport_data :: AuthorizationState -> Maybe Bool
has_passport_data = Maybe Bool
has_passport_data_
, recovery_email_address_pattern :: AuthorizationState -> Maybe Text
recovery_email_address_pattern = Maybe Text
recovery_email_address_pattern_
}
= String
"AuthorizationStateWaitPassword"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"password_hint" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
password_hint_
, String
"has_recovery_email_address" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_recovery_email_address_
, String
"has_passport_data" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_passport_data_
, String
"recovery_email_address_pattern" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
recovery_email_address_pattern_
]
shortShow AuthorizationState
AuthorizationStateReady
= String
"AuthorizationStateReady"
shortShow AuthorizationState
AuthorizationStateLoggingOut
= String
"AuthorizationStateLoggingOut"
shortShow AuthorizationState
AuthorizationStateClosing
= String
"AuthorizationStateClosing"
shortShow AuthorizationState
AuthorizationStateClosed
= String
"AuthorizationStateClosed"
instance AT.FromJSON AuthorizationState where
parseJSON :: Value -> Parser AuthorizationState
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
"authorizationStateWaitTdlibParameters" -> AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuthorizationState
AuthorizationStateWaitTdlibParameters
String
"authorizationStateWaitPhoneNumber" -> AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuthorizationState
AuthorizationStateWaitPhoneNumber
String
"authorizationStateWaitEmailAddress" -> Value -> Parser AuthorizationState
parseAuthorizationStateWaitEmailAddress Value
v
String
"authorizationStateWaitEmailCode" -> Value -> Parser AuthorizationState
parseAuthorizationStateWaitEmailCode Value
v
String
"authorizationStateWaitCode" -> Value -> Parser AuthorizationState
parseAuthorizationStateWaitCode Value
v
String
"authorizationStateWaitOtherDeviceConfirmation" -> Value -> Parser AuthorizationState
parseAuthorizationStateWaitOtherDeviceConfirmation Value
v
String
"authorizationStateWaitRegistration" -> Value -> Parser AuthorizationState
parseAuthorizationStateWaitRegistration Value
v
String
"authorizationStateWaitPassword" -> Value -> Parser AuthorizationState
parseAuthorizationStateWaitPassword Value
v
String
"authorizationStateReady" -> AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuthorizationState
AuthorizationStateReady
String
"authorizationStateLoggingOut" -> AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuthorizationState
AuthorizationStateLoggingOut
String
"authorizationStateClosing" -> AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuthorizationState
AuthorizationStateClosing
String
"authorizationStateClosed" -> AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuthorizationState
AuthorizationStateClosed
String
_ -> Parser AuthorizationState
forall a. Monoid a => a
mempty
where
parseAuthorizationStateWaitEmailAddress :: A.Value -> AT.Parser AuthorizationState
parseAuthorizationStateWaitEmailAddress :: Value -> Parser AuthorizationState
parseAuthorizationStateWaitEmailAddress = String
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AuthorizationStateWaitEmailAddress" ((Object -> Parser AuthorizationState)
-> Value -> Parser AuthorizationState)
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
allow_apple_id_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_apple_id"
Maybe Bool
allow_google_id_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_google_id"
AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AuthorizationState -> Parser AuthorizationState)
-> AuthorizationState -> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ AuthorizationStateWaitEmailAddress
{ allow_apple_id :: Maybe Bool
allow_apple_id = Maybe Bool
allow_apple_id_
, allow_google_id :: Maybe Bool
allow_google_id = Maybe Bool
allow_google_id_
}
parseAuthorizationStateWaitEmailCode :: A.Value -> AT.Parser AuthorizationState
parseAuthorizationStateWaitEmailCode :: Value -> Parser AuthorizationState
parseAuthorizationStateWaitEmailCode = String
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AuthorizationStateWaitEmailCode" ((Object -> Parser AuthorizationState)
-> Value -> Parser AuthorizationState)
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
allow_apple_id_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_apple_id"
Maybe Bool
allow_google_id_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_google_id"
Maybe EmailAddressAuthenticationCodeInfo
code_info_ <- Object
o Object -> Key -> Parser (Maybe EmailAddressAuthenticationCodeInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"code_info"
Maybe EmailAddressResetState
email_address_reset_state_ <- Object
o Object -> Key -> Parser (Maybe EmailAddressResetState)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"email_address_reset_state"
AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AuthorizationState -> Parser AuthorizationState)
-> AuthorizationState -> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ AuthorizationStateWaitEmailCode
{ allow_apple_id :: Maybe Bool
allow_apple_id = Maybe Bool
allow_apple_id_
, allow_google_id :: Maybe Bool
allow_google_id = Maybe Bool
allow_google_id_
, code_info :: Maybe EmailAddressAuthenticationCodeInfo
code_info = Maybe EmailAddressAuthenticationCodeInfo
code_info_
, email_address_reset_state :: Maybe EmailAddressResetState
email_address_reset_state = Maybe EmailAddressResetState
email_address_reset_state_
}
parseAuthorizationStateWaitCode :: A.Value -> AT.Parser AuthorizationState
parseAuthorizationStateWaitCode :: Value -> Parser AuthorizationState
parseAuthorizationStateWaitCode = String
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AuthorizationStateWaitCode" ((Object -> Parser AuthorizationState)
-> Value -> Parser AuthorizationState)
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe AuthenticationCodeInfo
_code_info_ <- Object
o Object -> Key -> Parser (Maybe AuthenticationCodeInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"code_info"
AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AuthorizationState -> Parser AuthorizationState)
-> AuthorizationState -> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ AuthorizationStateWaitCode
{ _code_info :: Maybe AuthenticationCodeInfo
_code_info = Maybe AuthenticationCodeInfo
_code_info_
}
parseAuthorizationStateWaitOtherDeviceConfirmation :: A.Value -> AT.Parser AuthorizationState
parseAuthorizationStateWaitOtherDeviceConfirmation :: Value -> Parser AuthorizationState
parseAuthorizationStateWaitOtherDeviceConfirmation = String
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AuthorizationStateWaitOtherDeviceConfirmation" ((Object -> Parser AuthorizationState)
-> Value -> Parser AuthorizationState)
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
link_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"link"
AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AuthorizationState -> Parser AuthorizationState)
-> AuthorizationState -> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ AuthorizationStateWaitOtherDeviceConfirmation
{ link :: Maybe Text
link = Maybe Text
link_
}
parseAuthorizationStateWaitRegistration :: A.Value -> AT.Parser AuthorizationState
parseAuthorizationStateWaitRegistration :: Value -> Parser AuthorizationState
parseAuthorizationStateWaitRegistration = String
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AuthorizationStateWaitRegistration" ((Object -> Parser AuthorizationState)
-> Value -> Parser AuthorizationState)
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe TermsOfService
terms_of_service_ <- Object
o Object -> Key -> Parser (Maybe TermsOfService)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"terms_of_service"
AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AuthorizationState -> Parser AuthorizationState)
-> AuthorizationState -> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ AuthorizationStateWaitRegistration
{ terms_of_service :: Maybe TermsOfService
terms_of_service = Maybe TermsOfService
terms_of_service_
}
parseAuthorizationStateWaitPassword :: A.Value -> AT.Parser AuthorizationState
parseAuthorizationStateWaitPassword :: Value -> Parser AuthorizationState
parseAuthorizationStateWaitPassword = String
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AuthorizationStateWaitPassword" ((Object -> Parser AuthorizationState)
-> Value -> Parser AuthorizationState)
-> (Object -> Parser AuthorizationState)
-> Value
-> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
password_hint_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"password_hint"
Maybe Bool
has_recovery_email_address_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_recovery_email_address"
Maybe Bool
has_passport_data_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_passport_data"
Maybe Text
recovery_email_address_pattern_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"recovery_email_address_pattern"
AuthorizationState -> Parser AuthorizationState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AuthorizationState -> Parser AuthorizationState)
-> AuthorizationState -> Parser AuthorizationState
forall a b. (a -> b) -> a -> b
$ AuthorizationStateWaitPassword
{ password_hint :: Maybe Text
password_hint = Maybe Text
password_hint_
, has_recovery_email_address :: Maybe Bool
has_recovery_email_address = Maybe Bool
has_recovery_email_address_
, has_passport_data :: Maybe Bool
has_passport_data = Maybe Bool
has_passport_data_
, recovery_email_address_pattern :: Maybe Text
recovery_email_address_pattern = Maybe Text
recovery_email_address_pattern_
}
parseJSON Value
_ = Parser AuthorizationState
forall a. Monoid a => a
mempty