module TD.Data.EmailAddressResetState
(EmailAddressResetState(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data EmailAddressResetState
= EmailAddressResetStateAvailable
{ EmailAddressResetState -> Maybe Int
wait_period :: Maybe Int
}
| EmailAddressResetStatePending
{ EmailAddressResetState -> Maybe Int
reset_in :: Maybe Int
}
deriving (EmailAddressResetState -> EmailAddressResetState -> Bool
(EmailAddressResetState -> EmailAddressResetState -> Bool)
-> (EmailAddressResetState -> EmailAddressResetState -> Bool)
-> Eq EmailAddressResetState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmailAddressResetState -> EmailAddressResetState -> Bool
== :: EmailAddressResetState -> EmailAddressResetState -> Bool
$c/= :: EmailAddressResetState -> EmailAddressResetState -> Bool
/= :: EmailAddressResetState -> EmailAddressResetState -> Bool
Eq, Int -> EmailAddressResetState -> ShowS
[EmailAddressResetState] -> ShowS
EmailAddressResetState -> String
(Int -> EmailAddressResetState -> ShowS)
-> (EmailAddressResetState -> String)
-> ([EmailAddressResetState] -> ShowS)
-> Show EmailAddressResetState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmailAddressResetState -> ShowS
showsPrec :: Int -> EmailAddressResetState -> ShowS
$cshow :: EmailAddressResetState -> String
show :: EmailAddressResetState -> String
$cshowList :: [EmailAddressResetState] -> ShowS
showList :: [EmailAddressResetState] -> ShowS
Show)
instance I.ShortShow EmailAddressResetState where
shortShow :: EmailAddressResetState -> String
shortShow EmailAddressResetStateAvailable
{ wait_period :: EmailAddressResetState -> Maybe Int
wait_period = Maybe Int
wait_period_
}
= String
"EmailAddressResetStateAvailable"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"wait_period" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
wait_period_
]
shortShow EmailAddressResetStatePending
{ reset_in :: EmailAddressResetState -> Maybe Int
reset_in = Maybe Int
reset_in_
}
= String
"EmailAddressResetStatePending"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"reset_in" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
reset_in_
]
instance AT.FromJSON EmailAddressResetState where
parseJSON :: Value -> Parser EmailAddressResetState
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
"emailAddressResetStateAvailable" -> Value -> Parser EmailAddressResetState
parseEmailAddressResetStateAvailable Value
v
String
"emailAddressResetStatePending" -> Value -> Parser EmailAddressResetState
parseEmailAddressResetStatePending Value
v
String
_ -> Parser EmailAddressResetState
forall a. Monoid a => a
mempty
where
parseEmailAddressResetStateAvailable :: A.Value -> AT.Parser EmailAddressResetState
parseEmailAddressResetStateAvailable :: Value -> Parser EmailAddressResetState
parseEmailAddressResetStateAvailable = String
-> (Object -> Parser EmailAddressResetState)
-> Value
-> Parser EmailAddressResetState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"EmailAddressResetStateAvailable" ((Object -> Parser EmailAddressResetState)
-> Value -> Parser EmailAddressResetState)
-> (Object -> Parser EmailAddressResetState)
-> Value
-> Parser EmailAddressResetState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
wait_period_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"wait_period"
EmailAddressResetState -> Parser EmailAddressResetState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EmailAddressResetState -> Parser EmailAddressResetState)
-> EmailAddressResetState -> Parser EmailAddressResetState
forall a b. (a -> b) -> a -> b
$ EmailAddressResetStateAvailable
{ wait_period :: Maybe Int
wait_period = Maybe Int
wait_period_
}
parseEmailAddressResetStatePending :: A.Value -> AT.Parser EmailAddressResetState
parseEmailAddressResetStatePending :: Value -> Parser EmailAddressResetState
parseEmailAddressResetStatePending = String
-> (Object -> Parser EmailAddressResetState)
-> Value
-> Parser EmailAddressResetState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"EmailAddressResetStatePending" ((Object -> Parser EmailAddressResetState)
-> Value -> Parser EmailAddressResetState)
-> (Object -> Parser EmailAddressResetState)
-> Value
-> Parser EmailAddressResetState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
reset_in_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reset_in"
EmailAddressResetState -> Parser EmailAddressResetState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EmailAddressResetState -> Parser EmailAddressResetState)
-> EmailAddressResetState -> Parser EmailAddressResetState
forall a b. (a -> b) -> a -> b
$ EmailAddressResetStatePending
{ reset_in :: Maybe Int
reset_in = Maybe Int
reset_in_
}
parseJSON Value
_ = Parser EmailAddressResetState
forall a. Monoid a => a
mempty