{-# 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.DataPipeline.EvaluateExpression
-- 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)
--
-- Task runners call @EvaluateExpression@ to evaluate a string in the
-- context of the specified object. For example, a task runner can evaluate
-- SQL queries stored in Amazon S3.
module Amazonka.DataPipeline.EvaluateExpression
  ( -- * Creating a Request
    EvaluateExpression (..),
    newEvaluateExpression,

    -- * Request Lenses
    evaluateExpression_pipelineId,
    evaluateExpression_objectId,
    evaluateExpression_expression,

    -- * Destructuring the Response
    EvaluateExpressionResponse (..),
    newEvaluateExpressionResponse,

    -- * Response Lenses
    evaluateExpressionResponse_httpStatus,
    evaluateExpressionResponse_evaluatedExpression,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DataPipeline.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Contains the parameters for EvaluateExpression.
--
-- /See:/ 'newEvaluateExpression' smart constructor.
data EvaluateExpression = EvaluateExpression'
  { -- | The ID of the pipeline.
    EvaluateExpression -> Text
pipelineId :: Prelude.Text,
    -- | The ID of the object.
    EvaluateExpression -> Text
objectId :: Prelude.Text,
    -- | The expression to evaluate.
    EvaluateExpression -> Text
expression :: Prelude.Text
  }
  deriving (EvaluateExpression -> EvaluateExpression -> Bool
(EvaluateExpression -> EvaluateExpression -> Bool)
-> (EvaluateExpression -> EvaluateExpression -> Bool)
-> Eq EvaluateExpression
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EvaluateExpression -> EvaluateExpression -> Bool
$c/= :: EvaluateExpression -> EvaluateExpression -> Bool
== :: EvaluateExpression -> EvaluateExpression -> Bool
$c== :: EvaluateExpression -> EvaluateExpression -> Bool
Prelude.Eq, ReadPrec [EvaluateExpression]
ReadPrec EvaluateExpression
Int -> ReadS EvaluateExpression
ReadS [EvaluateExpression]
(Int -> ReadS EvaluateExpression)
-> ReadS [EvaluateExpression]
-> ReadPrec EvaluateExpression
-> ReadPrec [EvaluateExpression]
-> Read EvaluateExpression
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EvaluateExpression]
$creadListPrec :: ReadPrec [EvaluateExpression]
readPrec :: ReadPrec EvaluateExpression
$creadPrec :: ReadPrec EvaluateExpression
readList :: ReadS [EvaluateExpression]
$creadList :: ReadS [EvaluateExpression]
readsPrec :: Int -> ReadS EvaluateExpression
$creadsPrec :: Int -> ReadS EvaluateExpression
Prelude.Read, Int -> EvaluateExpression -> ShowS
[EvaluateExpression] -> ShowS
EvaluateExpression -> String
(Int -> EvaluateExpression -> ShowS)
-> (EvaluateExpression -> String)
-> ([EvaluateExpression] -> ShowS)
-> Show EvaluateExpression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EvaluateExpression] -> ShowS
$cshowList :: [EvaluateExpression] -> ShowS
show :: EvaluateExpression -> String
$cshow :: EvaluateExpression -> String
showsPrec :: Int -> EvaluateExpression -> ShowS
$cshowsPrec :: Int -> EvaluateExpression -> ShowS
Prelude.Show, (forall x. EvaluateExpression -> Rep EvaluateExpression x)
-> (forall x. Rep EvaluateExpression x -> EvaluateExpression)
-> Generic EvaluateExpression
forall x. Rep EvaluateExpression x -> EvaluateExpression
forall x. EvaluateExpression -> Rep EvaluateExpression x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EvaluateExpression x -> EvaluateExpression
$cfrom :: forall x. EvaluateExpression -> Rep EvaluateExpression x
Prelude.Generic)

-- |
-- Create a value of 'EvaluateExpression' 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:
--
-- 'pipelineId', 'evaluateExpression_pipelineId' - The ID of the pipeline.
--
-- 'objectId', 'evaluateExpression_objectId' - The ID of the object.
--
-- 'expression', 'evaluateExpression_expression' - The expression to evaluate.
newEvaluateExpression ::
  -- | 'pipelineId'
  Prelude.Text ->
  -- | 'objectId'
  Prelude.Text ->
  -- | 'expression'
  Prelude.Text ->
  EvaluateExpression
newEvaluateExpression :: Text -> Text -> Text -> EvaluateExpression
newEvaluateExpression
  Text
pPipelineId_
  Text
pObjectId_
  Text
pExpression_ =
    EvaluateExpression' :: Text -> Text -> Text -> EvaluateExpression
EvaluateExpression'
      { $sel:pipelineId:EvaluateExpression' :: Text
pipelineId = Text
pPipelineId_,
        $sel:objectId:EvaluateExpression' :: Text
objectId = Text
pObjectId_,
        $sel:expression:EvaluateExpression' :: Text
expression = Text
pExpression_
      }

-- | The ID of the pipeline.
evaluateExpression_pipelineId :: Lens.Lens' EvaluateExpression Prelude.Text
evaluateExpression_pipelineId :: (Text -> f Text) -> EvaluateExpression -> f EvaluateExpression
evaluateExpression_pipelineId = (EvaluateExpression -> Text)
-> (EvaluateExpression -> Text -> EvaluateExpression)
-> Lens EvaluateExpression EvaluateExpression Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateExpression' {Text
pipelineId :: Text
$sel:pipelineId:EvaluateExpression' :: EvaluateExpression -> Text
pipelineId} -> Text
pipelineId) (\s :: EvaluateExpression
s@EvaluateExpression' {} Text
a -> EvaluateExpression
s {$sel:pipelineId:EvaluateExpression' :: Text
pipelineId = Text
a} :: EvaluateExpression)

