{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds #-}
module Telegram.Bot.API.Payments where

import Data.Aeson
import Data.Proxy
import Data.Text
import GHC.Generics (Generic)
import Servant.API
import Servant.Client hiding (Response)

import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.Types
import Telegram.Bot.API.MakingRequests
import Telegram.Bot.API.Internal.TH (makeDefault)

-- * Methods

-- ** 'sendInvoice'

data SendInvoiceRequest = SendInvoiceRequest
  { SendInvoiceRequest -> ChatId
sendInvoiceChatId                    :: ChatId                     -- ^ Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  , SendInvoiceRequest -> Maybe MessageThreadId
sendInvoiceMessageThreadId           :: Maybe MessageThreadId      -- ^ Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.
  , SendInvoiceRequest -> Text
sendInvoiceTitle                     :: Text                       -- ^ Product name, 1-32 characters.
  , SendInvoiceRequest -> Text
sendInvoiceDescription               :: Text                       -- ^ Product description, 1-255 characters.
  , SendInvoiceRequest -> Text
sendInvoicePayload                   :: Text                       -- ^ Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
  , SendInvoiceRequest -> Text
sendInvoiceProviderToken             :: Text                       -- ^ Payments provider token, obtained via Botfather.
  , SendInvoiceRequest -> Text
sendInvoiceCurrency                  :: Text                       -- ^ Three-letter ISO 4217 currency code, see more on currencies.
  , SendInvoiceRequest -> [LabeledPrice]
sendInvoicePrices                    :: [LabeledPrice]             -- ^ Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
  , SendInvoiceRequest -> Maybe Integer
sendInvoiceMaxTipAmount              :: Maybe Integer              -- ^ The maximum accepted amount for tips in the smallest units of the currency (integer, not float\/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0.
  , SendInvoiceRequest -> Maybe [Integer]
sendInvoiceequestSuggestedTipAmounts :: Maybe [Integer]            -- ^ A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
  , SendInvoiceRequest -> Maybe Text
sendInvoiceStartParameter            :: Maybe Text                 -- ^ Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter.
  , SendInvoiceRequest -> Maybe Text
sendInvoiceProviderData              :: Maybe Text                 -- ^ A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
  , SendInvoiceRequest -> Maybe Text
sendInvoicePhotoUrl                  :: Maybe Text                 -- ^ URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
  , SendInvoiceRequest -> Maybe Int
sendInvoicePhotoSize                 :: Maybe Int                  -- ^ Photo size.
  , SendInvoiceRequest -> Maybe Int
sendInvoicePhotoWidth                :: Maybe Int                  -- ^ Photo width.
  , SendInvoiceRequest -> Maybe Int
sendInvoicePhotoHeight               :: Maybe Int                  -- ^ Photo height.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceNeedName                  :: Maybe Bool                 -- ^ Pass 'True', if you require the user's full name to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceNeedPhoneNumber           :: Maybe Bool                 -- ^ Pass 'True', if you require the user's phone number to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceNeedEmail                 :: Maybe Bool                 -- ^ Pass 'True', if you require the user's email address to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceNeedShippingAddress       :: Maybe Bool                 -- ^ Pass 'True', if you require the user's shipping address to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceSendPhoneNumberToProvider :: Maybe Bool                 -- ^ Pass 'True', if you require the user's phone number to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceSendEmailToProvider       :: Maybe Bool                 -- ^ Pass 'True', if user's email address should be sent to provider.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceIsFlexible                :: Maybe Bool                 -- ^ Pass 'True', if the final price depends on the shipping method.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceDisableNotification       :: Maybe Bool                 -- ^ Sends the message silently. Users will receive a notification with no sound.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceProtectContent            :: Maybe Bool                 -- ^ Protects the contents of the sent message from forwarding and saving.
  , SendInvoiceRequest -> Maybe MessageId
sendInvoiceReplyToMessageId          :: Maybe MessageId            -- ^ If the message is a reply, ID of the original message.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceAllowSendingWithoutReply  :: Maybe Bool                 -- ^ Pass 'True', if the message should be sent even if the specified replied-to message is not found.
  , SendInvoiceRequest -> Maybe InlineKeyboardMarkup
sendInvoiceReplyMarkup               :: Maybe InlineKeyboardMarkup -- ^ A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
  }
  deriving (forall x. Rep SendInvoiceRequest x -> SendInvoiceRequest
forall x. SendInvoiceRequest -> Rep SendInvoiceRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendInvoiceRequest x -> SendInvoiceRequest
$cfrom :: forall x. SendInvoiceRequest -> Rep SendInvoiceRequest x
Generic, Int -> SendInvoiceRequest -> ShowS
[SendInvoiceRequest] -> ShowS
SendInvoiceRequest -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendInvoiceRequest] -> ShowS
$cshowList :: [SendInvoiceRequest] -> ShowS
show :: SendInvoiceRequest -> String
$cshow :: SendInvoiceRequest -> String
showsPrec :: Int -> SendInvoiceRequest -> ShowS
$cshowsPrec :: Int -> SendInvoiceRequest -> ShowS
Show)

instance ToJSON SendInvoiceRequest where toJSON :: SendInvoiceRequest -> Value
toJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GToJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
a -> Value
gtoJSON
instance FromJSON SendInvoiceRequest where parseJSON :: Value -> Parser SendInvoiceRequest
parseJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GFromJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
Value -> Parser a
gparseJSON

type SendInvoice
  =  "sendInvoice"
  :> ReqBody '[JSON] SendInvoiceRequest
  :> Post '[JSON] (Response Message)

-- | Use this method to send invoices. On success, the sent 'Message' is returned.
sendInvoice :: SendInvoiceRequest -> ClientM (Response Message)
sendInvoice :: SendInvoiceRequest -> ClientM (Response Message)
sendInvoice = forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @SendInvoice)

