module TD.Query.GetChatHistory
  (GetChatHistory(..)
  , defaultGetChatHistory
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Returns messages in a chat. The messages are returned in reverse chronological order (i.e., in order of decreasing message_id). For optimal performance, the number of returned messages is chosen by TDLib. This is an offline request if only_local is true. Returns 'TD.Data.Messages.Messages'
data GetChatHistory
  = GetChatHistory
    { GetChatHistory -> Maybe Int
chat_id         :: Maybe Int  -- ^ Chat identifier
    , GetChatHistory -> Maybe Int
from_message_id :: Maybe Int  -- ^ Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
    , GetChatHistory -> Maybe Int
offset          :: Maybe Int  -- ^ Specify 0 to get results from exactly the message from_message_id or a negative offset up to 99 to get additionally some newer messages
    , GetChatHistory -> Maybe Int
limit           :: Maybe Int  -- ^ The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than or equal to -offset. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
    , GetChatHistory -> Maybe Bool
only_local      :: Maybe Bool -- ^ Pass true to get only messages that are available without sending network requests
    }
  deriving (GetChatHistory -> GetChatHistory -> Bool
(GetChatHistory -> GetChatHistory -> Bool)
-> (GetChatHistory -> GetChatHistory -> Bool) -> Eq GetChatHistory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetChatHistory -> GetChatHistory -> Bool
== :: GetChatHistory -> GetChatHistory -> Bool
$c/= :: GetChatHistory -> GetChatHistory -> Bool
/= :: GetChatHistory -> GetChatHistory -> Bool
Eq, Int -> GetChatHistory -> ShowS
[GetChatHistory] -> ShowS
GetChatHistory -> String
(Int -> GetChatHistory -> ShowS)
-> (GetChatHistory -> String)
-> ([GetChatHistory] -> ShowS)
-> Show GetChatHistory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetChatHistory -> ShowS
showsPrec :: Int -> GetChatHistory -> ShowS
$cshow :: GetChatHistory -> String
show :: GetChatHistory -> String
$cshowList :: [GetChatHistory] -> ShowS
showList :: [GetChatHistory] -> ShowS
Show)

instance I.ShortShow GetChatHistory where
  shortShow :: GetChatHistory -> String
shortShow
    GetChatHistory
      { chat_id :: GetChatHistory -> Maybe Int
chat_id         = Maybe Int
chat_id_
      , from_message_id :: GetChatHistory -> Maybe Int
from_message_id = Maybe Int
from_message_id_
      , offset :: GetChatHistory -> Maybe Int
offset          = Maybe Int
offset_
      , limit :: GetChatHistory -> Maybe Int
limit           = Maybe Int
limit_
      , only_local :: GetChatHistory -> Maybe Bool
only_local      = Maybe Bool
only_local_
      }
        = String
"GetChatHistory"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"chat_id"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"from_message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
from_message_id_
          , String
"offset"          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
offset_
          , String
"limit"           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          , String
"only_local"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
only_local_
          ]

instance AT.ToJSON GetChatHistory where
  toJSON :: GetChatHistory -> Value
toJSON
    GetChatHistory
      { chat_id :: GetChatHistory -> Maybe Int
chat_id         = Maybe Int
chat_id_
      , from_message_id :: GetChatHistory -> Maybe Int
from_message_id = Maybe Int
from_message_id_
      , offset :: GetChatHistory -> Maybe Int
offset          = Maybe Int
offset_
      , limit :: GetChatHistory -> Maybe Int
limit           = Maybe Int
limit_
      , only_local :: GetChatHistory -> Maybe Bool
only_local      = Maybe Bool
only_local_
      }
        = [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
"getChatHistory"
          , 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
"from_message_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
from_message_id_
          , Key
"offset"          Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
offset_
          , Key
"limit"           Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
limit_
          , Key
"only_local"      Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
only_local_
          ]

defaultGetChatHistory :: GetChatHistory
defaultGetChatHistory :: GetChatHistory
defaultGetChatHistory =
  GetChatHistory
    { chat_id :: Maybe Int
chat_id         = Maybe Int
forall a. Maybe a
Nothing
    , from_message_id :: Maybe Int
from_message_id = Maybe Int
forall a. Maybe a
Nothing
    , offset :: Maybe Int
offset          = Maybe Int
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit           = Maybe Int
forall a. Maybe a
Nothing
    , only_local :: Maybe Bool
only_local      = Maybe Bool
forall a. Maybe a
Nothing
    }