module TD.Query.AnswerWebAppQuery
  (AnswerWebAppQuery(..)
  , defaultAnswerWebAppQuery
  ) 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.InputInlineQueryResult as InputInlineQueryResult

-- | Sets the result of interaction with a Web App and sends corresponding message on behalf of the user to the chat from which the query originated; for bots only. Returns 'TD.Data.SentWebAppMessage.SentWebAppMessage'
data AnswerWebAppQuery
  = AnswerWebAppQuery
    { AnswerWebAppQuery -> Maybe Text
web_app_query_id :: Maybe T.Text                                        -- ^ Identifier of the Web App query
    , AnswerWebAppQuery -> Maybe InputInlineQueryResult
result           :: Maybe InputInlineQueryResult.InputInlineQueryResult -- ^ The result of the query
    }
  deriving (AnswerWebAppQuery -> AnswerWebAppQuery -> Bool
(AnswerWebAppQuery -> AnswerWebAppQuery -> Bool)
-> (AnswerWebAppQuery -> AnswerWebAppQuery -> Bool)
-> Eq AnswerWebAppQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AnswerWebAppQuery -> AnswerWebAppQuery -> Bool
== :: AnswerWebAppQuery -> AnswerWebAppQuery -> Bool
$c/= :: AnswerWebAppQuery -> AnswerWebAppQuery -> Bool
/= :: AnswerWebAppQuery -> AnswerWebAppQuery -> Bool
Eq, Int -> AnswerWebAppQuery -> ShowS
[AnswerWebAppQuery] -> ShowS
AnswerWebAppQuery -> String
(Int -> AnswerWebAppQuery -> ShowS)
-> (AnswerWebAppQuery -> String)
-> ([AnswerWebAppQuery] -> ShowS)
-> Show AnswerWebAppQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AnswerWebAppQuery -> ShowS
showsPrec :: Int -> AnswerWebAppQuery -> ShowS
$cshow :: AnswerWebAppQuery -> String
show :: AnswerWebAppQuery -> String
$cshowList :: [AnswerWebAppQuery] -> ShowS
showList :: [AnswerWebAppQuery] -> ShowS
Show)

instance I.ShortShow AnswerWebAppQuery where
  shortShow :: AnswerWebAppQuery -> String
shortShow
    AnswerWebAppQuery
      { web_app_query_id :: AnswerWebAppQuery -> Maybe Text
web_app_query_id = Maybe Text
web_app_query_id_
      , result :: AnswerWebAppQuery -> Maybe InputInlineQueryResult
result           = Maybe InputInlineQueryResult
result_
      }
        = String
"AnswerWebAppQuery"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"web_app_query_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
web_app_query_id_
          , String
"result"           String -> Maybe InputInlineQueryResult -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputInlineQueryResult
result_
          ]

instance AT.ToJSON AnswerWebAppQuery where
  toJSON :: AnswerWebAppQuery -> Value
toJSON
    AnswerWebAppQuery
      { web_app_query_id :: AnswerWebAppQuery -> Maybe Text
web_app_query_id = Maybe Text
web_app_query_id_
      , result :: AnswerWebAppQuery -> Maybe InputInlineQueryResult
result           = Maybe InputInlineQueryResult
result_
      }
        = [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
"answerWebAppQuery"
          , Key
"web_app_query_id" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
web_app_query_id_
          , Key
"result"           Key -> Maybe InputInlineQueryResult -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputInlineQueryResult
result_
          ]

defaultAnswerWebAppQuery :: AnswerWebAppQuery
defaultAnswerWebAppQuery :: AnswerWebAppQuery
defaultAnswerWebAppQuery =
  AnswerWebAppQuery
    { web_app_query_id :: Maybe Text
web_app_query_id = Maybe Text
forall a. Maybe a
Nothing
    , result :: Maybe InputInlineQueryResult
result           = Maybe InputInlineQueryResult
forall a. Maybe a
Nothing
    }