-- | The ID of the object.
evaluateExpression_objectId :: Lens.Lens' EvaluateExpression Prelude.Text
evaluateExpression_objectId :: (Text -> f Text) -> EvaluateExpression -> f EvaluateExpression
evaluateExpression_objectId = (EvaluateExpression -> Text)
-> (EvaluateExpression -> Text -> EvaluateExpression)
-> Lens EvaluateExpression EvaluateExpression Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateExpression' {Text
objectId :: Text
$sel:objectId:EvaluateExpression' :: EvaluateExpression -> Text
objectId} -> Text
objectId) (\s :: EvaluateExpression
s@EvaluateExpression' {} Text
a -> EvaluateExpression
s {$sel:objectId:EvaluateExpression' :: Text
objectId = Text
a} :: EvaluateExpression)

-- | The expression to evaluate.
evaluateExpression_expression :: Lens.Lens' EvaluateExpression Prelude.Text
evaluateExpression_expression :: (Text -> f Text) -> EvaluateExpression -> f EvaluateExpression
evaluateExpression_expression = (EvaluateExpression -> Text)
-> (EvaluateExpression -> Text -> EvaluateExpression)
-> Lens EvaluateExpression EvaluateExpression Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateExpression' {Text
expression :: Text
$sel:expression:EvaluateExpression' :: EvaluateExpression -> Text
expression} -> Text
expression) (\s :: EvaluateExpression
s@EvaluateExpression' {} Text
a -> EvaluateExpression
s {$sel:expression:EvaluateExpression' :: Text
expression = Text
a} :: EvaluateExpression)

instance Core.AWSRequest EvaluateExpression where
  type
    AWSResponse EvaluateExpression =
      EvaluateExpressionResponse
  request :: EvaluateExpression -> Request EvaluateExpression
request = Service -> EvaluateExpression -> Request EvaluateExpression
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy EvaluateExpression
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EvaluateExpression)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse EvaluateExpression))
-> Logger
-> Service
-> Proxy EvaluateExpression
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EvaluateExpression)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> EvaluateExpressionResponse
EvaluateExpressionResponse'
            (Int -> Text -> EvaluateExpressionResponse)
-> Either String Int
-> Either String (Text -> EvaluateExpressionResponse)
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 (Text -> EvaluateExpressionResponse)
-> Either String Text -> Either String EvaluateExpressionResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"evaluatedExpression")
      )

instance Prelude.Hashable EvaluateExpression

instance Prelude.NFData EvaluateExpression

instance Core.ToHeaders EvaluateExpression where
  toHeaders :: EvaluateExpression -> ResponseHeaders
toHeaders =
    ResponseHeaders -> EvaluateExpression -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"DataPipeline.EvaluateExpression" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON EvaluateExpression where
  toJSON :: EvaluateExpression -> Value
toJSON EvaluateExpression' {Text
expression :: Text
objectId :: Text
pipelineId :: Text
$sel:expression:EvaluateExpression' :: EvaluateExpression -> Text
$sel:objectId:EvaluateExpression' :: EvaluateExpression -> Text
$sel:pipelineId:EvaluateExpression' :: EvaluateExpression -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"pipelineId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
pipelineId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"objectId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
objectId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"expression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
expression)
          ]
      )

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

instance Core.ToQuery EvaluateExpression where
  toQuery :: EvaluateExpression -> QueryString
toQuery = QueryString -> EvaluateExpression -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

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

-- |
-- Create a value of 'EvaluateExpressionResponse' 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', 'evaluateExpressionResponse_httpStatus' - The response's http status code.
--
-- 'evaluatedExpression', 'evaluateExpressionResponse_evaluatedExpression' - The evaluated expression.
newEvaluateExpressionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'evaluatedExpression'
  Prelude.Text ->
  EvaluateExpressionResponse
newEvaluateExpressionResponse :: Int -> Text -> EvaluateExpressionResponse
newEvaluateExpressionResponse
  Int
pHttpStatus_
  Text
pEvaluatedExpression_ =
    EvaluateExpressionResponse' :: Int -> Text -> EvaluateExpressionResponse
EvaluateExpressionResponse'
      { $sel:httpStatus:EvaluateExpressionResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:evaluatedExpression:EvaluateExpressionResponse' :: Text
evaluatedExpression = Text
pEvaluatedExpression_
      }

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

-- | The evaluated expression.
evaluateExpressionResponse_evaluatedExpression :: Lens.Lens' EvaluateExpressionResponse Prelude.Text
evaluateExpressionResponse_evaluatedExpression :: (Text -> f Text)
-> EvaluateExpressionResponse -> f EvaluateExpressionResponse
evaluateExpressionResponse_evaluatedExpression = (EvaluateExpressionResponse -> Text)
-> (EvaluateExpressionResponse
    -> Text -> EvaluateExpressionResponse)
-> Lens
     EvaluateExpressionResponse EvaluateExpressionResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateExpressionResponse' {Text
evaluatedExpression :: Text
$sel:evaluatedExpression:EvaluateExpressionResponse' :: EvaluateExpressionResponse -> Text
evaluatedExpression} -> Text
evaluatedExpression) (\s :: EvaluateExpressionResponse
s@EvaluateExpressionResponse' {} Text
a -> EvaluateExpressionResponse
s {$sel:evaluatedExpression:EvaluateExpressionResponse' :: Text
evaluatedExpression = Text
a} :: EvaluateExpressionResponse)

instance Prelude.NFData EvaluateExpressionResponse