module TD.Data.PaymentOption
(PaymentOption(..)) 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 PaymentOption
= PaymentOption
{ PaymentOption -> Maybe Text
title :: Maybe T.Text
, PaymentOption -> Maybe Text
url :: Maybe T.Text
}
deriving (PaymentOption -> PaymentOption -> Bool
(PaymentOption -> PaymentOption -> Bool)
-> (PaymentOption -> PaymentOption -> Bool) -> Eq PaymentOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PaymentOption -> PaymentOption -> Bool
== :: PaymentOption -> PaymentOption -> Bool
$c/= :: PaymentOption -> PaymentOption -> Bool
/= :: PaymentOption -> PaymentOption -> Bool
Eq, Int -> PaymentOption -> ShowS
[PaymentOption] -> ShowS
PaymentOption -> String
(Int -> PaymentOption -> ShowS)
-> (PaymentOption -> String)
-> ([PaymentOption] -> ShowS)
-> Show PaymentOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PaymentOption -> ShowS
showsPrec :: Int -> PaymentOption -> ShowS
$cshow :: PaymentOption -> String
show :: PaymentOption -> String
$cshowList :: [PaymentOption] -> ShowS
showList :: [PaymentOption] -> ShowS
Show)
instance I.ShortShow PaymentOption where
shortShow :: PaymentOption -> String
shortShow PaymentOption
{ title :: PaymentOption -> Maybe Text
title = Maybe Text
title_
, url :: PaymentOption -> Maybe Text
url = Maybe Text
url_
}
= String
"PaymentOption"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
]
instance AT.FromJSON PaymentOption where
parseJSON :: Value -> Parser PaymentOption
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
"paymentOption" -> Value -> Parser PaymentOption
parsePaymentOption Value
v
String
_ -> Parser PaymentOption
forall a. Monoid a => a
mempty
where
parsePaymentOption :: A.Value -> AT.Parser PaymentOption
parsePaymentOption :: Value -> Parser PaymentOption
parsePaymentOption = String
-> (Object -> Parser PaymentOption)
-> Value
-> Parser PaymentOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaymentOption" ((Object -> Parser PaymentOption) -> Value -> Parser PaymentOption)
-> (Object -> Parser PaymentOption)
-> Value
-> Parser PaymentOption
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
PaymentOption -> Parser PaymentOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaymentOption -> Parser PaymentOption)
-> PaymentOption -> Parser PaymentOption
forall a b. (a -> b) -> a -> b
$ PaymentOption
{ title :: Maybe Text
title = Maybe Text
title_
, url :: Maybe Text
url = Maybe Text
url_
}
parseJSON Value
_ = Parser PaymentOption
forall a. Monoid a => a
mempty