module TD.Data.TonTransactionType
(TonTransactionType(..)) 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.Sticker as Sticker
data TonTransactionType
= TonTransactionTypeFragmentDeposit
{ TonTransactionType -> Maybe Bool
is_gift :: Maybe Bool
, TonTransactionType -> Maybe Sticker
sticker :: Maybe Sticker.Sticker
}
| TonTransactionTypeSuggestedPostPayment
{ TonTransactionType -> Maybe Int
chat_id :: Maybe Int
}
| TonTransactionTypeUnsupported
deriving (TonTransactionType -> TonTransactionType -> Bool
(TonTransactionType -> TonTransactionType -> Bool)
-> (TonTransactionType -> TonTransactionType -> Bool)
-> Eq TonTransactionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TonTransactionType -> TonTransactionType -> Bool
== :: TonTransactionType -> TonTransactionType -> Bool
$c/= :: TonTransactionType -> TonTransactionType -> Bool
/= :: TonTransactionType -> TonTransactionType -> Bool
Eq, Int -> TonTransactionType -> ShowS
[TonTransactionType] -> ShowS
TonTransactionType -> String
(Int -> TonTransactionType -> ShowS)
-> (TonTransactionType -> String)
-> ([TonTransactionType] -> ShowS)
-> Show TonTransactionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TonTransactionType -> ShowS
showsPrec :: Int -> TonTransactionType -> ShowS
$cshow :: TonTransactionType -> String
show :: TonTransactionType -> String
$cshowList :: [TonTransactionType] -> ShowS
showList :: [TonTransactionType] -> ShowS
Show)
instance I.ShortShow TonTransactionType where
shortShow :: TonTransactionType -> String
shortShow TonTransactionTypeFragmentDeposit
{ is_gift :: TonTransactionType -> Maybe Bool
is_gift = Maybe Bool
is_gift_
, sticker :: TonTransactionType -> Maybe Sticker
sticker = Maybe Sticker
sticker_
}
= String
"TonTransactionTypeFragmentDeposit"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"is_gift" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_gift_
, String
"sticker" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
sticker_
]
shortShow TonTransactionTypeSuggestedPostPayment
{ chat_id :: TonTransactionType -> Maybe Int
chat_id = Maybe Int
chat_id_
}
= String
"TonTransactionTypeSuggestedPostPayment"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
]
shortShow TonTransactionType
TonTransactionTypeUnsupported
= String
"TonTransactionTypeUnsupported"
instance AT.FromJSON TonTransactionType where
parseJSON :: Value -> Parser TonTransactionType
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
"tonTransactionTypeFragmentDeposit" -> Value -> Parser TonTransactionType
parseTonTransactionTypeFragmentDeposit Value
v
String
"tonTransactionTypeSuggestedPostPayment" -> Value -> Parser TonTransactionType
parseTonTransactionTypeSuggestedPostPayment Value
v
String
"tonTransactionTypeUnsupported" -> TonTransactionType -> Parser TonTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TonTransactionType
TonTransactionTypeUnsupported
String
_ -> Parser TonTransactionType
forall a. Monoid a => a
mempty
where
parseTonTransactionTypeFragmentDeposit :: A.Value -> AT.Parser TonTransactionType
parseTonTransactionTypeFragmentDeposit :: Value -> Parser TonTransactionType
parseTonTransactionTypeFragmentDeposit = String
-> (Object -> Parser TonTransactionType)
-> Value
-> Parser TonTransactionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonTransactionTypeFragmentDeposit" ((Object -> Parser TonTransactionType)
-> Value -> Parser TonTransactionType)
-> (Object -> Parser TonTransactionType)
-> Value
-> Parser TonTransactionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
is_gift_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_gift"
Maybe Sticker
sticker_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sticker"
TonTransactionType -> Parser TonTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonTransactionType -> Parser TonTransactionType)
-> TonTransactionType -> Parser TonTransactionType
forall a b. (a -> b) -> a -> b
$ TonTransactionTypeFragmentDeposit
{ is_gift :: Maybe Bool
is_gift = Maybe Bool
is_gift_
, sticker :: Maybe Sticker
sticker = Maybe Sticker
sticker_
}
parseTonTransactionTypeSuggestedPostPayment :: A.Value -> AT.Parser TonTransactionType
parseTonTransactionTypeSuggestedPostPayment :: Value -> Parser TonTransactionType
parseTonTransactionTypeSuggestedPostPayment = String
-> (Object -> Parser TonTransactionType)
-> Value
-> Parser TonTransactionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonTransactionTypeSuggestedPostPayment" ((Object -> Parser TonTransactionType)
-> Value -> Parser TonTransactionType)
-> (Object -> Parser TonTransactionType)
-> Value
-> Parser TonTransactionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
TonTransactionType -> Parser TonTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonTransactionType -> Parser TonTransactionType)
-> TonTransactionType -> Parser TonTransactionType
forall a b. (a -> b) -> a -> b
$ TonTransactionTypeSuggestedPostPayment
{ chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
}
parseJSON Value
_ = Parser TonTransactionType
forall a. Monoid a => a
mempty