{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CloudSearch.BuildSuggesters
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Indexes the search suggestions. For more information, see
-- <http://docs.aws.amazon.com/cloudsearch/latest/developerguide/getting-suggestions.html#configuring-suggesters Configuring Suggesters>
-- in the /Amazon CloudSearch Developer Guide/.
module Amazonka.CloudSearch.BuildSuggesters
  ( -- * Creating a Request
    BuildSuggesters (..),
    newBuildSuggesters,

    -- * Request Lenses
    buildSuggesters_domainName,

    -- * Destructuring the Response
    BuildSuggestersResponse (..),
    newBuildSuggestersResponse,

    -- * Response Lenses
    buildSuggestersResponse_fieldNames,
    buildSuggestersResponse_httpStatus,
  )
where

import Amazonka.CloudSearch.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Container for the parameters to the @BuildSuggester@ operation.
-- Specifies the name of the domain you want to update.
--
-- /See:/ 'newBuildSuggesters' smart constructor.
data BuildSuggesters = BuildSuggesters'
  { BuildSuggesters -> Text
domainName :: Prelude.Text
  }
  deriving (BuildSuggesters -> BuildSuggesters -> Bool
(BuildSuggesters -> BuildSuggesters -> Bool)
-> (BuildSuggesters -> BuildSuggesters -> Bool)
-> Eq BuildSuggesters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildSuggesters -> BuildSuggesters -> Bool
$c/= :: BuildSuggesters -> BuildSuggesters -> Bool
== :: BuildSuggesters -> BuildSuggesters -> Bool
$c== :: BuildSuggesters -> BuildSuggesters -> Bool
Prelude.Eq, ReadPrec [BuildSuggesters]
ReadPrec BuildSuggesters
Int -> ReadS BuildSuggesters
ReadS [BuildSuggesters]
(Int -> ReadS BuildSuggesters)
-> ReadS [BuildSuggesters]
-> ReadPrec BuildSuggesters
-> ReadPrec [BuildSuggesters]
-> Read BuildSuggesters
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BuildSuggesters]
$creadListPrec :: ReadPrec [BuildSuggesters]
readPrec :: ReadPrec BuildSuggesters
$creadPrec :: ReadPrec BuildSuggesters
readList :: ReadS [BuildSuggesters]
$creadList :: ReadS [BuildSuggesters]
readsPrec :: Int -> ReadS BuildSuggesters
$creadsPrec :: Int -> ReadS BuildSuggesters
Prelude.Read, Int -> BuildSuggesters -> ShowS
[BuildSuggesters] -> ShowS
BuildSuggesters -> String
(Int -> BuildSuggesters -> ShowS)
-> (BuildSuggesters -> String)
-> ([BuildSuggesters] -> ShowS)
-> Show BuildSuggesters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildSuggesters] -> ShowS
$cshowList :: [BuildSuggesters] -> ShowS
show :: BuildSuggesters -> String
$cshow :: BuildSuggesters -> String
showsPrec :: Int -> BuildSuggesters -> ShowS
$cshowsPrec :: Int -> BuildSuggesters -> ShowS
Prelude.Show, (forall x. BuildSuggesters -> Rep BuildSuggesters x)
-> (forall x. Rep BuildSuggesters x -> BuildSuggesters)
-> Generic BuildSuggesters
forall x. Rep BuildSuggesters x -> BuildSuggesters
forall x. BuildSuggesters -> Rep BuildSuggesters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BuildSuggesters x -> BuildSuggesters
$cfrom :: forall x. BuildSuggesters -> Rep BuildSuggesters x
Prelude.Generic)

-- |
-- Create a value of 'BuildSuggesters' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'domainName', 'buildSuggesters_domainName' - Undocumented member.
newBuildSuggesters ::
  -- | 'domainName'
  Prelude.Text ->
  BuildSuggesters
newBuildSuggesters :: Text -> BuildSuggesters
newBuildSuggesters Text
pDomainName_ =
  BuildSuggesters' :: Text -> BuildSuggesters
BuildSuggesters' {$sel:domainName:BuildSuggesters' :: Text
domainName = Text
pDomainName_}

