module TD.Query.LoadChats
  (LoadChats(..)
  , defaultLoadChats
  ) 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.ChatList as ChatList

-- | Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats have been loaded. Returns 'TD.Data.Ok.Ok'
data LoadChats
  = LoadChats
    { LoadChats -> Maybe ChatList
chat_list :: Maybe ChatList.ChatList -- ^ The chat list in which to load chats; pass null to load chats from the main chat list
    , LoadChats -> Maybe Int
limit     :: Maybe Int               -- ^ The maximum number of chats to be loaded. For optimal performance, the number of loaded chats is chosen by TDLib and can be smaller than the specified limit, even if the end of the list is not reached
    }
  deriving (LoadChats -> LoadChats -> Bool
(LoadChats -> LoadChats -> Bool)
-> (LoadChats -> LoadChats -> Bool) -> Eq LoadChats
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LoadChats -> LoadChats -> Bool
== :: LoadChats -> LoadChats -> Bool
$c/= :: LoadChats -> LoadChats -> Bool
/= :: LoadChats -> LoadChats -> Bool
Eq, Int -> LoadChats -> ShowS
[LoadChats] -> ShowS
LoadChats -> String
(Int -> LoadChats -> ShowS)
-> (LoadChats -> String)
-> ([LoadChats] -> ShowS)
-> Show LoadChats
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LoadChats -> ShowS
showsPrec :: Int -> LoadChats -> ShowS
$cshow :: LoadChats -> String
show :: LoadChats -> String
$cshowList :: [LoadChats] -> ShowS
showList :: [LoadChats] -> ShowS
Show)

instance I.ShortShow LoadChats where
  shortShow :: LoadChats -> String
shortShow
    LoadChats
      { chat_list :: LoadChats -> Maybe ChatList
chat_list = Maybe ChatList
chat_list_
      , limit :: LoadChats -> Maybe Int
limit     = Maybe Int
limit_
      }
        = String
"LoadChats"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"chat_list" String -> Maybe ChatList -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatList
chat_list_
          , String
"limit"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          ]

instance AT.ToJSON LoadChats where
  toJSON :: LoadChats -> Value
toJSON
    LoadChats
      { chat_list :: LoadChats -> Maybe ChatList
chat_list = Maybe ChatList
chat_list_
      , limit :: LoadChats -> 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
"loadChats"
          , Key
"chat_list" Key -> Maybe ChatList -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ChatList
chat_list_
          , 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_
          ]

defaultLoadChats :: LoadChats
defaultLoadChats :: LoadChats
defaultLoadChats =
  LoadChats
    { chat_list :: Maybe ChatList
chat_list = Maybe ChatList
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit     = Maybe Int
forall a. Maybe a
Nothing
    }