{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$sel:domainName:IndexDocuments' :: Text
domainName = Text
pDomainName_}

-- | Undocumented member.
indexDocuments_domainName :: Lens.Lens' IndexDocuments Prelude.Text
indexDocuments_domainName :: Lens' IndexDocuments Text
indexDocuments_domainName = 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 :: (Service -> Service) -> IndexDocuments -> Request IndexDocuments
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy IndexDocuments
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse IndexDocuments)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> 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'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                            forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"FieldNames"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                            forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable IndexDocuments where
  hashWithSalt :: Int -> IndexDocuments -> Int
hashWithSalt Int
_salt IndexDocuments' {Text
domainName :: Text
$sel:domainName:IndexDocuments' :: IndexDocuments -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
domainName

instance Prelude.NFData IndexDocuments where
  rnf :: IndexDocuments -> ()
rnf IndexDocuments' {Text
domainName :: Text
$sel:domainName:IndexDocuments' :: IndexDocuments -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
domainName

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

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

instance Data.ToQuery IndexDocuments where
  toQuery :: IndexDocuments -> QueryString
toQuery IndexDocuments' {Text
domainName :: Text
$sel:domainName:IndexDocuments' :: IndexDocuments -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"IndexDocuments" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2013-01-01" :: Prelude.ByteString),
        ByteString
"DomainName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: 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
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]
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
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. 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'
    { $sel:fieldNames:IndexDocumentsResponse' :: Maybe [Text]
fieldNames =
        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 :: Lens' IndexDocumentsResponse (Maybe [Text])
indexDocumentsResponse_fieldNames = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' IndexDocumentsResponse Int
indexDocumentsResponse_httpStatus = 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 where
  rnf :: IndexDocumentsResponse -> ()
rnf IndexDocumentsResponse' {Int
Maybe [Text]
httpStatus :: Int
fieldNames :: Maybe [Text]
$sel:httpStatus:IndexDocumentsResponse' :: IndexDocumentsResponse -> Int
$sel:fieldNames:IndexDocumentsResponse' :: IndexDocumentsResponse -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
fieldNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus