module TD.Data.PremiumGiftCodePaymentOption
  (PremiumGiftCodePaymentOption(..)) 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

data PremiumGiftCodePaymentOption
  = PremiumGiftCodePaymentOption -- ^ Describes an option for creating Telegram Premium gift codes or Telegram Premium giveaway. Use telegramPaymentPurposePremiumGiftCodes or telegramPaymentPurposePremiumGiveaway for out-of-store payments
    { PremiumGiftCodePaymentOption -> Maybe Text
currency               :: Maybe T.Text -- ^ ISO 4217 currency code for Telegram Premium gift code payment
    , PremiumGiftCodePaymentOption -> Maybe Int
amount                 :: Maybe Int    -- ^ The amount to pay, in the smallest units of the currency
    , PremiumGiftCodePaymentOption -> Maybe Int
winner_count           :: Maybe Int    -- ^ Number of users which will be able to activate the gift codes
    , PremiumGiftCodePaymentOption -> Maybe Int
month_count            :: Maybe Int    -- ^ Number of months the Telegram Premium subscription will be active
    , PremiumGiftCodePaymentOption -> Maybe Text
store_product_id       :: Maybe T.Text -- ^ Identifier of the store product associated with the option; may be empty if none
    , PremiumGiftCodePaymentOption -> Maybe Int
store_product_quantity :: Maybe Int    -- ^ Number of times the store product must be paid
    }
  deriving (PremiumGiftCodePaymentOption
-> PremiumGiftCodePaymentOption -> Bool
(PremiumGiftCodePaymentOption
 -> PremiumGiftCodePaymentOption -> Bool)
-> (PremiumGiftCodePaymentOption
    -> PremiumGiftCodePaymentOption -> Bool)
-> Eq PremiumGiftCodePaymentOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PremiumGiftCodePaymentOption
-> PremiumGiftCodePaymentOption -> Bool
== :: PremiumGiftCodePaymentOption
-> PremiumGiftCodePaymentOption -> Bool
$c/= :: PremiumGiftCodePaymentOption
-> PremiumGiftCodePaymentOption -> Bool
/= :: PremiumGiftCodePaymentOption
-> PremiumGiftCodePaymentOption -> Bool
Eq, Int -> PremiumGiftCodePaymentOption -> ShowS
[PremiumGiftCodePaymentOption] -> ShowS
PremiumGiftCodePaymentOption -> String
(Int -> PremiumGiftCodePaymentOption -> ShowS)
-> (PremiumGiftCodePaymentOption -> String)
-> ([PremiumGiftCodePaymentOption] -> ShowS)
-> Show PremiumGiftCodePaymentOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PremiumGiftCodePaymentOption -> ShowS
showsPrec :: Int -> PremiumGiftCodePaymentOption -> ShowS
$cshow :: PremiumGiftCodePaymentOption -> String
show :: PremiumGiftCodePaymentOption -> String
$cshowList :: [PremiumGiftCodePaymentOption] -> ShowS
showList :: [PremiumGiftCodePaymentOption] -> ShowS
Show)

instance I.ShortShow PremiumGiftCodePaymentOption where
  shortShow :: PremiumGiftCodePaymentOption -> String
shortShow PremiumGiftCodePaymentOption
    { currency :: PremiumGiftCodePaymentOption -> Maybe Text
currency               = Maybe Text
currency_
    , amount :: PremiumGiftCodePaymentOption -> Maybe Int
amount                 = Maybe Int
amount_
    , winner_count :: PremiumGiftCodePaymentOption -> Maybe Int
winner_count           = Maybe Int
winner_count_
    , month_count :: PremiumGiftCodePaymentOption -> Maybe Int
month_count            = Maybe Int
month_count_
    , store_product_id :: PremiumGiftCodePaymentOption -> Maybe Text
store_product_id       = Maybe Text
store_product_id_
    , store_product_quantity :: PremiumGiftCodePaymentOption -> Maybe Int
store_product_quantity = Maybe Int
store_product_quantity_
    }
      = String
"PremiumGiftCodePaymentOption"
        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
"winner_count"           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
winner_count_
        , 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
"store_product_quantity" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
store_product_quantity_
        ]

instance AT.FromJSON PremiumGiftCodePaymentOption where
  parseJSON :: Value -> Parser PremiumGiftCodePaymentOption
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
"premiumGiftCodePaymentOption" -> Value -> Parser PremiumGiftCodePaymentOption
parsePremiumGiftCodePaymentOption Value
v
      String
_                              -> Parser PremiumGiftCodePaymentOption
forall a. Monoid a => a
mempty
    
    where
      parsePremiumGiftCodePaymentOption :: A.Value -> AT.Parser PremiumGiftCodePaymentOption
      parsePremiumGiftCodePaymentOption :: Value -> Parser PremiumGiftCodePaymentOption
parsePremiumGiftCodePaymentOption = String
-> (Object -> Parser PremiumGiftCodePaymentOption)
-> Value
-> Parser PremiumGiftCodePaymentOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PremiumGiftCodePaymentOption" ((Object -> Parser PremiumGiftCodePaymentOption)
 -> Value -> Parser PremiumGiftCodePaymentOption)
-> (Object -> Parser PremiumGiftCodePaymentOption)
-> Value
-> Parser PremiumGiftCodePaymentOption
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
winner_count_           <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"winner_count"
        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 Int
store_product_quantity_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"store_product_quantity"
        PremiumGiftCodePaymentOption -> Parser PremiumGiftCodePaymentOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PremiumGiftCodePaymentOption
 -> Parser PremiumGiftCodePaymentOption)
-> PremiumGiftCodePaymentOption
-> Parser PremiumGiftCodePaymentOption
forall a b. (a -> b) -> a -> b
$ PremiumGiftCodePaymentOption
          { currency :: Maybe Text
currency               = Maybe Text
currency_
          , amount :: Maybe Int
amount                 = Maybe Int
amount_
          , winner_count :: Maybe Int
winner_count           = Maybe Int
winner_count_
          , month_count :: Maybe Int
month_count            = Maybe Int
month_count_
          , store_product_id :: Maybe Text
store_product_id       = Maybe Text
store_product_id_
          , store_product_quantity :: Maybe Int
store_product_quantity = Maybe Int
store_product_quantity_
          }
  parseJSON Value
_ = Parser PremiumGiftCodePaymentOption
forall a. Monoid a => a
mempty