module TD.Data.ChatRevenueTransaction
(ChatRevenueTransaction(..)) 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.ChatRevenueTransactionType as ChatRevenueTransactionType
data ChatRevenueTransaction
= ChatRevenueTransaction
{ ChatRevenueTransaction -> Maybe Text
cryptocurrency :: Maybe T.Text
, ChatRevenueTransaction -> Maybe Int
cryptocurrency_amount :: Maybe Int
, ChatRevenueTransaction -> Maybe ChatRevenueTransactionType
_type :: Maybe ChatRevenueTransactionType.ChatRevenueTransactionType
}
deriving (ChatRevenueTransaction -> ChatRevenueTransaction -> Bool
(ChatRevenueTransaction -> ChatRevenueTransaction -> Bool)
-> (ChatRevenueTransaction -> ChatRevenueTransaction -> Bool)
-> Eq ChatRevenueTransaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatRevenueTransaction -> ChatRevenueTransaction -> Bool
== :: ChatRevenueTransaction -> ChatRevenueTransaction -> Bool
$c/= :: ChatRevenueTransaction -> ChatRevenueTransaction -> Bool
/= :: ChatRevenueTransaction -> ChatRevenueTransaction -> Bool
Eq, Int -> ChatRevenueTransaction -> ShowS
[ChatRevenueTransaction] -> ShowS
ChatRevenueTransaction -> String
(Int -> ChatRevenueTransaction -> ShowS)
-> (ChatRevenueTransaction -> String)
-> ([ChatRevenueTransaction] -> ShowS)
-> Show ChatRevenueTransaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatRevenueTransaction -> ShowS
showsPrec :: Int -> ChatRevenueTransaction -> ShowS
$cshow :: ChatRevenueTransaction -> String
show :: ChatRevenueTransaction -> String
$cshowList :: [ChatRevenueTransaction] -> ShowS
showList :: [ChatRevenueTransaction] -> ShowS
Show)
instance I.ShortShow ChatRevenueTransaction where
shortShow :: ChatRevenueTransaction -> String
shortShow ChatRevenueTransaction
{ cryptocurrency :: ChatRevenueTransaction -> Maybe Text
cryptocurrency = Maybe Text
cryptocurrency_
, cryptocurrency_amount :: ChatRevenueTransaction -> Maybe Int
cryptocurrency_amount = Maybe Int
cryptocurrency_amount_
, _type :: ChatRevenueTransaction -> Maybe ChatRevenueTransactionType
_type = Maybe ChatRevenueTransactionType
_type_
}
= String
"ChatRevenueTransaction"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"cryptocurrency" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
cryptocurrency_
, String
"cryptocurrency_amount" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
cryptocurrency_amount_
, String
"_type" String -> Maybe ChatRevenueTransactionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatRevenueTransactionType
_type_
]
instance AT.FromJSON ChatRevenueTransaction where
parseJSON :: Value -> Parser ChatRevenueTransaction
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
"chatRevenueTransaction" -> Value -> Parser ChatRevenueTransaction
parseChatRevenueTransaction Value
v
String
_ -> Parser ChatRevenueTransaction
forall a. Monoid a => a
mempty
where
parseChatRevenueTransaction :: A.Value -> AT.Parser ChatRevenueTransaction
parseChatRevenueTransaction :: Value -> Parser ChatRevenueTransaction
parseChatRevenueTransaction = String
-> (Object -> Parser ChatRevenueTransaction)
-> Value
-> Parser ChatRevenueTransaction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatRevenueTransaction" ((Object -> Parser ChatRevenueTransaction)
-> Value -> Parser ChatRevenueTransaction)
-> (Object -> Parser ChatRevenueTransaction)
-> Value
-> Parser ChatRevenueTransaction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
cryptocurrency_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"cryptocurrency"
Maybe Int
cryptocurrency_amount_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"cryptocurrency_amount"
Maybe ChatRevenueTransactionType
_type_ <- Object
o Object -> Key -> Parser (Maybe ChatRevenueTransactionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
ChatRevenueTransaction -> Parser ChatRevenueTransaction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatRevenueTransaction -> Parser ChatRevenueTransaction)
-> ChatRevenueTransaction -> Parser ChatRevenueTransaction
forall a b. (a -> b) -> a -> b
$ ChatRevenueTransaction
{ cryptocurrency :: Maybe Text
cryptocurrency = Maybe Text
cryptocurrency_
, cryptocurrency_amount :: Maybe Int
cryptocurrency_amount = Maybe Int
cryptocurrency_amount_
, _type :: Maybe ChatRevenueTransactionType
_type = Maybe ChatRevenueTransactionType
_type_
}
parseJSON Value
_ = Parser ChatRevenueTransaction
forall a. Monoid a => a
mempty