module TD.Query.GetInlineQueryResults
  (GetInlineQueryResults(..)
  , defaultGetInlineQueryResults
  ) 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.Location as Location
import qualified Data.Text as T

-- | Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires. Returns 'TD.Data.InlineQueryResults.InlineQueryResults'
data GetInlineQueryResults
  = GetInlineQueryResults
    { GetInlineQueryResults -> Maybe Int
bot_user_id   :: Maybe Int               -- ^ Identifier of the target bot
    , GetInlineQueryResults -> Maybe Int
chat_id       :: Maybe Int               -- ^ Identifier of the chat where the query was sent
    , GetInlineQueryResults -> Maybe Location
user_location :: Maybe Location.Location -- ^ Location of the user; pass null if unknown or the bot doesn't need user's location
    , GetInlineQueryResults -> Maybe Text
query         :: Maybe T.Text            -- ^ Text of the query
    , GetInlineQueryResults -> Maybe Text
offset        :: Maybe T.Text            -- ^ Offset of the first entry to return; use empty string to get the first chunk of results
    }
  deriving (GetInlineQueryResults -> GetInlineQueryResults -> Bool
(GetInlineQueryResults -> GetInlineQueryResults -> Bool)
-> (GetInlineQueryResults -> GetInlineQueryResults -> Bool)
-> Eq GetInlineQueryResults
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetInlineQueryResults -> GetInlineQueryResults -> Bool
== :: GetInlineQueryResults -> GetInlineQueryResults -> Bool
$c/= :: GetInlineQueryResults -> GetInlineQueryResults -> Bool
/= :: GetInlineQueryResults -> GetInlineQueryResults -> Bool
Eq, Int -> GetInlineQueryResults -> ShowS
[GetInlineQueryResults] -> ShowS
GetInlineQueryResults -> String
(Int -> GetInlineQueryResults -> ShowS)
-> (GetInlineQueryResults -> String)
-> ([GetInlineQueryResults] -> ShowS)
-> Show GetInlineQueryResults
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetInlineQueryResults -> ShowS
showsPrec :: Int -> GetInlineQueryResults -> ShowS
$cshow :: GetInlineQueryResults -> String
show :: GetInlineQueryResults -> String
$cshowList :: [GetInlineQueryResults] -> ShowS
showList :: [GetInlineQueryResults] -> ShowS
Show)

instance I.ShortShow GetInlineQueryResults where
  shortShow :: GetInlineQueryResults -> String
shortShow
    GetInlineQueryResults
      { bot_user_id :: GetInlineQueryResults -> Maybe Int
bot_user_id   = Maybe Int
bot_user_id_
      , chat_id :: GetInlineQueryResults -> Maybe Int
chat_id       = Maybe Int
chat_id_
      , user_location :: GetInlineQueryResults -> Maybe Location
user_location = Maybe Location
user_location_
      , query :: GetInlineQueryResults -> Maybe Text
query         = Maybe Text
query_
      , offset :: GetInlineQueryResults -> Maybe Text
offset        = Maybe Text
offset_
      }
        = String
"GetInlineQueryResults"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"bot_user_id"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
          , String
"chat_id"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"user_location" String -> Maybe Location -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Location
user_location_
          , String
"query"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
query_
          , String
"offset"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
offset_
          ]

instance AT.ToJSON GetInlineQueryResults where
  toJSON :: GetInlineQueryResults -> Value
toJSON
    GetInlineQueryResults
      { bot_user_id :: GetInlineQueryResults -> Maybe Int
bot_user_id   = Maybe Int
bot_user_id_
      , chat_id :: GetInlineQueryResults -> Maybe Int
chat_id       = Maybe Int
chat_id_
      , user_location :: GetInlineQueryResults -> Maybe Location
user_location = Maybe Location
user_location_
      , query :: GetInlineQueryResults -> Maybe Text
query         = Maybe Text
query_
      , offset :: GetInlineQueryResults -> Maybe Text
offset        = Maybe Text
offset_
      }
        = [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
"getInlineQueryResults"
          , Key
"bot_user_id"   Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
bot_user_id_
          , Key
"chat_id"       Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
chat_id_
          , Key
"user_location" Key -> Maybe Location -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Location
user_location_
          , Key
"query"         Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
query_
          , Key
"offset"        Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
offset_
          ]

defaultGetInlineQueryResults :: GetInlineQueryResults
defaultGetInlineQueryResults :: GetInlineQueryResults
defaultGetInlineQueryResults =
  GetInlineQueryResults
    { bot_user_id :: Maybe Int
bot_user_id   = Maybe Int
forall a. Maybe a
Nothing
    , chat_id :: Maybe Int
chat_id       = Maybe Int
forall a. Maybe a
Nothing
    , user_location :: Maybe Location
user_location = Maybe Location
forall a. Maybe a
Nothing
    , query :: Maybe Text
query         = Maybe Text
forall a. Maybe a
Nothing
    , offset :: Maybe Text
offset        = Maybe Text
forall a. Maybe a
Nothing
    }