module TD.Query.SearchPublicStoriesByTag
  (SearchPublicStoriesByTag(..)
  , defaultSearchPublicStoriesByTag
  ) 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 stories containing the given hashtag or cashtag. For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit. Returns 'TD.Data.FoundStories.FoundStories'
data SearchPublicStoriesByTag
  = SearchPublicStoriesByTag
    { SearchPublicStoriesByTag -> Maybe Text
tag    :: Maybe T.Text -- ^ Hashtag or cashtag to search for
    , SearchPublicStoriesByTag -> 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
    , SearchPublicStoriesByTag -> Maybe Int
limit  :: Maybe Int    -- ^ The maximum number of stories to be returned; up to 100. For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit
    }
  deriving (SearchPublicStoriesByTag -> SearchPublicStoriesByTag -> Bool
(SearchPublicStoriesByTag -> SearchPublicStoriesByTag -> Bool)
-> (SearchPublicStoriesByTag -> SearchPublicStoriesByTag -> Bool)
-> Eq SearchPublicStoriesByTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchPublicStoriesByTag -> SearchPublicStoriesByTag -> Bool
== :: SearchPublicStoriesByTag -> SearchPublicStoriesByTag -> Bool
$c/= :: SearchPublicStoriesByTag -> SearchPublicStoriesByTag -> Bool
/= :: SearchPublicStoriesByTag -> SearchPublicStoriesByTag -> Bool
Eq, Int -> SearchPublicStoriesByTag -> ShowS
[SearchPublicStoriesByTag] -> ShowS
SearchPublicStoriesByTag -> String
(Int -> SearchPublicStoriesByTag -> ShowS)
-> (SearchPublicStoriesByTag -> String)
-> ([SearchPublicStoriesByTag] -> ShowS)
-> Show SearchPublicStoriesByTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchPublicStoriesByTag -> ShowS
showsPrec :: Int -> SearchPublicStoriesByTag -> ShowS
$cshow :: SearchPublicStoriesByTag -> String
show :: SearchPublicStoriesByTag -> String
$cshowList :: [SearchPublicStoriesByTag] -> ShowS
showList :: [SearchPublicStoriesByTag] -> ShowS
Show)

instance I.ShortShow SearchPublicStoriesByTag where
  shortShow :: SearchPublicStoriesByTag -> String
shortShow
    SearchPublicStoriesByTag
      { tag :: SearchPublicStoriesByTag -> Maybe Text
tag    = Maybe Text
tag_
      , offset :: SearchPublicStoriesByTag -> Maybe Text
offset = Maybe Text
offset_
      , limit :: SearchPublicStoriesByTag -> Maybe Int
limit  = Maybe Int
limit_
      }
        = String
"SearchPublicStoriesByTag"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"tag"    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
tag_
          , 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_
          ]

instance AT.ToJSON SearchPublicStoriesByTag where
  toJSON :: SearchPublicStoriesByTag -> Value
toJSON
    SearchPublicStoriesByTag
      { tag :: SearchPublicStoriesByTag -> Maybe Text
tag    = Maybe Text
tag_
      , offset :: SearchPublicStoriesByTag -> Maybe Text
offset = Maybe Text
offset_
      , limit :: SearchPublicStoriesByTag -> 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
"searchPublicStoriesByTag"
          , Key
"tag"    Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
tag_
          , 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_
          ]

defaultSearchPublicStoriesByTag :: SearchPublicStoriesByTag
defaultSearchPublicStoriesByTag :: SearchPublicStoriesByTag
defaultSearchPublicStoriesByTag =
  SearchPublicStoriesByTag
    { tag :: Maybe Text
tag    = 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
    }