module TD.Query.SearchStringsByPrefix
  (SearchStringsByPrefix(..)
  , defaultSearchStringsByPrefix
  ) 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 specified query by word prefixes in the provided strings. Returns 0-based positions of strings that matched. Can be called synchronously. Returns 'TD.Data.FoundPositions.FoundPositions'
data SearchStringsByPrefix
  = SearchStringsByPrefix
    { SearchStringsByPrefix -> Maybe [Text]
strings                     :: Maybe [T.Text] -- ^ The strings to search in for the query
    , SearchStringsByPrefix -> Maybe Text
query                       :: Maybe T.Text   -- ^ Query to search for
    , SearchStringsByPrefix -> Maybe Int
limit                       :: Maybe Int      -- ^ The maximum number of objects to return
    , SearchStringsByPrefix -> Maybe Bool
return_none_for_empty_query :: Maybe Bool     -- ^ Pass true to receive no results for an empty query
    }
  deriving (SearchStringsByPrefix -> SearchStringsByPrefix -> Bool
(SearchStringsByPrefix -> SearchStringsByPrefix -> Bool)
-> (SearchStringsByPrefix -> SearchStringsByPrefix -> Bool)
-> Eq SearchStringsByPrefix
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchStringsByPrefix -> SearchStringsByPrefix -> Bool
== :: SearchStringsByPrefix -> SearchStringsByPrefix -> Bool
$c/= :: SearchStringsByPrefix -> SearchStringsByPrefix -> Bool
/= :: SearchStringsByPrefix -> SearchStringsByPrefix -> Bool
Eq, Int -> SearchStringsByPrefix -> ShowS
[SearchStringsByPrefix] -> ShowS
SearchStringsByPrefix -> String
(Int -> SearchStringsByPrefix -> ShowS)
-> (SearchStringsByPrefix -> String)
-> ([SearchStringsByPrefix] -> ShowS)
-> Show SearchStringsByPrefix
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchStringsByPrefix -> ShowS
showsPrec :: Int -> SearchStringsByPrefix -> ShowS
$cshow :: SearchStringsByPrefix -> String
show :: SearchStringsByPrefix -> String
$cshowList :: [SearchStringsByPrefix] -> ShowS
showList :: [SearchStringsByPrefix] -> ShowS
Show)

instance I.ShortShow SearchStringsByPrefix where
  shortShow :: SearchStringsByPrefix -> String
shortShow
    SearchStringsByPrefix
      { strings :: SearchStringsByPrefix -> Maybe [Text]
strings                     = Maybe [Text]
strings_
      , query :: SearchStringsByPrefix -> Maybe Text
query                       = Maybe Text
query_
      , limit :: SearchStringsByPrefix -> Maybe Int
limit                       = Maybe Int
limit_
      , return_none_for_empty_query :: SearchStringsByPrefix -> Maybe Bool
return_none_for_empty_query = Maybe Bool
return_none_for_empty_query_
      }
        = String
"SearchStringsByPrefix"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"strings"                     String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
strings_
          , String
"query"                       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
query_
          , String
"limit"                       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          , String
"return_none_for_empty_query" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
return_none_for_empty_query_
          ]

instance AT.ToJSON SearchStringsByPrefix where
  toJSON :: SearchStringsByPrefix -> Value
toJSON
    SearchStringsByPrefix
      { strings :: SearchStringsByPrefix -> Maybe [Text]
strings                     = Maybe [Text]
strings_
      , query :: SearchStringsByPrefix -> Maybe Text
query                       = Maybe Text
query_
      , limit :: SearchStringsByPrefix -> Maybe Int
limit                       = Maybe Int
limit_
      , return_none_for_empty_query :: SearchStringsByPrefix -> Maybe Bool
return_none_for_empty_query = Maybe Bool
return_none_for_empty_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
"searchStringsByPrefix"
          , Key
"strings"                     Key -> Maybe [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Text]
strings_
          , 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
"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
"return_none_for_empty_query" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
return_none_for_empty_query_
          ]

defaultSearchStringsByPrefix :: SearchStringsByPrefix
defaultSearchStringsByPrefix :: SearchStringsByPrefix
defaultSearchStringsByPrefix =
  SearchStringsByPrefix
    { strings :: Maybe [Text]
strings                     = Maybe [Text]
forall a. Maybe a
Nothing
    , query :: Maybe Text
query                       = Maybe Text
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit                       = Maybe Int
forall a. Maybe a
Nothing
    , return_none_for_empty_query :: Maybe Bool
return_none_for_empty_query = Maybe Bool
forall a. Maybe a
Nothing
    }