module TD.Data.InputCredentials
(InputCredentials(..)) 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 InputCredentials
= InputCredentialsSaved
{ InputCredentials -> Maybe Text
saved_credentials_id :: Maybe T.Text
}
| InputCredentialsNew
{ InputCredentials -> Maybe Text
_data :: Maybe T.Text
, InputCredentials -> Maybe Bool
allow_save :: Maybe Bool
}
| InputCredentialsApplePay
{ _data :: Maybe T.Text
}
| InputCredentialsGooglePay
{ _data :: Maybe T.Text
}
deriving (InputCredentials -> InputCredentials -> Bool
(InputCredentials -> InputCredentials -> Bool)
-> (InputCredentials -> InputCredentials -> Bool)
-> Eq InputCredentials
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputCredentials -> InputCredentials -> Bool
== :: InputCredentials -> InputCredentials -> Bool
$c/= :: InputCredentials -> InputCredentials -> Bool
/= :: InputCredentials -> InputCredentials -> Bool
Eq, Int -> InputCredentials -> ShowS
[InputCredentials] -> ShowS
InputCredentials -> String
(Int -> InputCredentials -> ShowS)
-> (InputCredentials -> String)
-> ([InputCredentials] -> ShowS)
-> Show InputCredentials
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputCredentials -> ShowS
showsPrec :: Int -> InputCredentials -> ShowS
$cshow :: InputCredentials -> String
show :: InputCredentials -> String
$cshowList :: [InputCredentials] -> ShowS
showList :: [InputCredentials] -> ShowS
Show)
instance I.ShortShow InputCredentials where
shortShow :: InputCredentials -> String
shortShow InputCredentialsSaved
{ saved_credentials_id :: InputCredentials -> Maybe Text
saved_credentials_id = Maybe Text
saved_credentials_id_
}
= String
"InputCredentialsSaved"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"saved_credentials_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
saved_credentials_id_
]
shortShow InputCredentialsNew
{ _data :: InputCredentials -> Maybe Text
_data = Maybe Text
_data_
, allow_save :: InputCredentials -> Maybe Bool
allow_save = Maybe Bool
allow_save_
}
= String
"InputCredentialsNew"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_data" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_data_
, String
"allow_save" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_save_
]
shortShow InputCredentialsApplePay
{ _data :: InputCredentials -> Maybe Text
_data = Maybe Text
_data_
}
= String
"InputCredentialsApplePay"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_data" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_data_
]
shortShow InputCredentialsGooglePay
{ _data :: InputCredentials -> Maybe Text
_data = Maybe Text
_data_
}
= String
"InputCredentialsGooglePay"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_data" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_data_
]
instance AT.FromJSON InputCredentials where
parseJSON :: Value -> Parser InputCredentials
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
"inputCredentialsSaved" -> Value -> Parser InputCredentials
parseInputCredentialsSaved Value
v
String
"inputCredentialsNew" -> Value -> Parser InputCredentials
parseInputCredentialsNew Value
v
String
"inputCredentialsApplePay" -> Value -> Parser InputCredentials
parseInputCredentialsApplePay Value
v
String
"inputCredentialsGooglePay" -> Value -> Parser InputCredentials
parseInputCredentialsGooglePay Value
v
String
_ -> Parser InputCredentials
forall a. Monoid a => a
mempty
where
parseInputCredentialsSaved :: A.Value -> AT.Parser InputCredentials
parseInputCredentialsSaved :: Value -> Parser InputCredentials
parseInputCredentialsSaved = String
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputCredentialsSaved" ((Object -> Parser InputCredentials)
-> Value -> Parser InputCredentials)
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
saved_credentials_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"saved_credentials_id"
InputCredentials -> Parser InputCredentials
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputCredentials -> Parser InputCredentials)
-> InputCredentials -> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ InputCredentialsSaved
{ saved_credentials_id :: Maybe Text
saved_credentials_id = Maybe Text
saved_credentials_id_
}
parseInputCredentialsNew :: A.Value -> AT.Parser InputCredentials
parseInputCredentialsNew :: Value -> Parser InputCredentials
parseInputCredentialsNew = String
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputCredentialsNew" ((Object -> Parser InputCredentials)
-> Value -> Parser InputCredentials)
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
_data_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"data"
Maybe Bool
allow_save_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_save"
InputCredentials -> Parser InputCredentials
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputCredentials -> Parser InputCredentials)
-> InputCredentials -> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ InputCredentialsNew
{ _data :: Maybe Text
_data = Maybe Text
_data_
, allow_save :: Maybe Bool
allow_save = Maybe Bool
allow_save_
}
parseInputCredentialsApplePay :: A.Value -> AT.Parser InputCredentials
parseInputCredentialsApplePay :: Value -> Parser InputCredentials
parseInputCredentialsApplePay = String
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputCredentialsApplePay" ((Object -> Parser InputCredentials)
-> Value -> Parser InputCredentials)
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
_data_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"data"
InputCredentials -> Parser InputCredentials
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputCredentials -> Parser InputCredentials)
-> InputCredentials -> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ InputCredentialsApplePay
{ _data :: Maybe Text
_data = Maybe Text
_data_
}
parseInputCredentialsGooglePay :: A.Value -> AT.Parser InputCredentials
parseInputCredentialsGooglePay :: Value -> Parser InputCredentials
parseInputCredentialsGooglePay = String
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputCredentialsGooglePay" ((Object -> Parser InputCredentials)
-> Value -> Parser InputCredentials)
-> (Object -> Parser InputCredentials)
-> Value
-> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
_data_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"data"
InputCredentials -> Parser InputCredentials
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputCredentials -> Parser InputCredentials)
-> InputCredentials -> Parser InputCredentials
forall a b. (a -> b) -> a -> b
$ InputCredentialsGooglePay
{ _data :: Maybe Text
_data = Maybe Text
_data_
}
parseJSON Value
_ = Parser InputCredentials
forall a. Monoid a => a
mempty
instance AT.ToJSON InputCredentials where
toJSON :: InputCredentials -> Value
toJSON InputCredentialsSaved
{ saved_credentials_id :: InputCredentials -> Maybe Text
saved_credentials_id = Maybe Text
saved_credentials_id_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputCredentialsSaved"
, Key
"saved_credentials_id" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
saved_credentials_id_
]
toJSON InputCredentialsNew
{ _data :: InputCredentials -> Maybe Text
_data = Maybe Text
_data_
, allow_save :: InputCredentials -> Maybe Bool
allow_save = Maybe Bool
allow_save_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputCredentialsNew"
, Key
"data" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_data_
, Key
"allow_save" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_save_
]
toJSON InputCredentialsApplePay
{ _data :: InputCredentials -> Maybe Text
_data = Maybe Text
_data_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputCredentialsApplePay"
, Key
"data" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_data_
]
toJSON InputCredentialsGooglePay
{ _data :: InputCredentials -> Maybe Text
_data = Maybe Text
_data_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputCredentialsGooglePay"
, Key
"data" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_data_
]