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