module TD.Data.StorePaymentPurpose
  (StorePaymentPurpose(..)) 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.FormattedText as FormattedText
import qualified TD.Data.GiveawayParameters as GiveawayParameters

-- | Describes a purpose of an in-store payment
data StorePaymentPurpose
  = StorePaymentPurposePremiumSubscription -- ^ The user subscribing to Telegram Premium
    { StorePaymentPurpose -> Maybe Bool
is_restore :: Maybe Bool -- ^ Pass true if this is a restore of a Telegram Premium purchase; only for App Store
    , StorePaymentPurpose -> Maybe Bool
is_upgrade :: Maybe Bool -- ^ Pass true if this is an upgrade from a monthly subscription to early subscription; only for App Store
    }
  | StorePaymentPurposeGiftedPremium -- ^ The user gifting Telegram Premium to another user
    { StorePaymentPurpose -> Maybe Int
user_id  :: Maybe Int    -- ^ Identifier of the user to which Telegram Premium is gifted
    , StorePaymentPurpose -> Maybe Text
currency :: Maybe T.Text -- ^ ISO 4217 currency code of the payment currency
    , StorePaymentPurpose -> Maybe Int
amount   :: Maybe Int    -- ^ Paid amount, in the smallest units of the currency
    }
  | StorePaymentPurposePremiumGiftCodes -- ^ The user creating Telegram Premium gift codes for other users
    { StorePaymentPurpose -> Maybe Int
boosted_chat_id :: Maybe Int                         -- ^ Identifier of the supergroup or channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user; 0 if none
    , currency        :: Maybe T.Text                      -- ^ ISO 4217 currency code of the payment currency
    , amount          :: Maybe Int                         -- ^ Paid amount, in the smallest units of the currency
    , StorePaymentPurpose -> Maybe [Int]
user_ids        :: Maybe [Int]                       -- ^ Identifiers of the users which can activate the gift codes
    , StorePaymentPurpose -> Maybe FormattedText
text            :: Maybe FormattedText.FormattedText -- ^ Text to show along with the gift codes; 0-getOption("gift_text_length_max") characters. Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities are allowed
    }
  | StorePaymentPurposePremiumGiveaway -- ^ The user creating a Telegram Premium giveaway
    { StorePaymentPurpose -> Maybe GiveawayParameters
parameters :: Maybe GiveawayParameters.GiveawayParameters -- ^ Giveaway parameters
    , currency   :: Maybe T.Text                                -- ^ ISO 4217 currency code of the payment currency
    , amount     :: Maybe Int                                   -- ^ Paid amount, in the smallest units of the currency
    }
  | StorePaymentPurposeStarGiveaway -- ^ The user creating a Telegram Star giveaway
    { parameters   :: Maybe GiveawayParameters.GiveawayParameters -- ^ Giveaway parameters
    , currency     :: Maybe T.Text                                -- ^ ISO 4217 currency code of the payment currency
    , amount       :: Maybe Int                                   -- ^ Paid amount, in the smallest units of the currency
    , StorePaymentPurpose -> Maybe Int
winner_count :: Maybe Int                                   -- ^ The number of users to receive Telegram Stars
    , StorePaymentPurpose -> Maybe Int
star_count   :: Maybe Int                                   -- ^ The number of Telegram Stars to be distributed through the giveaway
    }
  | StorePaymentPurposeStars -- ^ The user buying Telegram Stars
    { currency   :: Maybe T.Text -- ^ ISO 4217 currency code of the payment currency
    , amount     :: Maybe Int    -- ^ Paid amount, in the smallest units of the currency
    , star_count :: Maybe Int    -- ^ Number of bought Telegram Stars
    }
  | StorePaymentPurposeGiftedStars -- ^ The user buying Telegram Stars for other users
    { user_id    :: Maybe Int    -- ^ Identifier of the user to which Telegram Stars are gifted
    , currency   :: Maybe T.Text -- ^ ISO 4217 currency code of the payment currency
    , amount     :: Maybe Int    -- ^ Paid amount, in the smallest units of the currency
    , star_count :: Maybe Int    -- ^ Number of bought Telegram Stars
    }
  deriving (StorePaymentPurpose -> StorePaymentPurpose -> Bool
(StorePaymentPurpose -> StorePaymentPurpose -> Bool)
-> (StorePaymentPurpose -> StorePaymentPurpose -> Bool)
-> Eq StorePaymentPurpose
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StorePaymentPurpose -> StorePaymentPurpose -> Bool
== :: StorePaymentPurpose -> StorePaymentPurpose -> Bool
$c/= :: StorePaymentPurpose -> StorePaymentPurpose -> Bool
/= :: StorePaymentPurpose -> StorePaymentPurpose -> Bool
Eq, Int -> StorePaymentPurpose -> ShowS
[StorePaymentPurpose] -> ShowS
StorePaymentPurpose -> String
(Int -> StorePaymentPurpose -> ShowS)
-> (StorePaymentPurpose -> String)
-> ([StorePaymentPurpose] -> ShowS)
-> Show StorePaymentPurpose
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StorePaymentPurpose -> ShowS
showsPrec :: Int -> StorePaymentPurpose -> ShowS
$cshow :: StorePaymentPurpose -> String
show :: StorePaymentPurpose -> String
$cshowList :: [StorePaymentPurpose] -> ShowS
showList :: [StorePaymentPurpose] -> ShowS
Show)

