module TD.Query.SearchPublicPosts
  (SearchPublicPosts(..)
  , defaultSearchPublicPosts
  ) 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 for public channel posts using the given query. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit. Returns 'TD.Data.FoundPublicPosts.FoundPublicPosts'
data SearchPublicPosts
  = SearchPublicPosts
    { SearchPublicPosts -> Maybe Text
query      :: Maybe T.Text -- ^ Query to search for
    , SearchPublicPosts -> Maybe Text
offset     :: Maybe T.Text -- ^ Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
    , SearchPublicPosts -> Maybe Int
limit      :: Maybe Int    -- ^ The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
    , SearchPublicPosts -> Maybe Int
star_count :: Maybe Int    -- ^ The amount of Telegram Stars the user agreed to pay for the search; pass 0 for free searches
    }
  deriving (SearchPublicPosts -> SearchPublicPosts -> Bool
(SearchPublicPosts -> SearchPublicPosts -> Bool)
-> (SearchPublicPosts -> SearchPublicPosts -> Bool)
-> Eq SearchPublicPosts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchPublicPosts -> SearchPublicPosts -> Bool
== :: SearchPublicPosts -> SearchPublicPosts -> Bool
$c/= :: SearchPublicPosts -> SearchPublicPosts -> Bool
/= :: SearchPublicPosts -> SearchPublicPosts -> Bool
Eq, Int -> SearchPublicPosts -> ShowS
[SearchPublicPosts] -> ShowS
SearchPublicPosts -> String
(Int -> SearchPublicPosts -> ShowS)
-> (SearchPublicPosts -> String)
-> ([SearchPublicPosts] -> ShowS)
-> Show SearchPublicPosts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchPublicPosts -> ShowS
showsPrec :: Int -> SearchPublicPosts -> ShowS
$cshow :: SearchPublicPosts -> String
show :: SearchPublicPosts -> String
$cshowList :: [SearchPublicPosts] -> ShowS
showList :: [SearchPublicPosts] -> ShowS
Show)

instance I.ShortShow SearchPublicPosts where
  shortShow :: SearchPublicPosts -> String
shortShow
    SearchPublicPosts
      { query :: SearchPublicPosts -> Maybe Text
query      = Maybe Text
query_
      , offset :: SearchPublicPosts -> Maybe Text
offset     = Maybe Text
offset_
      , limit :: SearchPublicPosts -> Maybe Int
limit      = Maybe Int
limit_
      , star_count :: SearchPublicPosts -> Maybe Int
star_count = Maybe Int
star_count_
      }
        = String
"SearchPublicPosts"
          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
"offset"     String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
offset_
          , String
"limit"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          , String
"star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
          ]

instance AT.ToJSON SearchPublicPosts where
  toJSON :: SearchPublicPosts -> Value
toJSON
    SearchPublicPosts
      { query :: SearchPublicPosts -> Maybe Text
query      = Maybe Text
query_
      , offset :: SearchPublicPosts -> Maybe Text
offset     = Maybe Text
offset_
      , limit :: SearchPublicPosts -> Maybe Int
limit      = Maybe Int
limit_
      , star_count :: SearchPublicPosts -> Maybe Int
star_count = Maybe Int
star_count_
      }
        = [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
"searchPublicPosts"
          , 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
"offset"     Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
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
"star_count" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
star_count_
          ]

defaultSearchPublicPosts :: SearchPublicPosts
defaultSearchPublicPosts :: SearchPublicPosts
defaultSearchPublicPosts =
  SearchPublicPosts
    { query :: Maybe Text
query      = Maybe Text
forall a. Maybe a
Nothing
    , offset :: Maybe Text
offset     = Maybe Text
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit      = Maybe Int
forall a. Maybe a
Nothing
    , star_count :: Maybe Int
star_count = Maybe Int
forall a. Maybe a
Nothing
    }