{-# 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.DefineIndexField
-- 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)
--
-- Configures an @IndexField@ for the search domain. Used to create new
-- fields and modify existing ones. You must specify the name of the domain
-- you are configuring and an index field configuration. The index field
-- configuration specifies a unique name, the index field type, and the
-- options you want to configure for the field. The options you can specify
-- depend on the @IndexFieldType@. If the field exists, the new
-- configuration replaces the old one. For more information, see
-- <http://docs.aws.amazon.com/cloudsearch/latest/developerguide/configuring-index-fields.html Configuring Index Fields>
-- in the /Amazon CloudSearch Developer Guide/.
module Amazonka.CloudSearch.DefineIndexField
  ( -- * Creating a Request
    DefineIndexField (..),
    newDefineIndexField,

    -- * Request Lenses
    defineIndexField_domainName,
    defineIndexField_indexField,

    -- * Destructuring the Response
    DefineIndexFieldResponse (..),
    newDefineIndexFieldResponse,

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

-- |
-- Create a value of 'DefineIndexField' 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', 'defineIndexField_domainName' - Undocumented member.
--
-- 'indexField', 'defineIndexField_indexField' - The index field and field options you want to configure.
newDefineIndexField ::
  -- | 'domainName'
  Prelude.Text ->
  -- | 'indexField'
  IndexField ->
  DefineIndexField
newDefineIndexField :: Text -> IndexField -> DefineIndexField
newDefineIndexField Text
pDomainName_ IndexField
pIndexField_ =
  DefineIndexField' :: Text -> IndexField -> DefineIndexField
DefineIndexField'
    { $sel:domainName:DefineIndexField' :: Text
domainName = Text
pDomainName_,
      $sel:indexField:DefineIndexField' :: IndexField
indexField = IndexField
pIndexField_
    }

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

-- | The index field and field options you want to configure.
defineIndexField_indexField :: Lens.Lens' DefineIndexField IndexField
defineIndexField_indexField :: (IndexField -> f IndexField)
-> DefineIndexField -> f DefineIndexField
defineIndexField_indexField = (DefineIndexField -> IndexField)
-> (DefineIndexField -> IndexField -> DefineIndexField)
-> Lens DefineIndexField DefineIndexField IndexField IndexField
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefineIndexField' {IndexField
indexField :: IndexField
$sel:indexField:DefineIndexField' :: DefineIndexField -> IndexField
indexField} -> IndexField
indexField) (\s :: DefineIndexField
s@DefineIndexField' {} IndexField
a -> DefineIndexField
s {$sel:indexField:DefineIndexField' :: IndexField
indexField = IndexField
a} :: DefineIndexField)

instance Core.AWSRequest DefineIndexField where
  type
    AWSResponse DefineIndexField =
      DefineIndexFieldResponse
  request :: DefineIndexField -> Request DefineIndexField
request = Service -> DefineIndexField -> Request DefineIndexField
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy DefineIndexField
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DefineIndexField)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse DefineIndexField))
-> Logger
-> Service
-> Proxy DefineIndexField
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DefineIndexField)))
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
"DefineIndexFieldResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> IndexFieldStatus -> DefineIndexFieldResponse
DefineIndexFieldResponse'
            (Int -> IndexFieldStatus -> DefineIndexFieldResponse)
-> Either String Int
-> Either String (IndexFieldStatus -> DefineIndexFieldResponse)
forall (f :: * -> *) a b. Functor 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))
            Either String (IndexFieldStatus -> DefineIndexFieldResponse)
-> Either String IndexFieldStatus
-> Either String DefineIndexFieldResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String IndexFieldStatus
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"IndexField")
      )

instance Prelude.Hashable DefineIndexField

instance Prelude.NFData DefineIndexField

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

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

instance Core.ToQuery DefineIndexField where
  toQuery :: DefineIndexField -> QueryString
toQuery DefineIndexField' {Text
IndexField
indexField :: IndexField
domainName :: Text
$sel:indexField:DefineIndexField' :: DefineIndexField -> IndexField
$sel:domainName:DefineIndexField' :: DefineIndexField -> 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
"DefineIndexField" :: 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,
        ByteString
"IndexField" ByteString -> IndexField -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: IndexField
indexField
      ]

