module TD.Data.PaymentReceipt
(PaymentReceipt(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.ProductInfo as ProductInfo
import qualified TD.Data.PaymentReceiptType as PaymentReceiptType
data PaymentReceipt
= PaymentReceipt
{ PaymentReceipt -> Maybe ProductInfo
product_info :: Maybe ProductInfo.ProductInfo
, PaymentReceipt -> Maybe Int
date :: Maybe Int
, PaymentReceipt -> Maybe Int
seller_bot_user_id :: Maybe Int
, PaymentReceipt -> Maybe PaymentReceiptType
_type :: Maybe PaymentReceiptType.PaymentReceiptType
}
deriving (PaymentReceipt -> PaymentReceipt -> Bool
(PaymentReceipt -> PaymentReceipt -> Bool)
-> (PaymentReceipt -> PaymentReceipt -> Bool) -> Eq PaymentReceipt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PaymentReceipt -> PaymentReceipt -> Bool
== :: PaymentReceipt -> PaymentReceipt -> Bool
$c/= :: PaymentReceipt -> PaymentReceipt -> Bool
/= :: PaymentReceipt -> PaymentReceipt -> Bool
Eq, Int -> PaymentReceipt -> ShowS
[PaymentReceipt] -> ShowS
PaymentReceipt -> String
(Int -> PaymentReceipt -> ShowS)
-> (PaymentReceipt -> String)
-> ([PaymentReceipt] -> ShowS)
-> Show PaymentReceipt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PaymentReceipt -> ShowS
showsPrec :: Int -> PaymentReceipt -> ShowS
$cshow :: PaymentReceipt -> String
show :: PaymentReceipt -> String
$cshowList :: [PaymentReceipt] -> ShowS
showList :: [PaymentReceipt] -> ShowS
Show)
instance I.ShortShow PaymentReceipt where
shortShow :: PaymentReceipt -> String
shortShow PaymentReceipt
{ product_info :: PaymentReceipt -> Maybe ProductInfo
product_info = Maybe ProductInfo
product_info_
, date :: PaymentReceipt -> Maybe Int
date = Maybe Int
date_
, seller_bot_user_id :: PaymentReceipt -> Maybe Int
seller_bot_user_id = Maybe Int
seller_bot_user_id_
, _type :: PaymentReceipt -> Maybe PaymentReceiptType
_type = Maybe PaymentReceiptType
_type_
}
= String
"PaymentReceipt"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"product_info" String -> Maybe ProductInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ProductInfo
product_info_
, String
"date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
, String
"seller_bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
seller_bot_user_id_
, String
"_type" String -> Maybe PaymentReceiptType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe PaymentReceiptType
_type_
]
instance AT.FromJSON PaymentReceipt where
parseJSON :: Value -> Parser PaymentReceipt
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
"paymentReceipt" -> Value -> Parser PaymentReceipt
parsePaymentReceipt Value
v
String
_ -> Parser PaymentReceipt
forall a. Monoid a => a
mempty
where
parsePaymentReceipt :: A.Value -> AT.Parser PaymentReceipt
parsePaymentReceipt :: Value -> Parser PaymentReceipt
parsePaymentReceipt = String
-> (Object -> Parser PaymentReceipt)
-> Value
-> Parser PaymentReceipt
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaymentReceipt" ((Object -> Parser PaymentReceipt)
-> Value -> Parser PaymentReceipt)
-> (Object -> Parser PaymentReceipt)
-> Value
-> Parser PaymentReceipt
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ProductInfo
product_info_ <- Object
o Object -> Key -> Parser (Maybe ProductInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"product_info"
Maybe Int
date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"date"
Maybe Int
seller_bot_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"seller_bot_user_id"
Maybe PaymentReceiptType
_type_ <- Object
o Object -> Key -> Parser (Maybe PaymentReceiptType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
PaymentReceipt -> Parser PaymentReceipt
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaymentReceipt -> Parser PaymentReceipt)
-> PaymentReceipt -> Parser PaymentReceipt
forall a b. (a -> b) -> a -> b
$ PaymentReceipt
{ product_info :: Maybe ProductInfo
product_info = Maybe ProductInfo
product_info_
, date :: Maybe Int
date = Maybe Int
date_
, seller_bot_user_id :: Maybe Int
seller_bot_user_id = Maybe Int
seller_bot_user_id_
, _type :: Maybe PaymentReceiptType
_type = Maybe PaymentReceiptType
_type_
}
parseJSON Value
_ = Parser PaymentReceipt
forall a. Monoid a => a
mempty