-- | Undocumented member.
buildSuggesters_domainName :: Lens.Lens' BuildSuggesters Prelude.Text
buildSuggesters_domainName :: (Text -> f Text) -> BuildSuggesters -> f BuildSuggesters
buildSuggesters_domainName = (BuildSuggesters -> Text)
-> (BuildSuggesters -> Text -> BuildSuggesters)
-> Lens BuildSuggesters BuildSuggesters Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BuildSuggesters' {Text
domainName :: Text
$sel:domainName:BuildSuggesters' :: BuildSuggesters -> Text
domainName} -> Text
domainName) (\s :: BuildSuggesters
s@BuildSuggesters' {} Text
a -> BuildSuggesters
s {$sel:domainName:BuildSuggesters' :: Text
domainName = Text
a} :: BuildSuggesters)

instance Core.AWSRequest BuildSuggesters where
  type
    AWSResponse BuildSuggesters =
      BuildSuggestersResponse
  request :: BuildSuggesters -> Request BuildSuggesters
request = Service -> BuildSuggesters -> Request BuildSuggesters
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy BuildSuggesters
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BuildSuggesters)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse BuildSuggesters))
-> Logger
-> Service
-> Proxy BuildSuggesters
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BuildSuggesters)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"BuildSuggestersResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [Text] -> Int -> BuildSuggestersResponse
BuildSuggestersResponse'
            (Maybe [Text] -> Int -> BuildSuggestersResponse)
-> Either String (Maybe [Text])
-> Either String (Int -> BuildSuggestersResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"FieldNames" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                            Either String [Node]
-> ([Node] -> Either String (Maybe [Text]))
-> Either String (Maybe [Text])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Text])
-> [Node] -> Either String (Maybe [Text])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                        )
            Either String (Int -> BuildSuggestersResponse)
-> Either String Int -> Either String BuildSuggestersResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable BuildSuggesters

instance Prelude.NFData BuildSuggesters

instance Core.ToHeaders BuildSuggesters where
  toHeaders :: BuildSuggesters -> ResponseHeaders
toHeaders = ResponseHeaders -> BuildSuggesters -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath BuildSuggesters where
  toPath :: BuildSuggesters -> ByteString
toPath = ByteString -> BuildSuggesters -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery BuildSuggesters where
  toQuery :: BuildSuggesters -> QueryString
toQuery BuildSuggesters' {Text
domainName :: Text
$sel:domainName:BuildSuggesters' :: BuildSuggesters -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"BuildSuggesters" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2013-01-01" :: Prelude.ByteString),
        ByteString
"DomainName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
domainName
      ]

-- | The result of a @BuildSuggester@ request. Contains a list of the fields
-- used for suggestions.
--
-- /See:/ 'newBuildSuggestersResponse' smart constructor.
data BuildSuggestersResponse = BuildSuggestersResponse'
  { BuildSuggestersResponse -> Maybe [Text]
fieldNames :: Prelude.Maybe [Prelude.Text],
    -- | The response's http status code.
    BuildSuggestersResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BuildSuggestersResponse -> BuildSuggestersResponse -> Bool
(BuildSuggestersResponse -> BuildSuggestersResponse -> Bool)
-> (BuildSuggestersResponse -> BuildSuggestersResponse -> Bool)
-> Eq BuildSuggestersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildSuggestersResponse -> BuildSuggestersResponse -> Bool
$c/= :: BuildSuggestersResponse -> BuildSuggestersResponse -> Bool
== :: BuildSuggestersResponse -> BuildSuggestersResponse -> Bool
$c== :: BuildSuggestersResponse -> BuildSuggestersResponse -> Bool
Prelude.Eq, ReadPrec [BuildSuggestersResponse]
ReadPrec BuildSuggestersResponse
Int -> ReadS BuildSuggestersResponse
ReadS [BuildSuggestersResponse]
(Int -> ReadS BuildSuggestersResponse)
-> ReadS [BuildSuggestersResponse]
-> ReadPrec BuildSuggestersResponse
-> ReadPrec [BuildSuggestersResponse]
-> Read BuildSuggestersResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BuildSuggestersResponse]
$creadListPrec :: ReadPrec [BuildSuggestersResponse]
readPrec :: ReadPrec BuildSuggestersResponse
$creadPrec :: ReadPrec BuildSuggestersResponse
readList :: ReadS [BuildSuggestersResponse]
$creadList :: ReadS [BuildSuggestersResponse]
readsPrec :: Int -> ReadS BuildSuggestersResponse
$creadsPrec :: Int -> ReadS BuildSuggestersResponse
Prelude.Read, Int -> BuildSuggestersResponse -> ShowS
[BuildSuggestersResponse] -> ShowS
BuildSuggestersResponse -> String
(Int -> BuildSuggestersResponse -> ShowS)
-> (BuildSuggestersResponse -> String)
-> ([BuildSuggestersResponse] -> ShowS)
-> Show BuildSuggestersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildSuggestersResponse] -> ShowS
$cshowList :: [BuildSuggestersResponse] -> ShowS
show :: BuildSuggestersResponse -> String
$cshow :: BuildSuggestersResponse -> String
showsPrec :: Int -> BuildSuggestersResponse -> ShowS
$cshowsPrec :: Int -> BuildSuggestersResponse -> ShowS
Prelude.Show, (forall x.
 BuildSuggestersResponse -> Rep BuildSuggestersResponse x)