-- | The result of a @DefineIndexField@ request. Contains the status of the
-- newly-configured index field.
--
-- /See:/ 'newDefineIndexFieldResponse' smart constructor.
data DefineIndexFieldResponse = DefineIndexFieldResponse'
  { -- | The response's http status code.
    DefineIndexFieldResponse -> Int
httpStatus :: Prelude.Int,
    DefineIndexFieldResponse -> IndexFieldStatus
indexField :: IndexFieldStatus
  }
  deriving (DefineIndexFieldResponse -> DefineIndexFieldResponse -> Bool
(DefineIndexFieldResponse -> DefineIndexFieldResponse -> Bool)
-> (DefineIndexFieldResponse -> DefineIndexFieldResponse -> Bool)
-> Eq DefineIndexFieldResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DefineIndexFieldResponse -> DefineIndexFieldResponse -> Bool
$c/= :: DefineIndexFieldResponse -> DefineIndexFieldResponse -> Bool
== :: DefineIndexFieldResponse -> DefineIndexFieldResponse -> Bool
$c== :: DefineIndexFieldResponse -> DefineIndexFieldResponse -> Bool
Prelude.Eq, ReadPrec [DefineIndexFieldResponse]
ReadPrec DefineIndexFieldResponse
Int -> ReadS DefineIndexFieldResponse
ReadS [DefineIndexFieldResponse]
(Int -> ReadS DefineIndexFieldResponse)
-> ReadS [DefineIndexFieldResponse]
-> ReadPrec DefineIndexFieldResponse
-> ReadPrec [DefineIndexFieldResponse]
-> Read DefineIndexFieldResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DefineIndexFieldResponse]
$creadListPrec :: ReadPrec [DefineIndexFieldResponse]
readPrec :: ReadPrec DefineIndexFieldResponse
$creadPrec :: ReadPrec DefineIndexFieldResponse
readList :: ReadS [DefineIndexFieldResponse]
$creadList :: ReadS [DefineIndexFieldResponse]
readsPrec :: Int -> ReadS DefineIndexFieldResponse
$creadsPrec :: Int -> ReadS DefineIndexFieldResponse
Prelude.Read, Int -> DefineIndexFieldResponse -> ShowS
[DefineIndexFieldResponse] -> ShowS
DefineIndexFieldResponse -> String
(Int -> DefineIndexFieldResponse -> ShowS)
-> (DefineIndexFieldResponse -> String)
-> ([DefineIndexFieldResponse] -> ShowS)
-> Show DefineIndexFieldResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefineIndexFieldResponse] -> ShowS
$cshowList :: [DefineIndexFieldResponse] -> ShowS
show :: DefineIndexFieldResponse -> String
$cshow :: DefineIndexFieldResponse -> String
showsPrec :: Int -> DefineIndexFieldResponse -> ShowS
$cshowsPrec :: Int -> DefineIndexFieldResponse -> ShowS
Prelude.Show, (forall x.
 DefineIndexFieldResponse -> Rep DefineIndexFieldResponse x)
-> (forall x.
    Rep DefineIndexFieldResponse x -> DefineIndexFieldResponse)
-> Generic DefineIndexFieldResponse
forall x.
Rep DefineIndexFieldResponse x -> DefineIndexFieldResponse
forall x.
DefineIndexFieldResponse -> Rep DefineIndexFieldResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DefineIndexFieldResponse x -> DefineIndexFieldResponse
$cfrom :: forall x.
DefineIndexFieldResponse -> Rep DefineIndexFieldResponse x
Prelude.Generic)

-- |
-- Create a value of 'DefineIndexFieldResponse' 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:
--
-- 'httpStatus', 'defineIndexFieldResponse_httpStatus' - The response's http status code.
--
-- 'indexField', 'defineIndexFieldResponse_indexField' - Undocumented member.
newDefineIndexFieldResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'indexField'
  IndexFieldStatus ->
  DefineIndexFieldResponse
newDefineIndexFieldResponse :: Int -> IndexFieldStatus -> DefineIndexFieldResponse
newDefineIndexFieldResponse Int
pHttpStatus_ IndexFieldStatus
pIndexField_ =
  DefineIndexFieldResponse' :: Int -> IndexFieldStatus -> DefineIndexFieldResponse
DefineIndexFieldResponse'
    { $sel:httpStatus:DefineIndexFieldResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:indexField:DefineIndexFieldResponse' :: IndexFieldStatus
indexField = IndexFieldStatus
pIndexField_
    }

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

-- | Undocumented member.
defineIndexFieldResponse_indexField :: Lens.Lens' DefineIndexFieldResponse IndexFieldStatus
defineIndexFieldResponse_indexField :: (IndexFieldStatus -> f IndexFieldStatus)
-> DefineIndexFieldResponse -> f DefineIndexFieldResponse
defineIndexFieldResponse_indexField = (DefineIndexFieldResponse -> IndexFieldStatus)
-> (DefineIndexFieldResponse
    -> IndexFieldStatus -> DefineIndexFieldResponse)
-> Lens
     DefineIndexFieldResponse
     DefineIndexFieldResponse
     IndexFieldStatus
     IndexFieldStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefineIndexFieldResponse' {IndexFieldStatus
indexField :: IndexFieldStatus
$sel:indexField:DefineIndexFieldResponse' :: DefineIndexFieldResponse -> IndexFieldStatus
indexField} -> IndexFieldStatus
indexField) (\s :: DefineIndexFieldResponse
s@DefineIndexFieldResponse' {} IndexFieldStatus
a -> DefineIndexFieldResponse
s {$sel:indexField:DefineIndexFieldResponse' :: IndexFieldStatus
indexField = IndexFieldStatus
a} :: DefineIndexFieldResponse)

instance Prelude.NFData DefineIndexFieldResponse