module TD.Data.PremiumPaymentOption
(PremiumPaymentOption(..)) 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.InternalLinkType as InternalLinkType
data PremiumPaymentOption
= PremiumPaymentOption
{ PremiumPaymentOption -> Maybe Text
currency :: Maybe T.Text
, PremiumPaymentOption -> Maybe Int
amount :: Maybe Int
, PremiumPaymentOption -> Maybe Int
discount_percentage :: Maybe Int
, PremiumPaymentOption -> Maybe Int
month_count :: Maybe Int
, PremiumPaymentOption -> Maybe Text
store_product_id :: Maybe T.Text
, PremiumPaymentOption -> Maybe InternalLinkType
payment_link :: Maybe InternalLinkType.InternalLinkType
}
deriving (PremiumPaymentOption -> PremiumPaymentOption -> Bool
(PremiumPaymentOption -> PremiumPaymentOption -> Bool)
-> (PremiumPaymentOption -> PremiumPaymentOption -> Bool)
-> Eq PremiumPaymentOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PremiumPaymentOption -> PremiumPaymentOption -> Bool
== :: PremiumPaymentOption -> PremiumPaymentOption -> Bool
$c/= :: PremiumPaymentOption -> PremiumPaymentOption -> Bool
/= :: PremiumPaymentOption -> PremiumPaymentOption -> Bool
Eq, Int -> PremiumPaymentOption -> ShowS
[PremiumPaymentOption] -> ShowS
PremiumPaymentOption -> String
(Int -> PremiumPaymentOption -> ShowS)
-> (PremiumPaymentOption -> String)
-> ([PremiumPaymentOption] -> ShowS)
-> Show PremiumPaymentOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PremiumPaymentOption -> ShowS
showsPrec :: Int -> PremiumPaymentOption -> ShowS
$cshow :: PremiumPaymentOption -> String
show :: PremiumPaymentOption -> String
$cshowList :: [PremiumPaymentOption] -> ShowS
showList :: [PremiumPaymentOption] -> ShowS
Show)
instance I.ShortShow PremiumPaymentOption where
shortShow :: PremiumPaymentOption -> String
shortShow PremiumPaymentOption
{ currency :: PremiumPaymentOption -> Maybe Text
currency = Maybe Text
currency_
, amount :: PremiumPaymentOption -> Maybe Int
amount = Maybe Int
amount_
, discount_percentage :: PremiumPaymentOption -> Maybe Int
discount_percentage = Maybe Int
discount_percentage_
, month_count :: PremiumPaymentOption -> Maybe Int
month_count = Maybe Int
month_count_
, store_product_id :: PremiumPaymentOption -> Maybe Text
store_product_id = Maybe Text
store_product_id_
, payment_link :: PremiumPaymentOption -> Maybe InternalLinkType
payment_link = Maybe InternalLinkType
payment_link_
}
= String
"PremiumPaymentOption"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"currency" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
currency_
, String
"amount" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
amount_
, String
"discount_percentage" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
discount_percentage_
, String
"month_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
month_count_
, String
"store_product_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
store_product_id_
, String
"payment_link" String -> Maybe InternalLinkType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InternalLinkType
payment_link_
]
instance AT.FromJSON PremiumPaymentOption where
parseJSON :: Value -> Parser PremiumPaymentOption
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
"premiumPaymentOption" -> Value -> Parser PremiumPaymentOption
parsePremiumPaymentOption Value
v
String
_ -> Parser PremiumPaymentOption
forall a. Monoid a => a
mempty
where
parsePremiumPaymentOption :: A.Value -> AT.Parser PremiumPaymentOption
parsePremiumPaymentOption :: Value -> Parser PremiumPaymentOption
parsePremiumPaymentOption = String
-> (Object -> Parser PremiumPaymentOption)
-> Value
-> Parser PremiumPaymentOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PremiumPaymentOption" ((Object -> Parser PremiumPaymentOption)
-> Value -> Parser PremiumPaymentOption)
-> (Object -> Parser PremiumPaymentOption)
-> Value
-> Parser PremiumPaymentOption
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
currency_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"currency"
Maybe Int
amount_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"amount"
Maybe Int
discount_percentage_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"discount_percentage"
Maybe Int
month_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"month_count"
Maybe Text
store_product_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"store_product_id"
Maybe InternalLinkType
payment_link_ <- Object
o Object -> Key -> Parser (Maybe InternalLinkType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"payment_link"
PremiumPaymentOption -> Parser PremiumPaymentOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PremiumPaymentOption -> Parser PremiumPaymentOption)
-> PremiumPaymentOption -> Parser PremiumPaymentOption
forall a b. (a -> b) -> a -> b
$ PremiumPaymentOption
{ currency :: Maybe Text
currency = Maybe Text
currency_
, amount :: Maybe Int
amount = Maybe Int
amount_
, discount_percentage :: Maybe Int
discount_percentage = Maybe Int
discount_percentage_
, month_count :: Maybe Int
month_count = Maybe Int
month_count_
, store_product_id :: Maybe Text
store_product_id = Maybe Text
store_product_id_
, payment_link :: Maybe InternalLinkType
payment_link = Maybe InternalLinkType
payment_link_
}
parseJSON Value
_ = Parser PremiumPaymentOption
forall a. Monoid a => a
mempty