instance I.ShortShow StorePaymentPurpose where
  shortShow :: StorePaymentPurpose -> String
shortShow StorePaymentPurposePremiumSubscription
    { is_restore :: StorePaymentPurpose -> Maybe Bool
is_restore = Maybe Bool
is_restore_
    , is_upgrade :: StorePaymentPurpose -> Maybe Bool
is_upgrade = Maybe Bool
is_upgrade_
    }
      = String
"StorePaymentPurposePremiumSubscription"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"is_restore" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_restore_
        , String
"is_upgrade" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_upgrade_
        ]
  shortShow StorePaymentPurposeGiftedPremium
    { user_id :: StorePaymentPurpose -> Maybe Int
user_id  = Maybe Int
user_id_
    , currency :: StorePaymentPurpose -> Maybe Text
currency = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount   = Maybe Int
amount_
    }
      = String
"StorePaymentPurposeGiftedPremium"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"user_id"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
        , 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_
        ]
  shortShow StorePaymentPurposePremiumGiftCodes
    { boosted_chat_id :: StorePaymentPurpose -> Maybe Int
boosted_chat_id = Maybe Int
boosted_chat_id_
    , currency :: StorePaymentPurpose -> Maybe Text
currency        = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount          = Maybe Int
amount_
    , user_ids :: StorePaymentPurpose -> Maybe [Int]
user_ids        = Maybe [Int]
user_ids_
    , text :: StorePaymentPurpose -> Maybe FormattedText
text            = Maybe FormattedText
text_
    }
      = String
"StorePaymentPurposePremiumGiftCodes"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"boosted_chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
boosted_chat_id_
        , 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
"user_ids"        String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
user_ids_
        , String
"text"            String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
        ]
  shortShow StorePaymentPurposePremiumGiveaway
    { parameters :: StorePaymentPurpose -> Maybe GiveawayParameters
parameters = Maybe GiveawayParameters
parameters_
    , currency :: StorePaymentPurpose -> Maybe Text
currency   = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount     = Maybe Int
amount_
    }
      = String
"StorePaymentPurposePremiumGiveaway"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"parameters" String -> Maybe GiveawayParameters -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe GiveawayParameters
parameters_
        , 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_
        ]
  shortShow StorePaymentPurposeStarGiveaway
    { parameters :: StorePaymentPurpose -> Maybe GiveawayParameters
parameters   = Maybe GiveawayParameters
parameters_
    , currency :: StorePaymentPurpose -> Maybe Text
currency     = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount       = Maybe Int
amount_
    , winner_count :: StorePaymentPurpose -> Maybe Int
winner_count = Maybe Int
winner_count_
    , star_count :: StorePaymentPurpose -> Maybe Int
star_count   = Maybe Int
star_count_
    }
      = String
"StorePaymentPurposeStarGiveaway"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"parameters"   String -> Maybe GiveawayParameters -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe GiveawayParameters
parameters_
        , 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
"star_count"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
        ]
  shortShow StorePaymentPurposeStars
    { currency :: StorePaymentPurpose -> Maybe Text
currency   = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount     = Maybe Int
amount_
    , star_count :: StorePaymentPurpose -> Maybe Int
star_count = Maybe Int
star_count_
    }
      = String
