module TD.Data.PasswordState
(PasswordState(..)) 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
import qualified TD.Data.EmailAddressAuthenticationCodeInfo as EmailAddressAuthenticationCodeInfo
data PasswordState
= PasswordState
{ PasswordState -> Maybe Bool
has_password :: Maybe Bool
, PasswordState -> Maybe Text
password_hint :: Maybe T.Text
, PasswordState -> Maybe Bool
has_recovery_email_address :: Maybe Bool
, PasswordState -> Maybe Bool
has_passport_data :: Maybe Bool
, PasswordState -> Maybe EmailAddressAuthenticationCodeInfo
recovery_email_address_code_info :: Maybe EmailAddressAuthenticationCodeInfo.EmailAddressAuthenticationCodeInfo
, PasswordState -> Maybe Text
login_email_address_pattern :: Maybe T.Text
, PasswordState -> Maybe Int
pending_reset_date :: Maybe Int
}
deriving (PasswordState -> PasswordState -> Bool
(PasswordState -> PasswordState -> Bool)
-> (PasswordState -> PasswordState -> Bool) -> Eq PasswordState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PasswordState -> PasswordState -> Bool
== :: PasswordState -> PasswordState -> Bool
$c/= :: PasswordState -> PasswordState -> Bool
/= :: PasswordState -> PasswordState -> Bool
Eq, Int -> PasswordState -> ShowS
[PasswordState] -> ShowS
PasswordState -> String
(Int -> PasswordState -> ShowS)
-> (PasswordState -> String)
-> ([PasswordState] -> ShowS)
-> Show PasswordState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PasswordState -> ShowS
showsPrec :: Int -> PasswordState -> ShowS
$cshow :: PasswordState -> String
show :: PasswordState -> String
$cshowList :: [PasswordState] -> ShowS
showList :: [PasswordState] -> ShowS
Show)
instance I.ShortShow PasswordState where
shortShow :: PasswordState -> String
shortShow PasswordState
{ has_password :: PasswordState -> Maybe Bool
has_password = Maybe Bool
has_password_
, password_hint :: PasswordState -> Maybe Text
password_hint = Maybe Text
password_hint_
, has_recovery_email_address :: PasswordState -> Maybe Bool
has_recovery_email_address = Maybe Bool
has_recovery_email_address_
, has_passport_data :: PasswordState -> Maybe Bool
has_passport_data = Maybe Bool
has_passport_data_
, recovery_email_address_code_info :: PasswordState -> Maybe EmailAddressAuthenticationCodeInfo
recovery_email_address_code_info = Maybe EmailAddressAuthenticationCodeInfo
recovery_email_address_code_info_
, login_email_address_pattern :: PasswordState -> Maybe Text
login_email_address_pattern = Maybe Text
login_email_address_pattern_
, pending_reset_date :: PasswordState -> Maybe Int
pending_reset_date = Maybe Int
pending_reset_date_
}
= String
"PasswordState"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"has_password" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_password_
, 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_code_info" String -> Maybe EmailAddressAuthenticationCodeInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe EmailAddressAuthenticationCodeInfo
recovery_email_address_code_info_
, String
"login_email_address_pattern" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
login_email_address_pattern_
, String
"pending_reset_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
pending_reset_date_
]
instance AT.FromJSON PasswordState where
parseJSON :: Value -> Parser PasswordState
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
"passwordState" -> Value -> Parser PasswordState
parsePasswordState Value
v
String
_ -> Parser PasswordState
forall a. Monoid a => a
mempty
where
parsePasswordState :: A.Value -> AT.Parser PasswordState
parsePasswordState :: Value -> Parser PasswordState
parsePasswordState = String
-> (Object -> Parser PasswordState)
-> Value
-> Parser PasswordState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PasswordState" ((Object -> Parser PasswordState) -> Value -> Parser PasswordState)
-> (Object -> Parser PasswordState)
-> Value
-> Parser PasswordState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
has_password_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_password"
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 EmailAddressAuthenticationCodeInfo
recovery_email_address_code_info_ <- Object
o Object -> Key -> Parser (Maybe EmailAddressAuthenticationCodeInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"recovery_email_address_code_info"
Maybe Text
login_email_address_pattern_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"login_email_address_pattern"
Maybe Int
pending_reset_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"pending_reset_date"
PasswordState -> Parser PasswordState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PasswordState -> Parser PasswordState)
-> PasswordState -> Parser PasswordState
forall a b. (a -> b) -> a -> b
$ PasswordState
{ has_password :: Maybe Bool
has_password = Maybe Bool
has_password_
, 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_code_info :: Maybe EmailAddressAuthenticationCodeInfo
recovery_email_address_code_info = Maybe EmailAddressAuthenticationCodeInfo
recovery_email_address_code_info_
, login_email_address_pattern :: Maybe Text
login_email_address_pattern = Maybe Text
login_email_address_pattern_
, pending_reset_date :: Maybe Int
pending_reset_date = Maybe Int
pending_reset_date_
}
parseJSON Value
_ = Parser PasswordState
forall a. Monoid a => a
mempty