-- ** 'createInvoiceLink'

data CreateInvoiceLinkRequest = CreateInvoiceLinkRequest
  { CreateInvoiceLinkRequest -> Text
createInvoiceLinkTitle                     :: Text            -- ^ Product name, 1-32 characters.
  , CreateInvoiceLinkRequest -> Text
createInvoiceLinkDescription               :: Text            -- ^ Product description, 1-255 characters.
  , CreateInvoiceLinkRequest -> Text
createInvoiceLinkPayload                   :: Text            -- ^ Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
  , CreateInvoiceLinkRequest -> Text
createInvoiceLinkProviderToken             :: Text            -- ^ Payment provider token, obtained via BotFather.
  , CreateInvoiceLinkRequest -> Text
createInvoiceLinkCurrency                  :: Text            -- ^ Three-letter ISO 4217 currency code, see more on currencies.
  , CreateInvoiceLinkRequest -> [LabeledPrice]
createInvoiceLinkPrices                    :: [LabeledPrice]  -- ^ Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
  , CreateInvoiceLinkRequest -> Maybe Integer
createInvoiceLinkMaxTipAmount              :: Maybe Integer   -- ^ The maximum accepted amount for tips in the smallest units of the currency (integer, not float\/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0.
  , CreateInvoiceLinkRequest -> Maybe [Integer]
createInvoiceLinkSuggestedTipAmounts       :: Maybe [Integer] -- ^ A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float\/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed @max_tip_amount@.
  , CreateInvoiceLinkRequest -> Maybe Text
createInvoiceLinkProviderData              :: Maybe Text      -- ^ JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
  , CreateInvoiceLinkRequest -> Maybe Text
createInvoiceLinkPhotoUrl                  :: Maybe Text      -- ^ URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
  , CreateInvoiceLinkRequest -> Maybe Int
createInvoiceLinkPhotoSize                 :: Maybe Int       -- ^ Photo size in bytes.
  , CreateInvoiceLinkRequest -> Maybe Int
createInvoiceLinkPhotoWidth                :: Maybe Int       -- ^ Photo width.
  , CreateInvoiceLinkRequest -> Maybe Int
createInvoiceLinkPhotoHeight               :: Maybe Int       -- ^ Photo height
  , CreateInvoiceLinkRequest -> Maybe Bool
createInvoiceLinkNeedName                  :: Maybe Bool      -- ^ Pass 'True' if you require the user's full name to complete the order.
  , CreateInvoiceLinkRequest -> Maybe Bool
createInvoiceLinkNeedPhoneNumber           :: Maybe Bool      -- ^ Pass 'True' if you require the user's phone number to complete the order.
  , CreateInvoiceLinkRequest -> Maybe Bool
createInvoiceLinkNeedEmail                 :: Maybe Bool      -- ^ Pass 'True' if you require the user's email address to complete the order.
  , CreateInvoiceLinkRequest -> Maybe Bool
createInvoiceLinkNeedShippingAddress       :: Maybe Bool      -- ^ Pass 'True' if you require the user's shipping address to complete the order.
  , CreateInvoiceLinkRequest -> Maybe Bool
createInvoiceLinkSendPhoneNumberToProvider :: Maybe Bool      -- ^ Pass 'True' if the user's phone number should be sent to the provider.
  , CreateInvoiceLinkRequest -> Maybe Bool
createInvoiceLinkSendEmailToProvider       :: Maybe Bool      -- ^ Pass 'True' if the user's email address should be sent to the provider.
  , CreateInvoiceLinkRequest -> Maybe Bool
createInvoiceLinkIsFlexible                :: Maybe Bool      -- ^ Pass 'True' if the final price depends on the shipping method.
  }
  deriving (forall x.
Rep CreateInvoiceLinkRequest x -> CreateInvoiceLinkRequest
forall x.
CreateInvoiceLinkRequest -> Rep CreateInvoiceLinkRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateInvoiceLinkRequest x -> CreateInvoiceLinkRequest
$cfrom :: forall x.
CreateInvoiceLinkRequest -> Rep CreateInvoiceLinkRequest x
Generic, Int -> CreateInvoiceLinkRequest -> ShowS
[CreateInvoiceLinkRequest] -> ShowS
CreateInvoiceLinkRequest -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateInvoiceLinkRequest] -> ShowS
$cshowList :: [CreateInvoiceLinkRequest] -> ShowS
show :: CreateInvoiceLinkRequest -> String
$cshow :: CreateInvoiceLinkRequest -> String
showsPrec :: Int -> CreateInvoiceLinkRequest -> ShowS
$cshowsPrec :: Int -> CreateInvoiceLinkRequest -> ShowS
Show)