"StorePaymentPurposeStars"
        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_
        ]
  shortShow StorePaymentPurposeGiftedStars
    { user_id :: StorePaymentPurpose -> Maybe Int
user_id    = Maybe Int
user_id_
    , currency :: StorePaymentPurpose -> Maybe Text
currency   = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount     = Maybe Int
amount_
    , star_count :: StorePaymentPurpose -> Maybe Int
star_count = Maybe Int
star_count_
    }
      = String
"StorePaymentPurposeGiftedStars"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"user_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
        , 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_
        ]

instance AT.FromJSON StorePaymentPurpose where
  parseJSON :: Value -> Parser StorePaymentPurpose
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
"storePaymentPurposePremiumSubscription" -> Value -> Parser StorePaymentPurpose
parseStorePaymentPurposePremiumSubscription Value
v
      String
"storePaymentPurposeGiftedPremium"       -> Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeGiftedPremium Value
v
      String
"storePaymentPurposePremiumGiftCodes"    -> Value -> Parser StorePaymentPurpose
parseStorePaymentPurposePremiumGiftCodes Value
v
      String
"storePaymentPurposePremiumGiveaway"     -> Value -> Parser StorePaymentPurpose
parseStorePaymentPurposePremiumGiveaway Value
v
      String
"storePaymentPurposeStarGiveaway"        -> Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeStarGiveaway Value
v
      String
"storePaymentPurposeStars"               -> Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeStars Value
v
      String
"storePaymentPurposeGiftedStars"         -> Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeGiftedStars Value
v
      String
_                                        -> Parser StorePaymentPurpose
forall a. Monoid a => a
mempty
    
    where
      parseStorePaymentPurposePremiumSubscription :: A.Value -> AT.Parser StorePaymentPurpose
      parseStorePaymentPurposePremiumSubscription :: Value -> Parser StorePaymentPurpose
parseStorePaymentPurposePremiumSubscription = String
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorePaymentPurposePremiumSubscription" ((Object -> Parser StorePaymentPurpose)
 -> Value -> Parser StorePaymentPurpose)
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
is_restore_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_restore"
        Maybe Bool
is_upgrade_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_upgrade"
        StorePaymentPurpose -> Parser StorePaymentPurpose
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorePaymentPurpose -> Parser StorePaymentPurpose)
-> StorePaymentPurpose -> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ StorePaymentPurposePremiumSubscription
          { is_restore :: Maybe Bool
is_restore = Maybe Bool
is_restore_
          , is_upgrade :: Maybe Bool
is_upgrade = Maybe Bool
is_upgrade_
          }
      parseStorePaymentPurposeGiftedPremium :: A.Value -> AT.Parser StorePaymentPurpose
      parseStorePaymentPurposeGiftedPremium :: Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeGiftedPremium = String
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorePaymentPurposeGiftedPremium" ((Object -> Parser StorePaymentPurpose)
 -> Value -> Parser StorePaymentPurpose)
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
user_id_  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"user_id"
        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"
        StorePaymentPurpose -> Parser StorePaymentPurpose
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorePaymentPurpose -> Parser StorePaymentPurpose)
-> StorePaymentPurpose -> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ StorePaymentPurposeGiftedPremium
          { user_id :: Maybe Int
user_id  = Maybe Int
user_id_
          , currency :: Maybe Text
currency = Maybe Text
currency_
          , amount :: Maybe Int
amount   = Maybe Int
amount_
          }
      parseStorePaymentPurposePremiumGiftCodes :: A.Value -> AT.Parser StorePaymentPurpose
      parseStorePaymentPurposePremiumGiftCodes :: Value -> Parser StorePaymentPurpose
parseStorePaymentPurposePremiumGiftCodes = String
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorePaymentPurposePremiumGiftCodes" ((Object -> Parser StorePaymentPurpose)
 -> Value -> Parser StorePaymentPurpose)
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
boosted_chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"boosted_chat_id"
        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]
user_ids_        <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"user_ids"
        Maybe FormattedText
text_            <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        StorePaymentPurpose -> Parser StorePaymentPurpose
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorePaymentPurpose -> Parser StorePaymentPurpose)
-> StorePaymentPurpose -> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ StorePaymentPurposePremiumGiftCodes
          { boosted_chat_id :: Maybe Int
boosted_chat_id = Maybe Int
boosted_chat_id_
          , currency :: Maybe Text
currency        = Maybe Text
currency_
          , amount :: Maybe Int
amount          = Maybe Int
amount_
          , user_ids :: Maybe [Int]
user_ids        = Maybe [Int]
user_ids_
          , text :: Maybe FormattedText
text            = Maybe FormattedText
text_
          }
      parseStorePaymentPurposePremiumGiveaway :: A.Value -> AT.Parser StorePaymentPurpose
      parseStorePaymentPurposePremiumGiveaway :: Value -> Parser StorePaymentPurpose
