module TD.Data.PremiumGiftPaymentOption
  (PremiumGiftPaymentOption(..)) 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.Sticker as Sticker

data PremiumGiftPaymentOption
  = PremiumGiftPaymentOption -- ^ Describes an option for gifting Telegram Premium to a user. Use telegramPaymentPurposePremiumGift for out-of-store payments or payments in Telegram Stars
    { PremiumGiftPaymentOption -> Maybe Text
currency            :: Maybe T.Text          -- ^ ISO 4217 currency code for the payment
    , PremiumGiftPaymentOption -> Maybe Int
amount              :: Maybe Int             -- ^ The amount to pay, in the smallest units of the currency
    , PremiumGiftPaymentOption -> Maybe Int
star_count          :: Maybe Int             -- ^ The alternative amount of Telegram Stars to pay; 0 if payment in Telegram Stars is not possible
    , PremiumGiftPaymentOption -> Maybe Int
discount_percentage :: Maybe Int             -- ^ The discount associated with this option, as a percentage
    , PremiumGiftPaymentOption -> Maybe Int
month_count         :: Maybe Int             -- ^ Number of months the Telegram Premium subscription will be active
    , PremiumGiftPaymentOption -> Maybe Text
store_product_id    :: Maybe T.Text          -- ^ Identifier of the store product associated with the option
    , PremiumGiftPaymentOption -> Maybe Sticker
sticker             :: Maybe Sticker.Sticker -- ^ A sticker to be shown along with the option; may be null if unknown
    }
  deriving (PremiumGiftPaymentOption -> PremiumGiftPaymentOption -> Bool
(PremiumGiftPaymentOption -> PremiumGiftPaymentOption -> Bool)
-> (PremiumGiftPaymentOption -> PremiumGiftPaymentOption -> Bool)
-> Eq PremiumGiftPaymentOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PremiumGiftPaymentOption -> PremiumGiftPaymentOption -> Bool
== :: PremiumGiftPaymentOption -> PremiumGiftPaymentOption -> Bool
$c/= :: PremiumGiftPaymentOption -> PremiumGiftPaymentOption -> Bool
/= :: PremiumGiftPaymentOption -> PremiumGiftPaymentOption -> Bool
Eq, Int -> PremiumGiftPaymentOption -> ShowS
[PremiumGiftPaymentOption] -> ShowS
PremiumGiftPaymentOption -> String
(Int -> PremiumGiftPaymentOption -> ShowS)
-> (PremiumGiftPaymentOption -> String)
-> ([PremiumGiftPaymentOption] -> ShowS)
-> Show PremiumGiftPaymentOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PremiumGiftPaymentOption -> ShowS
showsPrec :: Int -> PremiumGiftPaymentOption -> ShowS
$cshow :: PremiumGiftPaymentOption -> String
show :: PremiumGiftPaymentOption -> String
$cshowList :: [PremiumGiftPaymentOption] -> ShowS
showList :: [PremiumGiftPaymentOption] -> ShowS
Show)

instance I.ShortShow PremiumGiftPaymentOption where
  shortShow :: PremiumGiftPaymentOption -> String
shortShow PremiumGiftPaymentOption
    { currency :: PremiumGiftPaymentOption -> Maybe Text
currency            = Maybe Text
currency_
    , amount :: PremiumGiftPaymentOption -> Maybe Int
amount              = Maybe Int
amount_
    , star_count :: PremiumGiftPaymentOption -> Maybe Int
star_count          = Maybe Int
star_count_
    , discount_percentage :: PremiumGiftPaymentOption -> Maybe Int
discount_percentage = Maybe Int
discount_percentage_
    , month_count :: PremiumGiftPaymentOption -> Maybe Int
month_count         = Maybe Int
month_count_
    , store_product_id :: PremiumGiftPaymentOption -> Maybe Text
store_product_id    = Maybe Text
store_product_id_
    , sticker :: PremiumGiftPaymentOption -> Maybe Sticker
sticker             = Maybe Sticker
sticker_
    }
      = String
"PremiumGiftPaymentOption"
        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
"star_count"          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
        , 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
"sticker"             String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
sticker_
        ]

instance AT.FromJSON PremiumGiftPaymentOption where
  parseJSON :: Value -> Parser PremiumGiftPaymentOption
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
"premiumGiftPaymentOption" -> Value -> Parser PremiumGiftPaymentOption
parsePremiumGiftPaymentOption Value
v
      String
_                          -> Parser PremiumGiftPaymentOption
forall a. Monoid a => a
mempty
    
    where
      parsePremiumGiftPaymentOption :: A.Value -> AT.Parser PremiumGiftPaymentOption
      parsePremiumGiftPaymentOption :: Value -> Parser PremiumGiftPaymentOption
parsePremiumGiftPaymentOption = String
-> (Object -> Parser PremiumGiftPaymentOption)
-> Value
-> Parser PremiumGiftPaymentOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PremiumGiftPaymentOption" ((Object -> Parser PremiumGiftPaymentOption)
 -> Value -> Parser PremiumGiftPaymentOption)
-> (Object -> Parser PremiumGiftPaymentOption)
-> Value
-> Parser PremiumGiftPaymentOption
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
star_count_          <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"star_count"
        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 Sticker
sticker_             <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sticker"
        PremiumGiftPaymentOption -> Parser PremiumGiftPaymentOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PremiumGiftPaymentOption -> Parser PremiumGiftPaymentOption)
-> PremiumGiftPaymentOption -> Parser PremiumGiftPaymentOption
forall a b. (a -> b) -> a -> b
$ PremiumGiftPaymentOption
          { currency :: Maybe Text
currency            = Maybe Text
currency_
          , amount :: Maybe Int
amount              = Maybe Int
amount_
          , star_count :: Maybe Int
star_count          = Maybe Int
star_count_
          , 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_
          , sticker :: Maybe Sticker
sticker             = Maybe Sticker
sticker_
          }
  parseJSON Value
_ = Parser PremiumGiftPaymentOption
forall a. Monoid a => a
mempty