module TD.Query.SetAuthenticationPremiumPurchaseTransaction
  (SetAuthenticationPremiumPurchaseTransaction(..)
  , defaultSetAuthenticationPremiumPurchaseTransaction
  ) 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.StoreTransaction as StoreTransaction
import qualified Data.Text as T

-- | Informs server about an in-store purchase of Telegram Premium before authorization. Works only when the current authorization state is authorizationStateWaitPremiumPurchase. Returns 'TD.Data.Ok.Ok'
data SetAuthenticationPremiumPurchaseTransaction
  = SetAuthenticationPremiumPurchaseTransaction
    { SetAuthenticationPremiumPurchaseTransaction
-> Maybe StoreTransaction
transaction :: Maybe StoreTransaction.StoreTransaction -- ^ Information about the transaction
    , SetAuthenticationPremiumPurchaseTransaction -> Maybe Bool
is_restore  :: Maybe Bool                              -- ^ Pass true if this is a restore of a Telegram Premium purchase; only for App Store
    , SetAuthenticationPremiumPurchaseTransaction -> Maybe Text
currency    :: Maybe T.Text                            -- ^ ISO 4217 currency code of the payment currency
    , SetAuthenticationPremiumPurchaseTransaction -> Maybe Int
amount      :: Maybe Int                               -- ^ Paid amount, in the smallest units of the currency
    }
  deriving (SetAuthenticationPremiumPurchaseTransaction
-> SetAuthenticationPremiumPurchaseTransaction -> Bool
(SetAuthenticationPremiumPurchaseTransaction
 -> SetAuthenticationPremiumPurchaseTransaction -> Bool)
-> (SetAuthenticationPremiumPurchaseTransaction
    -> SetAuthenticationPremiumPurchaseTransaction -> Bool)
-> Eq SetAuthenticationPremiumPurchaseTransaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetAuthenticationPremiumPurchaseTransaction
-> SetAuthenticationPremiumPurchaseTransaction -> Bool
== :: SetAuthenticationPremiumPurchaseTransaction
-> SetAuthenticationPremiumPurchaseTransaction -> Bool
$c/= :: SetAuthenticationPremiumPurchaseTransaction
-> SetAuthenticationPremiumPurchaseTransaction -> Bool
/= :: SetAuthenticationPremiumPurchaseTransaction
-> SetAuthenticationPremiumPurchaseTransaction -> Bool
Eq, Int -> SetAuthenticationPremiumPurchaseTransaction -> ShowS
[SetAuthenticationPremiumPurchaseTransaction] -> ShowS
SetAuthenticationPremiumPurchaseTransaction -> String
(Int -> SetAuthenticationPremiumPurchaseTransaction -> ShowS)
-> (SetAuthenticationPremiumPurchaseTransaction -> String)
-> ([SetAuthenticationPremiumPurchaseTransaction] -> ShowS)
-> Show SetAuthenticationPremiumPurchaseTransaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetAuthenticationPremiumPurchaseTransaction -> ShowS
showsPrec :: Int -> SetAuthenticationPremiumPurchaseTransaction -> ShowS
$cshow :: SetAuthenticationPremiumPurchaseTransaction -> String
show :: SetAuthenticationPremiumPurchaseTransaction -> String
$cshowList :: [SetAuthenticationPremiumPurchaseTransaction] -> ShowS
showList :: [SetAuthenticationPremiumPurchaseTransaction] -> ShowS
Show)

instance I.ShortShow SetAuthenticationPremiumPurchaseTransaction where
  shortShow :: SetAuthenticationPremiumPurchaseTransaction -> String
shortShow
    SetAuthenticationPremiumPurchaseTransaction
      { transaction :: SetAuthenticationPremiumPurchaseTransaction
-> Maybe StoreTransaction
transaction = Maybe StoreTransaction
transaction_
      , is_restore :: SetAuthenticationPremiumPurchaseTransaction -> Maybe Bool
is_restore  = Maybe Bool
is_restore_
      , currency :: SetAuthenticationPremiumPurchaseTransaction -> Maybe Text
currency    = Maybe Text
currency_
      , amount :: SetAuthenticationPremiumPurchaseTransaction -> Maybe Int
amount      = Maybe Int
amount_
      }
        = String
"SetAuthenticationPremiumPurchaseTransaction"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"transaction" String -> Maybe StoreTransaction -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StoreTransaction
transaction_
          , String
"is_restore"  String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_restore_
          , 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_
          ]

instance AT.ToJSON SetAuthenticationPremiumPurchaseTransaction where
  toJSON :: SetAuthenticationPremiumPurchaseTransaction -> Value
toJSON
    SetAuthenticationPremiumPurchaseTransaction
      { transaction :: SetAuthenticationPremiumPurchaseTransaction
-> Maybe StoreTransaction
transaction = Maybe StoreTransaction
transaction_
      , is_restore :: SetAuthenticationPremiumPurchaseTransaction -> Maybe Bool
is_restore  = Maybe Bool
is_restore_
      , currency :: SetAuthenticationPremiumPurchaseTransaction -> Maybe Text
currency    = Maybe Text
currency_
      , amount :: SetAuthenticationPremiumPurchaseTransaction -> 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
"setAuthenticationPremiumPurchaseTransaction"
          , Key
"transaction" Key -> Maybe StoreTransaction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe StoreTransaction
transaction_
          , 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
"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_
          ]

defaultSetAuthenticationPremiumPurchaseTransaction :: SetAuthenticationPremiumPurchaseTransaction
defaultSetAuthenticationPremiumPurchaseTransaction :: SetAuthenticationPremiumPurchaseTransaction
defaultSetAuthenticationPremiumPurchaseTransaction =
  SetAuthenticationPremiumPurchaseTransaction
    { transaction :: Maybe StoreTransaction
transaction = Maybe StoreTransaction
forall a. Maybe a
Nothing
    , is_restore :: Maybe Bool
is_restore  = Maybe Bool
forall a. Maybe a
Nothing
    , currency :: Maybe Text
currency    = Maybe Text
forall a. Maybe a
Nothing
    , amount :: Maybe Int
amount      = Maybe Int
forall a. Maybe a
Nothing
    }