instance ToJSON CreateInvoiceLinkRequest where toJSON :: CreateInvoiceLinkRequest -> Value
toJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GToJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
a -> Value
gtoJSON
instance FromJSON CreateInvoiceLinkRequest where parseJSON :: Value -> Parser CreateInvoiceLinkRequest
parseJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GFromJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
Value -> Parser a
gparseJSON

type CreateInvoiceLink
  =  "createInvoiceLink"
  :> ReqBody '[JSON] CreateInvoiceLinkRequest
  :> Post '[JSON] (Response Text)

-- | Use this method to create a link for an invoice. Returns the created invoice link as 'Text' on success.
createInvoiceLink :: CreateInvoiceLinkRequest -> ClientM (Response Text)
createInvoiceLink :: CreateInvoiceLinkRequest -> ClientM (Response Text)
createInvoiceLink = forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @CreateInvoiceLink)

-- ** 'answerShippingQuery'

data AnswerShippingQueryRequest = AnswerShippingQueryRequest
  { AnswerShippingQueryRequest -> Text
answerShippingQueryShippingQueryId :: Text                   -- ^ Unique identifier for the query to be answered.
  , AnswerShippingQueryRequest -> Bool
answerShippingQueryOk              :: Bool                   -- ^ Specify 'True' if delivery to the specified address is possible and 'False' if there are any problems (for example, if delivery to the specified address is not possible).
  , AnswerShippingQueryRequest -> Maybe [ShippingOption]
answerShippingQueryShippingOptions :: Maybe [ShippingOption] -- ^ Required if @ok@ is 'True'. A JSON-serialized array of available shipping options.
  , AnswerShippingQueryRequest -> Maybe Text
answerShippingQueryErrorMessage    :: Maybe Text             -- ^ Required if @ok@ is 'False'. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
  }
  deriving (forall x.
Rep AnswerShippingQueryRequest x -> AnswerShippingQueryRequest
forall x.
AnswerShippingQueryRequest -> Rep AnswerShippingQueryRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AnswerShippingQueryRequest x -> AnswerShippingQueryRequest
$cfrom :: forall x.
AnswerShippingQueryRequest -> Rep AnswerShippingQueryRequest x
Generic, Int -> AnswerShippingQueryRequest -> ShowS
[AnswerShippingQueryRequest] -> ShowS
AnswerShippingQueryRequest -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AnswerShippingQueryRequest] -> ShowS
$cshowList :: [AnswerShippingQueryRequest] -> ShowS
show :: AnswerShippingQueryRequest -> String
$cshow :: AnswerShippingQueryRequest -> String
showsPrec :: Int -> AnswerShippingQueryRequest -> ShowS
$cshowsPrec :: Int -> AnswerShippingQueryRequest -> ShowS
Show)

