module TD.Query.SearchPublicChats
  (SearchPublicChats(..)
  ) 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

-- | Searches public chats by looking for specified query in their username and title. Currently, only private chats, supergroups and channels can be public. Returns a meaningful number of results. Excludes private chats with contacts and chats from the chat list from the results. Returns 'TD.Data.Chats.Chats'
data SearchPublicChats
  = SearchPublicChats
    { SearchPublicChats -> Maybe Text
query :: Maybe T.Text -- ^ Query to search for
    }
  deriving (SearchPublicChats -> SearchPublicChats -> Bool
(SearchPublicChats -> SearchPublicChats -> Bool)
-> (SearchPublicChats -> SearchPublicChats -> Bool)
-> Eq SearchPublicChats
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchPublicChats -> SearchPublicChats -> Bool
== :: SearchPublicChats -> SearchPublicChats -> Bool
$c/= :: SearchPublicChats -> SearchPublicChats -> Bool
/= :: SearchPublicChats -> SearchPublicChats -> Bool
Eq, Int -> SearchPublicChats -> ShowS
[SearchPublicChats] -> ShowS
SearchPublicChats -> String
(Int -> SearchPublicChats -> ShowS)
-> (SearchPublicChats -> String)
-> ([SearchPublicChats] -> ShowS)
-> Show SearchPublicChats
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchPublicChats -> ShowS
showsPrec :: Int -> SearchPublicChats -> ShowS
$cshow :: SearchPublicChats -> String
show :: SearchPublicChats -> String
$cshowList :: [SearchPublicChats] -> ShowS
showList :: [SearchPublicChats] -> ShowS
Show)

instance I.ShortShow SearchPublicChats where
  shortShow :: SearchPublicChats -> String
shortShow
    SearchPublicChats
      { query :: SearchPublicChats -> Maybe Text
query = Maybe Text
query_
      }
        = String
"SearchPublicChats"
          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_
          ]

instance AT.ToJSON SearchPublicChats where
  toJSON :: SearchPublicChats -> Value
toJSON
    SearchPublicChats
      { query :: SearchPublicChats -> Maybe Text
query = Maybe Text
query_
      }
        = [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
"searchPublicChats"
          , 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_
          ]