{-# 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.DefineExpression
-- 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 @Expression@ for the search domain. Used to create new
-- expressions and modify existing ones. If the expression exists, the new
-- configuration replaces the old one. For more information, see
-- <http://docs.aws.amazon.com/cloudsearch/latest/developerguide/configuring-expressions.html Configuring Expressions>
-- in the /Amazon CloudSearch Developer Guide/.
module Amazonka.CloudSearch.DefineExpression
  ( -- * Creating a Request
    DefineExpression (..),
    newDefineExpression,

    -- * Request Lenses
    defineExpression_domainName,
    defineExpression_expression,

    -- * Destructuring the Response
    DefineExpressionResponse (..),
    newDefineExpressionResponse,

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

-- |
-- Create a value of 'DefineExpression' 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', 'defineExpression_domainName' - Undocumented member.
--
-- 'expression', 'defineExpression_expression' - Undocumented member.
newDefineExpression ::
  -- | 'domainName'
  Prelude.Text ->
  -- | 'expression'
  Expression ->
  DefineExpression
newDefineExpression :: Text -> Expression -> DefineExpression
newDefineExpression Text
pDomainName_ Expression
pExpression_ =
  DefineExpression' :: Text -> Expression -> DefineExpression
DefineExpression'
    { $sel:domainName:DefineExpression' :: Text
domainName = Text
pDomainName_,
      $sel:expression:DefineExpression' :: Expression
expression = Expression
pExpression_
    }

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

-- | Undocumented member.
defineExpression_expression :: Lens.Lens' DefineExpression Expression
defineExpression_expression :: (Expression -> f Expression)
-> DefineExpression -> f DefineExpression
defineExpression_expression = (DefineExpression -> Expression)
-> (DefineExpression -> Expression -> DefineExpression)
-> Lens DefineExpression DefineExpression Expression Expression
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefineExpression' {Expression
expression :: Expression
$sel:expression:DefineExpression' :: DefineExpression -> Expression
expression} -> Expression
expression) (\s :: DefineExpression
s@DefineExpression' {} Expression
a -> DefineExpression
s {$sel:expression:DefineExpression' :: Expression
expression = Expression
a} :: DefineExpression)

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

instance Prelude.Hashable DefineExpression

instance Prelude.NFData DefineExpression

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

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

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

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

-- |
-- Create a value of 'DefineExpressionResponse' 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', 'defineExpressionResponse_httpStatus' - The response's http status code.
--
-- 'expression', 'defineExpressionResponse_expression' - Undocumented member.
newDefineExpressionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'expression'
  ExpressionStatus ->
  DefineExpressionResponse
newDefineExpressionResponse :: Int -> ExpressionStatus -> DefineExpressionResponse
newDefineExpressionResponse Int
pHttpStatus_ ExpressionStatus
pExpression_ =
  DefineExpressionResponse' :: Int -> ExpressionStatus -> DefineExpressionResponse
DefineExpressionResponse'
    { $sel:httpStatus:DefineExpressionResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:expression:DefineExpressionResponse' :: ExpressionStatus
expression = ExpressionStatus
pExpression_
    }

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

-- | Undocumented member.
defineExpressionResponse_expression :: Lens.Lens' DefineExpressionResponse ExpressionStatus
defineExpressionResponse_expression :: (ExpressionStatus -> f ExpressionStatus)
-> DefineExpressionResponse -> f DefineExpressionResponse
defineExpressionResponse_expression = (DefineExpressionResponse -> ExpressionStatus)
-> (DefineExpressionResponse
    -> ExpressionStatus -> DefineExpressionResponse)
-> Lens
     DefineExpressionResponse
     DefineExpressionResponse
     ExpressionStatus
     ExpressionStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefineExpressionResponse' {ExpressionStatus
expression :: ExpressionStatus
$sel:expression:DefineExpressionResponse' :: DefineExpressionResponse -> ExpressionStatus
expression} -> ExpressionStatus
expression) (\s :: DefineExpressionResponse
s@DefineExpressionResponse' {} ExpressionStatus
a -> DefineExpressionResponse
s {$sel:expression:DefineExpressionResponse' :: ExpressionStatus
expression = ExpressionStatus
a} :: DefineExpressionResponse)

instance Prelude.NFData DefineExpressionResponse