{-# 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.IndexDocuments
-- 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)
--
-- Tells the search domain to start indexing its documents using the latest
-- indexing options. This operation must be invoked to activate options
-- whose OptionStatus is @RequiresIndexDocuments@.
module Amazonka.CloudSearch.IndexDocuments
  ( -- * Creating a Request
    IndexDocuments (..),
    newIndexDocuments,

    -- * Request Lenses
    indexDocuments_domainName,

    -- * Destructuring the Response
    IndexDocumentsResponse (..),
    newIndexDocumentsResponse,

    -- * Response Lenses
    indexDocumentsResponse_fieldNames,
    indexDocumentsResponse_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 @IndexDocuments@ operation.
-- Specifies the name of the domain you want to re-index.
--
-- /See:/ 'newIndexDocuments' smart constructor.
data IndexDocuments = IndexDocuments'
  { IndexDocuments -> Text
domainName :: Prelude.Text
  }
  deriving (IndexDocuments -> IndexDocuments -> Bool
(IndexDocuments -> IndexDocuments -> Bool)
-> (IndexDocuments -> IndexDocuments -> Bool) -> Eq IndexDocuments
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndexDocuments -> IndexDocuments -> Bool
$c/= :: IndexDocuments -> IndexDocuments -> Bool
== :: IndexDocuments -> IndexDocuments -> Bool
$c== :: IndexDocuments -> IndexDocuments -> Bool
Prelude.Eq, ReadPrec [IndexDocuments]
ReadPrec IndexDocuments
Int -> ReadS IndexDocuments
ReadS [IndexDocuments]
(Int -> ReadS IndexDocuments)
-> ReadS [IndexDocuments]
-> ReadPrec IndexDocuments
-> ReadPrec [IndexDocuments]
-> Read IndexDocuments
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IndexDocuments]
$creadListPrec :: ReadPrec [IndexDocuments]
readPrec :: ReadPrec IndexDocuments
$creadPrec :: ReadPrec IndexDocuments
readList :: ReadS [IndexDocuments]
$creadList :: ReadS [IndexDocuments]
readsPrec :: Int -> ReadS IndexDocuments
$creadsPrec :: Int -> ReadS IndexDocuments
Prelude.Read, Int -> IndexDocuments -> ShowS
[IndexDocuments] -> ShowS
IndexDocuments -> String
(Int -> IndexDocuments -> ShowS)
-> (IndexDocuments -> String)
-> ([IndexDocuments] -> ShowS)
-> Show IndexDocuments
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IndexDocuments] -> ShowS
$cshowList :: [IndexDocuments] -> ShowS
show :: IndexDocuments -> String
$cshow :: IndexDocuments -> String
showsPrec :: Int -> IndexDocuments -> ShowS
$cshowsPrec :: Int -> IndexDocuments -> ShowS
Prelude.Show, (forall x. IndexDocuments -> Rep IndexDocuments x)
-> (forall x. Rep IndexDocuments x -> IndexDocuments)
-> Generic IndexDocuments
forall x. Rep IndexDocuments x -> IndexDocuments
forall x. IndexDocuments -> Rep IndexDocuments x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IndexDocuments x -> IndexDocuments
$cfrom :: forall x. IndexDocuments -> Rep IndexDocuments x
Prelude.Generic)

-- |
-- Create a value of 'IndexDocuments' 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', 'indexDocuments_domainName' - Undocumented member.
newIndexDocuments ::
  -- | 'domainName'
  Prelude.Text ->
  IndexDocuments
newIndexDocuments :: Text -> IndexDocuments
newIndexDocuments Text
pDomainName_ =
  IndexDocuments' :: Text -> IndexDocuments
IndexDocuments' {$sel:domainName:IndexDocuments' :: Text
domainName = Text
pDomainName_}

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

instance Core.AWSRequest IndexDocuments where
  type
    AWSResponse IndexDocuments =
      IndexDocumentsResponse
  request :: IndexDocuments -> Request IndexDocuments
request = Service -> IndexDocuments -> Request IndexDocuments
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy IndexDocuments
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse IndexDocuments)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse IndexDocuments))
-> Logger
-> Service
-> Proxy IndexDocuments
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse IndexDocuments)))
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
"IndexDocumentsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [Text] -> Int -> IndexDocumentsResponse
IndexDocumentsResponse'
            (Maybe [Text] -> Int -> IndexDocumentsResponse)
-> Either String (Maybe [Text])
-> Either String (Int -> IndexDocumentsResponse)
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 -> IndexDocumentsResponse)
-> Either String Int -> Either String IndexDocumentsResponse
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 IndexDocuments

instance Prelude.NFData IndexDocuments

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

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

instance Core.ToQuery IndexDocuments where
  toQuery :: IndexDocuments -> QueryString
