module TD.Query.SearchHashtags
  (SearchHashtags(..)
  , defaultSearchHashtags
  ) 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 recently used hashtags by their prefix. Returns 'TD.Data.Hashtags.Hashtags'
data SearchHashtags
  = SearchHashtags
    { SearchHashtags -> Maybe Text
prefix :: Maybe T.Text -- ^ Hashtag prefix to search for
    , SearchHashtags -> Maybe Int
limit  :: Maybe Int    -- ^ The maximum number of hashtags to be returned
    }
  deriving (SearchHashtags -> SearchHashtags -> Bool
(SearchHashtags -> SearchHashtags -> Bool)
-> (SearchHashtags -> SearchHashtags -> Bool) -> Eq SearchHashtags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchHashtags -> SearchHashtags -> Bool
== :: SearchHashtags -> SearchHashtags -> Bool
$c/= :: SearchHashtags -> SearchHashtags -> Bool
/= :: SearchHashtags -> SearchHashtags -> Bool
Eq, Int -> SearchHashtags -> ShowS
[SearchHashtags] -> ShowS
SearchHashtags -> String
(Int -> SearchHashtags -> ShowS)
-> (SearchHashtags -> String)
-> ([SearchHashtags] -> ShowS)
-> Show SearchHashtags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchHashtags -> ShowS
showsPrec :: Int -> SearchHashtags -> ShowS
$cshow :: SearchHashtags -> String
show :: SearchHashtags -> String
$cshowList :: [SearchHashtags] -> ShowS
showList :: [SearchHashtags] -> ShowS
Show)

instance I.ShortShow SearchHashtags where
  shortShow :: SearchHashtags -> String
shortShow
    SearchHashtags
      { prefix :: SearchHashtags -> Maybe Text
prefix = Maybe Text
prefix_
      , limit :: SearchHashtags -> Maybe Int
limit  = Maybe Int
limit_
      }
        = String
"SearchHashtags"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"prefix" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
prefix_
          , String
"limit"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          ]

instance AT.ToJSON SearchHashtags where
  toJSON :: SearchHashtags -> Value
toJSON
    SearchHashtags
      { prefix :: SearchHashtags -> Maybe Text
prefix = Maybe Text
prefix_
      , limit :: SearchHashtags -> 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
"searchHashtags"
          , Key
"prefix" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
prefix_
          , 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_
          ]

defaultSearchHashtags :: SearchHashtags
defaultSearchHashtags :: SearchHashtags
defaultSearchHashtags =
  SearchHashtags
    { prefix :: Maybe Text
prefix = Maybe Text
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit  = Maybe Int
forall a. Maybe a
Nothing
    }