instance ToJSON AnswerShippingQueryRequest where toJSON :: AnswerShippingQueryRequest -> Value
toJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GToJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
a -> Value
gtoJSON
instance FromJSON AnswerShippingQueryRequest where parseJSON :: Value -> Parser AnswerShippingQueryRequest
parseJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GFromJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
Value -> Parser a
gparseJSON

type AnswerShippingQuery
  =  "answerShippingQuery"
  :> ReqBody '[JSON] AnswerShippingQueryRequest
  :> Post '[JSON] (Response Bool)

-- | If you sent an invoice requesting a shipping address and the parameter @is_flexible@ was specified, the Bot API will send an 'Update' with a @shipping_query@ field to the bot. Use this method to reply to shipping queries. On success, True is returned.
answerShippingQuery :: AnswerShippingQueryRequest -> ClientM (Response Bool)
answerShippingQuery :: AnswerShippingQueryRequest -> ClientM (Response Bool)
answerShippingQuery = forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @AnswerShippingQuery)

-- ** 'answerPreCheckoutQuery'

data AnswerPreCheckoutQueryRequest = AnswerPreCheckoutQueryRequest
  { AnswerPreCheckoutQueryRequest -> Text
answerPreCheckoutQueryPreCheckoutQueryId :: Text       -- ^ Unique identifier for the query to be answered.
  , AnswerPreCheckoutQueryRequest -> Bool
answerPreCheckoutQueryOk                 :: Bool       -- ^ Specify 'True' if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
  , AnswerPreCheckoutQueryRequest -> Maybe Text
answerPreCheckoutQueryErrorMessage       :: Maybe Text -- ^ Required if @ok@ is 'False'. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
  }
  deriving (forall x.
Rep AnswerPreCheckoutQueryRequest x
-> AnswerPreCheckoutQueryRequest
forall x.
AnswerPreCheckoutQueryRequest
-> Rep AnswerPreCheckoutQueryRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AnswerPreCheckoutQueryRequest x
-> AnswerPreCheckoutQueryRequest
$cfrom :: forall x.
AnswerPreCheckoutQueryRequest
-> Rep AnswerPreCheckoutQueryRequest x
Generic, Int -> AnswerPreCheckoutQueryRequest -> ShowS
[AnswerPreCheckoutQueryRequest] -> ShowS
AnswerPreCheckoutQueryRequest -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AnswerPreCheckoutQueryRequest] -> ShowS
$cshowList :: [AnswerPreCheckoutQueryRequest] -> ShowS
show :: AnswerPreCheckoutQueryRequest -> String
$cshow :: AnswerPreCheckoutQueryRequest -> String
showsPrec :: Int -> AnswerPreCheckoutQueryRequest -> ShowS
$cshowsPrec :: Int -> AnswerPreCheckoutQueryRequest -> ShowS
Show)

instance ToJSON AnswerPreCheckoutQueryRequest where toJSON :: AnswerPreCheckoutQueryRequest -> Value
toJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GToJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
a -> Value
gtoJSON
instance FromJSON AnswerPreCheckoutQueryRequest where parseJSON :: Value -> Parser AnswerPreCheckoutQueryRequest
parseJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GFromJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
Value -> Parser a
gparseJSON

type AnswerPreCheckoutQuery
  =  "answerPreCheckoutQuery"
  :> ReqBody '[JSON] AnswerPreCheckoutQueryRequest
  :> Post '[JSON] (Response Bool)

-- | Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, 'True' is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
answerPreCheckoutQuery :: AnswerPreCheckoutQueryRequest -> ClientM (Response Bool)
answerPreCheckoutQuery :: AnswerPreCheckoutQueryRequest -> ClientM (Response Bool)
answerPreCheckoutQuery = forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @AnswerPreCheckoutQuery)

foldMap makeDefault
  [ ''SendInvoiceRequest
  , ''CreateInvoiceLinkRequest
  , ''AnswerShippingQueryRequest
  , ''AnswerPreCheckoutQueryRequest
  ]