toQuery IndexDocuments' {Text
domainName :: Text
$sel:domainName:IndexDocuments' :: IndexDocuments -> 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
"IndexDocuments" :: 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 an @IndexDocuments@ request. Contains the status of the
-- indexing operation, including the fields being indexed.
--
-- /See:/ 'newIndexDocumentsResponse' smart constructor.
data IndexDocumentsResponse = IndexDocumentsResponse'
  { -- | The names of the fields that are currently being indexed.
    IndexDocumentsResponse -> Maybe [Text]
fieldNames :: Prelude.Maybe [Prelude.Text],
    -- | The response's http status code.
    IndexDocumentsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (IndexDocumentsResponse -> IndexDocumentsResponse -> Bool
(IndexDocumentsResponse -> IndexDocumentsResponse -> Bool)
-> (IndexDocumentsResponse -> IndexDocumentsResponse -> Bool)
-> Eq IndexDocumentsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndexDocumentsResponse -> IndexDocumentsResponse -> Bool
$c/= :: IndexDocumentsResponse -> IndexDocumentsResponse -> Bool
== :: IndexDocumentsResponse -> IndexDocumentsResponse -> Bool
$c== :: IndexDocumentsResponse -> IndexDocumentsResponse -> Bool
Prelude.Eq, ReadPrec [IndexDocumentsResponse]
ReadPrec IndexDocumentsResponse
Int -> ReadS IndexDocumentsResponse
ReadS [IndexDocumentsResponse]
(Int -> ReadS IndexDocumentsResponse)
-> ReadS [IndexDocumentsResponse]
-> ReadPrec IndexDocumentsResponse
-> ReadPrec [IndexDocumentsResponse]
-> Read IndexDocumentsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IndexDocumentsResponse]
$creadListPrec :: ReadPrec [IndexDocumentsResponse]
readPrec :: ReadPrec IndexDocumentsResponse
$creadPrec :: ReadPrec IndexDocumentsResponse
readList :: ReadS [IndexDocumentsResponse]
$creadList :: ReadS [IndexDocumentsResponse]
readsPrec :: Int -> ReadS IndexDocumentsResponse
$creadsPrec :: Int -> ReadS IndexDocumentsResponse
Prelude.Read, Int -> IndexDocumentsResponse -> ShowS
[IndexDocumentsResponse] -> ShowS
IndexDocumentsResponse -> String
(Int -> IndexDocumentsResponse -> ShowS)
-> (IndexDocumentsResponse -> String)
-> ([IndexDocumentsResponse] -> ShowS)
-> Show IndexDocumentsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IndexDocumentsResponse] -> ShowS
$cshowList :: [IndexDocumentsResponse] -> ShowS
show :: IndexDocumentsResponse -> String
$cshow :: IndexDocumentsResponse -> String
showsPrec :: Int -> IndexDocumentsResponse -> ShowS
$cshowsPrec :: Int -> IndexDocumentsResponse -> ShowS
Prelude.Show, (forall x. IndexDocumentsResponse -> Rep IndexDocumentsResponse x)
-> (forall x.
    Rep IndexDocumentsResponse x -> IndexDocumentsResponse)
-> Generic IndexDocumentsResponse
forall x. Rep IndexDocumentsResponse x -> IndexDocumentsResponse
forall x. IndexDocumentsResponse -> Rep IndexDocumentsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IndexDocumentsResponse x -> IndexDocumentsResponse
$cfrom :: forall x. IndexDocumentsResponse -> Rep IndexDocumentsResponse x
Prelude.Generic)

-- |
-- Create a value of 'IndexDocumentsResponse' 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', 'indexDocumentsResponse_fieldNames' - The names of the fields that are currently being indexed.
--
-- 'httpStatus', 'indexDocumentsResponse_httpStatus' - The response's http status code.
newIndexDocumentsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  IndexDocumentsResponse
newIndexDocumentsResponse :: Int -> IndexDocumentsResponse
newIndexDocumentsResponse Int
pHttpStatus_ =
  IndexDocumentsResponse' :: Maybe [Text] -> Int -> IndexDocumentsResponse
IndexDocumentsResponse'
    { $sel:fieldNames:IndexDocumentsResponse' :: Maybe [Text]
fieldNames =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:IndexDocumentsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The names of the fields that are currently being indexed.
indexDocumentsResponse_fieldNames :: Lens.Lens' IndexDocumentsResponse (Prelude.Maybe [Prelude.Text])
indexDocumentsResponse_fieldNames :: (Maybe [Text] -> f (Maybe [Text]))
-> IndexDocumentsResponse -> f IndexDocumentsResponse
indexDocumentsResponse_fieldNames = (IndexDocumentsResponse -> Maybe [Text])
-> (IndexDocumentsResponse
    -> Maybe [Text] -> IndexDocumentsResponse)
-> Lens
     IndexDocumentsResponse
     IndexDocumentsResponse
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IndexDocumentsResponse' {Maybe [Text]
fieldNames :: Maybe [Text]
$sel:fieldNames:IndexDocumentsResponse' :: IndexDocumentsResponse -> Maybe [Text]
fieldNames} -> Maybe [Text]
fieldNames) (\s :: IndexDocumentsResponse
s@IndexDocumentsResponse' {} Maybe [Text]
a -> IndexDocumentsResponse
s {$sel:fieldNames:IndexDocumentsResponse' :: Maybe [Text]
fieldNames = Maybe [Text]
a} :: IndexDocumentsResponse) ((Maybe [Text] -> f (Maybe [Text]))
 -> IndexDocumentsResponse -> f IndexDocumentsResponse)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> IndexDocumentsResponse
-> f IndexDocumentsResponse
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.
indexDocumentsResponse_httpStatus :: Lens.Lens' IndexDocumentsResponse Prelude.Int
indexDocumentsResponse_httpStatus :: (Int -> f Int)
-> IndexDocumentsResponse -> f IndexDocumentsResponse
indexDocumentsResponse_httpStatus = (IndexDocumentsResponse -> Int)
-> (IndexDocumentsResponse -> Int -> IndexDocumentsResponse)
-> Lens IndexDocumentsResponse IndexDocumentsResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IndexDocumentsResponse' {Int
httpStatus :: Int
$sel:httpStatus:IndexDocumentsResponse' :: IndexDocumentsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: IndexDocumentsResponse
s@IndexDocumentsResponse' {} Int
a -> IndexDocumentsResponse
s {$sel:httpStatus:IndexDocumentsResponse' :: Int
httpStatus = Int
a} :: IndexDocumentsResponse)

instance Prelude.NFData IndexDocumentsResponse