{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeOperators              #-}
module Telegram.Bot.API.WebApps where

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

import Telegram.Bot.API.Internal.Utils (deriveJSON')
import Telegram.Bot.API.MakingRequests (Response)
import Telegram.Bot.API.InlineMode (InlineQueryId)
import Telegram.Bot.API.InlineMode.InlineQueryResult (InlineQueryResult)

-- * Types

-- ** 'AnswerWebAppQueryRequest'

data AnswerWebAppQueryRequest = AnswerWebAppQueryRequest
  { AnswerWebAppQueryRequest -> Text
answerWebAppQueryWebAppQueryId :: Text              -- ^ Unique identifier for the query to be answered.
  , AnswerWebAppQueryRequest -> InlineQueryResult
answerWebAppQueryResult        :: InlineQueryResult -- ^ A JSON-serialized object describing the message to be sent.
  }
  deriving (forall x.
Rep AnswerWebAppQueryRequest x -> AnswerWebAppQueryRequest
forall x.
AnswerWebAppQueryRequest -> Rep AnswerWebAppQueryRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AnswerWebAppQueryRequest x -> AnswerWebAppQueryRequest
$cfrom :: forall x.
AnswerWebAppQueryRequest -> Rep AnswerWebAppQueryRequest x
Generic, Int -> AnswerWebAppQueryRequest -> ShowS
[AnswerWebAppQueryRequest] -> ShowS
AnswerWebAppQueryRequest -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AnswerWebAppQueryRequest] -> ShowS
$cshowList :: [AnswerWebAppQueryRequest] -> ShowS
show :: AnswerWebAppQueryRequest -> String
$cshow :: AnswerWebAppQueryRequest -> String
showsPrec :: Int -> AnswerWebAppQueryRequest -> ShowS
$cshowsPrec :: Int -> AnswerWebAppQueryRequest -> ShowS
Show)

-- ** 'SentWebAppMessage'

-- | Contains information about an inline message sent by a Web App on behalf of a user.
newtype SentWebAppMessage = SentWebAppMessage
  { SentWebAppMessage -> Maybe InlineQueryId
sentWebAppMessageInlineMessageId :: Maybe InlineQueryId
  }
  deriving (forall x. Rep SentWebAppMessage x -> SentWebAppMessage
forall x. SentWebAppMessage -> Rep SentWebAppMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SentWebAppMessage x -> SentWebAppMessage
$cfrom :: forall x. SentWebAppMessage -> Rep SentWebAppMessage x
Generic, Int -> SentWebAppMessage -> ShowS
[SentWebAppMessage] -> ShowS
SentWebAppMessage -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SentWebAppMessage] -> ShowS
$cshowList :: [SentWebAppMessage] -> ShowS
show :: SentWebAppMessage -> String
$cshow :: SentWebAppMessage -> String
showsPrec :: Int -> SentWebAppMessage -> ShowS
$cshowsPrec :: Int -> SentWebAppMessage -> ShowS
Show)
  
foldMap deriveJSON'
  [ ''SentWebAppMessage
  , ''AnswerWebAppQueryRequest
  ]

-- * Methods

-- ** 'answerWebAppQuery'

type AnswerWebAppQuery
  = "answerWebAppQuery" :> ReqBody '[JSON] AnswerWebAppQueryRequest :> Post '[JSON] (Response SentWebAppMessage)

-- | Use this method to set the result of an interaction with a Web App
-- and send a corresponding message on behalf of the user
-- to the chat from which the query originated.
-- 
-- On success, a 'SentWebAppMessage' object is returned.
answerWebAppQuery :: AnswerWebAppQueryRequest -> ClientM (Response SentWebAppMessage)
answerWebAppQuery :: AnswerWebAppQueryRequest -> ClientM (Response SentWebAppMessage)
answerWebAppQuery = forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @AnswerWebAppQuery)