parseStorePaymentPurposePremiumGiveaway = String
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorePaymentPurposePremiumGiveaway" ((Object -> Parser StorePaymentPurpose)
 -> Value -> Parser StorePaymentPurpose)
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe GiveawayParameters
parameters_ <- Object
o Object -> Key -> Parser (Maybe GiveawayParameters)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"parameters"
        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"
        StorePaymentPurpose -> Parser StorePaymentPurpose
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorePaymentPurpose -> Parser StorePaymentPurpose)
-> StorePaymentPurpose -> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ StorePaymentPurposePremiumGiveaway
          { parameters :: Maybe GiveawayParameters
parameters = Maybe GiveawayParameters
parameters_
          , currency :: Maybe Text
currency   = Maybe Text
currency_
          , amount :: Maybe Int
amount     = Maybe Int
amount_
          }
      parseStorePaymentPurposeStarGiveaway :: A.Value -> AT.Parser StorePaymentPurpose
      parseStorePaymentPurposeStarGiveaway :: Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeStarGiveaway = String
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorePaymentPurposeStarGiveaway" ((Object -> Parser StorePaymentPurpose)
 -> Value -> Parser StorePaymentPurpose)
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe GiveawayParameters
parameters_   <- Object
o Object -> Key -> Parser (Maybe GiveawayParameters)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"parameters"
        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
star_count_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"star_count"
        StorePaymentPurpose -> Parser StorePaymentPurpose
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorePaymentPurpose -> Parser StorePaymentPurpose)
-> StorePaymentPurpose -> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ StorePaymentPurposeStarGiveaway
          { parameters :: Maybe GiveawayParameters
parameters   = Maybe GiveawayParameters
parameters_
          , currency :: Maybe Text
currency     = Maybe Text
currency_
          , amount :: Maybe Int
amount       = Maybe Int
amount_
          , winner_count :: Maybe Int
winner_count = Maybe Int
winner_count_
          , star_count :: Maybe Int
star_count   = Maybe Int
star_count_
          }
      parseStorePaymentPurposeStars :: A.Value -> AT.Parser StorePaymentPurpose
      parseStorePaymentPurposeStars :: Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeStars = String
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorePaymentPurposeStars" ((Object -> Parser StorePaymentPurpose)
 -> Value -> Parser StorePaymentPurpose)
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
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"
        StorePaymentPurpose -> Parser StorePaymentPurpose
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorePaymentPurpose -> Parser StorePaymentPurpose)
-> StorePaymentPurpose -> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ StorePaymentPurposeStars
          { currency :: Maybe Text
currency   = Maybe Text
currency_
          , amount :: Maybe Int
amount     = Maybe Int
amount_
          , star_count :: Maybe Int
star_count = Maybe Int
star_count_
          }
      parseStorePaymentPurposeGiftedStars :: A.Value -> AT.Parser StorePaymentPurpose
      parseStorePaymentPurposeGiftedStars :: Value -> Parser StorePaymentPurpose
parseStorePaymentPurposeGiftedStars = String
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorePaymentPurposeGiftedStars" ((Object -> Parser StorePaymentPurpose)
 -> Value -> Parser StorePaymentPurpose)
-> (Object -> Parser StorePaymentPurpose)
-> Value
-> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
user_id_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"user_id"
        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"
        StorePaymentPurpose -> Parser StorePaymentPurpose
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorePaymentPurpose -> Parser StorePaymentPurpose)
-> StorePaymentPurpose -> Parser StorePaymentPurpose
forall a b. (a -> b) -> a -> b
$ StorePaymentPurposeGiftedStars
          { user_id :: Maybe Int
user_id    = Maybe Int
user_id_
          , currency :: Maybe Text
currency   = Maybe Text
currency_
          , amount :: Maybe Int
amount     = Maybe Int
amount_
          , star_count :: Maybe Int
star_count = Maybe Int
star_count_
          }
  parseJSON Value
_ = Parser StorePaymentPurpose
forall a. Monoid a => a
mempty

