module TD.Data.TemporaryPasswordState
(TemporaryPasswordState(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data TemporaryPasswordState
= TemporaryPasswordState
{ TemporaryPasswordState -> Maybe Bool
has_password :: Maybe Bool
, TemporaryPasswordState -> Maybe Int
valid_for :: Maybe Int
}
deriving (TemporaryPasswordState -> TemporaryPasswordState -> Bool
(TemporaryPasswordState -> TemporaryPasswordState -> Bool)
-> (TemporaryPasswordState -> TemporaryPasswordState -> Bool)
-> Eq TemporaryPasswordState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TemporaryPasswordState -> TemporaryPasswordState -> Bool
== :: TemporaryPasswordState -> TemporaryPasswordState -> Bool
$c/= :: TemporaryPasswordState -> TemporaryPasswordState -> Bool
/= :: TemporaryPasswordState -> TemporaryPasswordState -> Bool
Eq, Int -> TemporaryPasswordState -> ShowS
[TemporaryPasswordState] -> ShowS
TemporaryPasswordState -> String
(Int -> TemporaryPasswordState -> ShowS)
-> (TemporaryPasswordState -> String)
-> ([TemporaryPasswordState] -> ShowS)
-> Show TemporaryPasswordState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TemporaryPasswordState -> ShowS
showsPrec :: Int -> TemporaryPasswordState -> ShowS
$cshow :: TemporaryPasswordState -> String
show :: TemporaryPasswordState -> String
$cshowList :: [TemporaryPasswordState] -> ShowS
showList :: [TemporaryPasswordState] -> ShowS
Show)
instance I.ShortShow TemporaryPasswordState where
shortShow :: TemporaryPasswordState -> String
shortShow TemporaryPasswordState
{ has_password :: TemporaryPasswordState -> Maybe Bool
has_password = Maybe Bool
has_password_
, valid_for :: TemporaryPasswordState -> Maybe Int
valid_for = Maybe Int
valid_for_
}
= String
"TemporaryPasswordState"
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
"valid_for" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
valid_for_
]
instance AT.FromJSON TemporaryPasswordState where
parseJSON :: Value -> Parser TemporaryPasswordState
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
"temporaryPasswordState" -> Value -> Parser TemporaryPasswordState
parseTemporaryPasswordState Value
v
String
_ -> Parser TemporaryPasswordState
forall a. Monoid a => a
mempty
where
parseTemporaryPasswordState :: A.Value -> AT.Parser TemporaryPasswordState
parseTemporaryPasswordState :: Value -> Parser TemporaryPasswordState
parseTemporaryPasswordState = String
-> (Object -> Parser TemporaryPasswordState)
-> Value
-> Parser TemporaryPasswordState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TemporaryPasswordState" ((Object -> Parser TemporaryPasswordState)
-> Value -> Parser TemporaryPasswordState)
-> (Object -> Parser TemporaryPasswordState)
-> Value
-> Parser TemporaryPasswordState
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 Int
valid_for_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"valid_for"
TemporaryPasswordState -> Parser TemporaryPasswordState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TemporaryPasswordState -> Parser TemporaryPasswordState)
-> TemporaryPasswordState -> Parser TemporaryPasswordState
forall a b. (a -> b) -> a -> b
$ TemporaryPasswordState
{ has_password :: Maybe Bool
has_password = Maybe Bool
has_password_
, valid_for :: Maybe Int
valid_for = Maybe Int
valid_for_
}
parseJSON Value
_ = Parser TemporaryPasswordState
forall a. Monoid a => a
mempty