{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.Expression
-- 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)
module Amazonka.CloudSearch.Types.Expression where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A named expression that can be evaluated at search time. Can be used to
-- sort the search results, define other expressions, or return computed
-- information in the search results.
--
-- /See:/ 'newExpression' smart constructor.
data Expression = Expression'
  { Expression -> Text
expressionName :: Prelude.Text,
    Expression -> Text
expressionValue :: Prelude.Text
  }
  deriving (Expression -> Expression -> Bool
(Expression -> Expression -> Bool)
-> (Expression -> Expression -> Bool) -> Eq Expression
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Expression -> Expression -> Bool
$c/= :: Expression -> Expression -> Bool
== :: Expression -> Expression -> Bool
$c== :: Expression -> Expression -> Bool
Prelude.Eq, ReadPrec [Expression]
ReadPrec Expression
Int -> ReadS Expression
ReadS [Expression]
(Int -> ReadS Expression)
-> ReadS [Expression]
-> ReadPrec Expression
-> ReadPrec [Expression]
-> Read Expression
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Expression]
$creadListPrec :: ReadPrec [Expression]
readPrec :: ReadPrec Expression
$creadPrec :: ReadPrec Expression
readList :: ReadS [Expression]
$creadList :: ReadS [Expression]
readsPrec :: Int -> ReadS Expression
$creadsPrec :: Int -> ReadS Expression
Prelude.Read, Int -> Expression -> ShowS
[Expression] -> ShowS
Expression -> String
(Int -> Expression -> ShowS)
-> (Expression -> String)
-> ([Expression] -> ShowS)
-> Show Expression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Expression] -> ShowS
$cshowList :: [Expression] -> ShowS
show :: Expression -> String
$cshow :: Expression -> String
showsPrec :: Int -> Expression -> ShowS
$cshowsPrec :: Int -> Expression -> ShowS
Prelude.Show, (forall x. Expression -> Rep Expression x)
-> (forall x. Rep Expression x -> Expression) -> Generic Expression
forall x. Rep Expression x -> Expression
forall x. Expression -> Rep Expression x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Expression x -> Expression
$cfrom :: forall x. Expression -> Rep Expression x
Prelude.Generic)

-- |
-- Create a value of 'Expression' 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:
--
-- 'expressionName', 'expression_expressionName' - Undocumented member.
--
-- 'expressionValue', 'expression_expressionValue' - Undocumented member.
newExpression ::
  -- | 'expressionName'
  Prelude.Text ->
  -- | 'expressionValue'
  Prelude.Text ->
  Expression
newExpression :: Text -> Text -> Expression
newExpression Text
pExpressionName_ Text
pExpressionValue_ =
  Expression' :: Text -> Text -> Expression
Expression'
    { $sel:expressionName:Expression' :: Text
expressionName = Text
pExpressionName_,
      $sel:expressionValue:Expression' :: Text
expressionValue = Text
pExpressionValue_
    }

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

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

instance Core.FromXML Expression where
  parseXML :: [Node] -> Either String Expression
parseXML [Node]
x =
    Text -> Text -> Expression
Expression'
      (Text -> Text -> Expression)
-> Either String Text -> Either String (Text -> Expression)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ExpressionName")
      Either String (Text -> Expression)
-> Either String Text -> Either String Expression
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ExpressionValue")

instance Prelude.Hashable Expression

instance Prelude.NFData Expression

instance Core.ToQuery Expression where
  toQuery :: Expression -> QueryString
toQuery Expression' {Text
expressionValue :: Text
expressionName :: Text
$sel:expressionValue:Expression' :: Expression -> Text
$sel:expressionName:Expression' :: Expression -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"ExpressionName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
expressionName,
        ByteString
"ExpressionValue" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
expressionValue
      ]