{-# 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

-- * Methods

-- ** 'sendInvoice'

data SendInvoiceRequest = SendInvoiceRequest
  { SendInvoiceRequest -> ChatId
sendInvoiceRequestChatId                    :: ChatId                     -- ^ Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  , SendInvoiceRequest -> Text
sendInvoiceRequestTitle                     :: Text                       -- ^ Product name, 1-32 characters.
  , SendInvoiceRequest -> Text
sendInvoiceRequestDescription               :: Text                       -- ^ Product description, 1-255 characters.
  , SendInvoiceRequest -> Text
sendInvoiceRequestPayload                   :: Text                       -- ^ Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
  , SendInvoiceRequest -> Text
sendInvoiceRequestProviderToken             :: Text                       -- ^ Payments provider token, obtained via Botfather.
  , SendInvoiceRequest -> Text
sendInvoiceRequestCurrency                  :: Text                       -- ^ Three-letter ISO 4217 currency code, see more on currencies.
  , SendInvoiceRequest -> [LabeledPrice]
sendInvoiceRequestPrices                    :: [LabeledPrice]             -- ^ Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
  , SendInvoiceRequest -> Maybe Integer
sendInvoiceRequestMaxTipAmount              :: 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]
sendInvoiceRequestSuggestedTipAmounts       :: 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
sendInvoiceRequestStartParameter            :: 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
sendInvoiceRequestProviderData              :: 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
sendInvoiceRequestPhotoUrl                  :: 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
sendInvoiceRequestPhotoSize                 :: Maybe Int                  -- ^ Photo size.
  , SendInvoiceRequest -> Maybe Int
sendInvoiceRequestPhotoWidth                :: Maybe Int                  -- ^ Photo width.
  , SendInvoiceRequest -> Maybe Int
sendInvoiceRequestPhotoHeight               :: Maybe Int                  -- ^ Photo height.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestNeedName                  :: Maybe Bool                 -- ^ Pass 'True', if you require the user's full name to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestNeedPhoneNumber           :: Maybe Bool                 -- ^ Pass 'True', if you require the user's phone number to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestNeedEmail                 :: Maybe Bool                 -- ^ Pass 'True', if you require the user's email address to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestNeedShippingAddress       :: Maybe Bool                 -- ^ Pass 'True', if you require the user's shipping address to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestSendPhoneNumberToProvider :: Maybe Bool                 -- ^ Pass 'True', if you require the user's phone number to complete the order.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestSendEmailToProvider       :: Maybe Bool                 -- ^ Pass 'True', if user's email address should be sent to provider.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestIsFlexible                :: Maybe Bool                 -- ^ Pass 'True', if the final price depends on the shipping method.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestDisableNotification       :: Maybe Bool                 -- ^ Sends the message silently. Users will receive a notification with no sound.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestProtectContent            :: Maybe Bool                 -- ^ Protects the contents of the sent message from forwarding and saving.
  , SendInvoiceRequest -> Maybe MessageId
sendInvoiceRequestReplyToMessageId          :: Maybe MessageId            -- ^ If the message is a reply, ID of the original message.
  , SendInvoiceRequest -> Maybe Bool
sendInvoiceRequestAllowSendingWithoutReply  :: Maybe Bool                 -- ^ Pass 'True', if the message should be sent even if the specified replied-to message is not found.
  , SendInvoiceRequest -> Maybe InlineKeyboardMarkup
sendInvoiceRequestReplyMarkup               :: 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. SendInvoiceRequest -> Rep SendInvoiceRequest x)
-> (forall x. Rep SendInvoiceRequest x -> SendInvoiceRequest)
-> Generic SendInvoiceRequest
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
(Int -> SendInvoiceRequest -> ShowS)
-> (SendInvoiceRequest -> String)
-> ([SendInvoiceRequest] -> ShowS)
-> Show SendInvoiceRequest
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 = SendInvoiceRequest -> Value
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 = Value -> Parser SendInvoiceRequest
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 = Proxy SendInvoice -> Client ClientM SendInvoice
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy SendInvoice
forall k (t :: k). Proxy t
Proxy @SendInvoice)

-- ** 'answerShippingQuery'

data AnswerShippingQueryRequest = AnswerShippingQueryRequest
  { AnswerShippingQueryRequest -> Text
answerShippingQueryRequestShippingQueryId :: Text                   -- ^ Unique identifier for the query to be answered.
  , AnswerShippingQueryRequest -> Bool
answerShippingQueryRequestOk              :: 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]
answerShippingQueryRequestShippingOptions :: Maybe [ShippingOption] -- ^ Required if @ok@ is 'True'. A JSON-serialized array of available shipping options.
  , AnswerShippingQueryRequest -> Maybe Text
answerShippingQueryRequestErrorMessage    :: 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.
 AnswerShippingQueryRequest -> Rep AnswerShippingQueryRequest x)
-> (forall x.
    Rep AnswerShippingQueryRequest x -> AnswerShippingQueryRequest)
-> Generic AnswerShippingQueryRequest
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
(Int -> AnswerShippingQueryRequest -> ShowS)
-> (AnswerShippingQueryRequest -> String)
-> ([AnswerShippingQueryRequest] -> ShowS)
-> Show AnswerShippingQueryRequest
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 = AnswerShippingQueryRequest -> Value
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 = Value -> Parser AnswerShippingQueryRequest
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 = Proxy AnswerShippingQuery -> Client ClientM AnswerShippingQuery
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy AnswerShippingQuery
forall k (t :: k). Proxy t
Proxy @AnswerShippingQuery)

-- ** 'answerPreCheckoutQuery'

data AnswerPreCheckoutQueryRequest = AnswerPreCheckoutQueryRequest
  { AnswerPreCheckoutQueryRequest -> Text
answerPreCheckoutQueryRequestPreCheckoutQueryId :: Text       -- ^ Unique identifier for the query to be answered.
  , AnswerPreCheckoutQueryRequest -> Bool
answerPreCheckoutQueryRequestOk                 :: 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
answerPreCheckoutQueryRequestErrorMessage       :: 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.
 AnswerPreCheckoutQueryRequest
 -> Rep AnswerPreCheckoutQueryRequest x)
-> (forall x.
    Rep AnswerPreCheckoutQueryRequest x
    -> AnswerPreCheckoutQueryRequest)
-> Generic AnswerPreCheckoutQueryRequest
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
(Int -> AnswerPreCheckoutQueryRequest -> ShowS)
-> (AnswerPreCheckoutQueryRequest -> String)
-> ([AnswerPreCheckoutQueryRequest] -> ShowS)
-> Show AnswerPreCheckoutQueryRequest
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 = AnswerPreCheckoutQueryRequest -> Value
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 = Value -> Parser AnswerPreCheckoutQueryRequest
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 = Proxy AnswerPreCheckoutQuery
-> Client ClientM AnswerPreCheckoutQuery
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy AnswerPreCheckoutQuery
forall k (t :: k). Proxy t
Proxy @AnswerPreCheckoutQuery)