instance AT.ToJSON StorePaymentPurpose where
  toJSON :: StorePaymentPurpose -> Value
toJSON StorePaymentPurposePremiumSubscription
    { is_restore :: StorePaymentPurpose -> Maybe Bool
is_restore = Maybe Bool
is_restore_
    , is_upgrade :: StorePaymentPurpose -> Maybe Bool
is_upgrade = Maybe Bool
is_upgrade_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"      Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storePaymentPurposePremiumSubscription"
        , Key
"is_restore" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_restore_
        , Key
"is_upgrade" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_upgrade_
        ]
  toJSON StorePaymentPurposeGiftedPremium
    { user_id :: StorePaymentPurpose -> Maybe Int
user_id  = Maybe Int
user_id_
    , currency :: StorePaymentPurpose -> Maybe Text
currency = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount   = Maybe Int
amount_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"    Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storePaymentPurposeGiftedPremium"
        , Key
"user_id"  Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
user_id_
        , Key
"currency" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
currency_
        , Key
"amount"   Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
amount_
        ]
  toJSON StorePaymentPurposePremiumGiftCodes
    { boosted_chat_id :: StorePaymentPurpose -> Maybe Int
boosted_chat_id = Maybe Int
boosted_chat_id_
    , currency :: StorePaymentPurpose -> Maybe Text
currency        = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount          = Maybe Int
amount_
    , user_ids :: StorePaymentPurpose -> Maybe [Int]
user_ids        = Maybe [Int]
user_ids_
    , text :: StorePaymentPurpose -> Maybe FormattedText
text            = Maybe FormattedText
text_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"           Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storePaymentPurposePremiumGiftCodes"
        , Key
"boosted_chat_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
boosted_chat_id_
        , Key
"currency"        Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
currency_
        , Key
"amount"          Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
amount_
        , Key
"user_ids"        Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
user_ids_
        , Key
"text"            Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
text_
        ]
  toJSON StorePaymentPurposePremiumGiveaway
    { parameters :: StorePaymentPurpose -> Maybe GiveawayParameters
parameters = Maybe GiveawayParameters
parameters_
    , currency :: StorePaymentPurpose -> Maybe Text
currency   = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount     = Maybe Int
amount_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"      Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storePaymentPurposePremiumGiveaway"
        , Key
"parameters" Key -> Maybe GiveawayParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe GiveawayParameters
parameters_
        , Key
"currency"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
currency_
        , Key
"amount"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
amount_
        ]
  toJSON StorePaymentPurposeStarGiveaway
    { parameters :: StorePaymentPurpose -> Maybe GiveawayParameters
parameters   = Maybe GiveawayParameters
parameters_
    , currency :: StorePaymentPurpose -> Maybe Text
currency     = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount       = Maybe Int
amount_
    , winner_count :: StorePaymentPurpose -> Maybe Int
winner_count = Maybe Int
winner_count_
    , star_count :: StorePaymentPurpose -> Maybe Int
star_count   = Maybe Int
star_count_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"        Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storePaymentPurposeStarGiveaway"
        , Key
"parameters"   Key -> Maybe GiveawayParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe GiveawayParameters
parameters_
        , Key
"currency"     Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
currency_
        , Key
"amount"       Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
amount_
        , Key
"winner_count" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
winner_count_
        , Key
"star_count"   Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
star_count_
        ]
  toJSON StorePaymentPurposeStars
    { currency :: StorePaymentPurpose -> Maybe Text
currency   = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount     = Maybe Int
amount_
    , star_count :: StorePaymentPurpose -> Maybe Int
star_count = Maybe Int
star_count_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"      Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storePaymentPurposeStars"
        , Key
"currency"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
currency_
        , Key
"amount"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
amount_
        , Key
"star_count" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
star_count_
        ]
  toJSON StorePaymentPurposeGiftedStars
    { user_id :: StorePaymentPurpose -> Maybe Int
user_id    = Maybe Int
user_id_
    , currency :: StorePaymentPurpose -> Maybe Text
currency   = Maybe Text
currency_
    , amount :: StorePaymentPurpose -> Maybe Int
amount     = Maybe Int
amount_
    , star_count :: StorePaymentPurpose -> Maybe Int
star_count = Maybe Int
star_count_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"      Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storePaymentPurposeGiftedStars"
        , Key
"user_id"    Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
user_id_
        , Key
"currency"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
currency_
        , Key
"amount"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
amount_
        , Key
"star_count" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
star_count_
        ]