module TD.Query.GetForumTopicHistory
  (GetForumTopicHistory(..)
  , defaultGetForumTopicHistory
  ) 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 topic in a forum supergroup chat or a chat with a bot with topics. 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. Returns 'TD.Data.Messages.Messages'
data GetForumTopicHistory
  = GetForumTopicHistory
    { GetForumTopicHistory -> Maybe Int
chat_id         :: Maybe Int -- ^ Chat identifier
    , GetForumTopicHistory -> Maybe Int
forum_topic_id  :: Maybe Int -- ^ Forum topic identifier
    , GetForumTopicHistory -> 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
    , GetForumTopicHistory -> Maybe Int
offset          :: Maybe Int -- ^ Specify 0 to get results from exactly the message from_message_id or a negative number from -99 to -1 to get additionally -offset newer messages
    , GetForumTopicHistory -> 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, then 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
    }
  deriving (GetForumTopicHistory -> GetForumTopicHistory -> Bool
(GetForumTopicHistory -> GetForumTopicHistory -> Bool)
-> (GetForumTopicHistory -> GetForumTopicHistory -> Bool)
-> Eq GetForumTopicHistory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetForumTopicHistory -> GetForumTopicHistory -> Bool
== :: GetForumTopicHistory -> GetForumTopicHistory -> Bool
$c/= :: GetForumTopicHistory -> GetForumTopicHistory -> Bool
/= :: GetForumTopicHistory -> GetForumTopicHistory -> Bool
Eq, Int -> GetForumTopicHistory -> ShowS
[GetForumTopicHistory] -> ShowS
GetForumTopicHistory -> String
(Int -> GetForumTopicHistory -> ShowS)
-> (GetForumTopicHistory -> String)
-> ([GetForumTopicHistory] -> ShowS)
-> Show GetForumTopicHistory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetForumTopicHistory -> ShowS
showsPrec :: Int -> GetForumTopicHistory -> ShowS
$cshow :: GetForumTopicHistory -> String
show :: GetForumTopicHistory -> String
$cshowList :: [GetForumTopicHistory] -> ShowS
showList :: [GetForumTopicHistory] -> ShowS
Show)

instance I.ShortShow GetForumTopicHistory where
  shortShow :: GetForumTopicHistory -> String
shortShow
    GetForumTopicHistory
      { chat_id :: GetForumTopicHistory -> Maybe Int
chat_id         = Maybe Int
chat_id_
      , forum_topic_id :: GetForumTopicHistory -> Maybe Int
forum_topic_id  = Maybe Int
forum_topic_id_
      , from_message_id :: GetForumTopicHistory -> Maybe Int
from_message_id = Maybe Int
from_message_id_
      , offset :: GetForumTopicHistory -> Maybe Int
offset          = Maybe Int
offset_
      , limit :: GetForumTopicHistory -> Maybe Int
limit           = Maybe Int
limit_
      }
        = String
"GetForumTopicHistory"
          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
"forum_topic_id"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
forum_topic_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_
          ]

instance AT.ToJSON GetForumTopicHistory where
  toJSON :: GetForumTopicHistory -> Value
toJSON
    GetForumTopicHistory
      { chat_id :: GetForumTopicHistory -> Maybe Int
chat_id         = Maybe Int
chat_id_
      , forum_topic_id :: GetForumTopicHistory -> Maybe Int
forum_topic_id  = Maybe Int
forum_topic_id_
      , from_message_id :: GetForumTopicHistory -> Maybe Int
from_message_id = Maybe Int
from_message_id_
      , offset :: GetForumTopicHistory -> Maybe Int
offset          = Maybe Int
offset_
      , limit :: GetForumTopicHistory -> Maybe Int
limit           = Maybe Int
limit_
      }
        = [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
"getForumTopicHistory"
          , 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
"forum_topic_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
forum_topic_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_
          ]

defaultGetForumTopicHistory :: GetForumTopicHistory
defaultGetForumTopicHistory :: GetForumTopicHistory
defaultGetForumTopicHistory =
  GetForumTopicHistory
    { chat_id :: Maybe Int
chat_id         = Maybe Int
forall a. Maybe a
Nothing
    , forum_topic_id :: Maybe Int
forum_topic_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
    }