module TD.Query.SearchChats
  (SearchChats(..)
  , defaultSearchChats
  ) 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.SearchChatTypeFilter as SearchChatTypeFilter

-- | Searches for the specified query in the title and username of already known chats. This is an offline method. Returns chats in the order seen in the main chat list. Returns 'TD.Data.Chats.Chats'
data SearchChats
  = SearchChats
    { SearchChats -> Maybe Text
query       :: Maybe T.Text                                    -- ^ Query to search for. If the query is empty, returns up to 50 recently found chats
    , SearchChats -> Maybe SearchChatTypeFilter
type_filter :: Maybe SearchChatTypeFilter.SearchChatTypeFilter -- ^ Additional filter for type of the chats to be returned; pass null to search for chats of all types
    , SearchChats -> Maybe Int
limit       :: Maybe Int                                       -- ^ The maximum number of chats to be returned
    }
  deriving (SearchChats -> SearchChats -> Bool
(SearchChats -> SearchChats -> Bool)
-> (SearchChats -> SearchChats -> Bool) -> Eq SearchChats
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchChats -> SearchChats -> Bool
== :: SearchChats -> SearchChats -> Bool
$c/= :: SearchChats -> SearchChats -> Bool
/= :: SearchChats -> SearchChats -> Bool
Eq, Int -> SearchChats -> ShowS
[SearchChats] -> ShowS
SearchChats -> String
(Int -> SearchChats -> ShowS)
-> (SearchChats -> String)
-> ([SearchChats] -> ShowS)
-> Show SearchChats
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchChats -> ShowS
showsPrec :: Int -> SearchChats -> ShowS
$cshow :: SearchChats -> String
show :: SearchChats -> String
$cshowList :: [SearchChats] -> ShowS
showList :: [SearchChats] -> ShowS
Show)

instance I.ShortShow SearchChats where
  shortShow :: SearchChats -> String
shortShow
    SearchChats
      { query :: SearchChats -> Maybe Text
query       = Maybe Text
query_
      , type_filter :: SearchChats -> Maybe SearchChatTypeFilter
type_filter = Maybe SearchChatTypeFilter
type_filter_
      , limit :: SearchChats -> Maybe Int
limit       = Maybe Int
limit_
      }
        = String
"SearchChats"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"query"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
query_
          , String
"type_filter" String -> Maybe SearchChatTypeFilter -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe SearchChatTypeFilter
type_filter_
          , String
"limit"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          ]

instance AT.ToJSON SearchChats where
  toJSON :: SearchChats -> Value
toJSON
    SearchChats
      { query :: SearchChats -> Maybe Text
query       = Maybe Text
query_
      , type_filter :: SearchChats -> Maybe SearchChatTypeFilter
type_filter = Maybe SearchChatTypeFilter
type_filter_
      , limit :: SearchChats -> 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
"searchChats"
          , 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
"type_filter" Key -> Maybe SearchChatTypeFilter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe SearchChatTypeFilter
type_filter_
          , 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_
          ]

defaultSearchChats :: SearchChats
defaultSearchChats :: SearchChats
defaultSearchChats =
  SearchChats
    { query :: Maybe Text
query       = Maybe Text
forall a. Maybe a
Nothing
    , type_filter :: Maybe SearchChatTypeFilter
type_filter = Maybe SearchChatTypeFilter
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit       = Maybe Int
forall a. Maybe a
Nothing
    }