-> (forall x.
    Rep BuildSuggestersResponse x -> BuildSuggestersResponse)
-> Generic BuildSuggestersResponse
forall x. Rep BuildSuggestersResponse x -> BuildSuggestersResponse
forall x. BuildSuggestersResponse -> Rep BuildSuggestersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BuildSuggestersResponse x -> BuildSuggestersResponse
$cfrom :: forall x. BuildSuggestersResponse -> Rep BuildSuggestersResponse x
Prelude.Generic)

-- |
-- Create a value of 'BuildSuggestersResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'fieldNames', 'buildSuggestersResponse_fieldNames' - Undocumented member.
--
-- 'httpStatus', 'buildSuggestersResponse_httpStatus' - The response's http status code.
newBuildSuggestersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BuildSuggestersResponse
newBuildSuggestersResponse :: Int -> BuildSuggestersResponse
newBuildSuggestersResponse Int
pHttpStatus_ =
  BuildSuggestersResponse' :: Maybe [Text] -> Int -> BuildSuggestersResponse
BuildSuggestersResponse'
    { $sel:fieldNames:BuildSuggestersResponse' :: Maybe [Text]
fieldNames =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BuildSuggestersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
buildSuggestersResponse_fieldNames :: Lens.Lens' BuildSuggestersResponse (Prelude.Maybe [Prelude.Text])
buildSuggestersResponse_fieldNames :: (Maybe [Text] -> f (Maybe [Text]))
-> BuildSuggestersResponse -> f BuildSuggestersResponse
buildSuggestersResponse_fieldNames = (BuildSuggestersResponse -> Maybe [Text])
-> (BuildSuggestersResponse
    -> Maybe [Text] -> BuildSuggestersResponse)
-> Lens
     BuildSuggestersResponse
     BuildSuggestersResponse
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BuildSuggestersResponse' {Maybe [Text]
fieldNames :: Maybe [Text]
$sel:fieldNames:BuildSuggestersResponse' :: BuildSuggestersResponse -> Maybe [Text]
fieldNames} -> Maybe [Text]
fieldNames) (\s :: BuildSuggestersResponse
s@BuildSuggestersResponse' {} Maybe [Text]
a -> BuildSuggestersResponse
s {$sel:fieldNames:BuildSuggestersResponse' :: Maybe [Text]
fieldNames = Maybe [Text]
a} :: BuildSuggestersResponse) ((Maybe [Text] -> f (Maybe [Text]))
 -> BuildSuggestersResponse -> f BuildSuggestersResponse)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> BuildSuggestersResponse
-> f BuildSuggestersResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
buildSuggestersResponse_httpStatus :: Lens.Lens' BuildSuggestersResponse Prelude.Int
buildSuggestersResponse_httpStatus :: (Int -> f Int)
-> BuildSuggestersResponse -> f BuildSuggestersResponse
buildSuggestersResponse_httpStatus = (BuildSuggestersResponse -> Int)
-> (BuildSuggestersResponse -> Int -> BuildSuggestersResponse)
-> Lens BuildSuggestersResponse BuildSuggestersResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BuildSuggestersResponse' {Int
httpStatus :: Int
$sel:httpStatus:BuildSuggestersResponse' :: BuildSuggestersResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BuildSuggestersResponse
s@BuildSuggestersResponse' {} Int
a -> BuildSuggestersResponse
s {$sel:httpStatus:BuildSuggestersResponse' :: Int
httpStatus = Int
a} :: BuildSuggestersResponse)

instance Prelude.NFData BuildSuggestersResponse