{-# 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.RedshiftData.BatchExecuteStatement
-- 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)
--
-- Runs one or more SQL statements, which can be data manipulation language
-- (DML) or data definition language (DDL). Depending on the authorization
-- method, use one of the following combinations of request parameters:
--
-- -   Secrets Manager - specify the Amazon Resource Name (ARN) of the
--     secret, the database name, and the cluster identifier that matches
--     the cluster in the secret.
--
-- -   Temporary credentials - specify the cluster identifier, the database
--     name, and the database user name. Permission to call the
--     @redshift:GetClusterCredentials@ operation is required to use this
--     method.
module Amazonka.RedshiftData.BatchExecuteStatement
  ( -- * Creating a Request
    BatchExecuteStatement (..),
    newBatchExecuteStatement,

    -- * Request Lenses
    batchExecuteStatement_dbUser,
    batchExecuteStatement_statementName,
    batchExecuteStatement_secretArn,
    batchExecuteStatement_withEvent,
    batchExecuteStatement_clusterIdentifier,
    batchExecuteStatement_database,
    batchExecuteStatement_sqls,

    -- * Destructuring the Response
    BatchExecuteStatementResponse (..),
    newBatchExecuteStatementResponse,

    -- * Response Lenses
    batchExecuteStatementResponse_dbUser,
    batchExecuteStatementResponse_database,
    batchExecuteStatementResponse_createdAt,
    batchExecuteStatementResponse_clusterIdentifier,
    batchExecuteStatementResponse_id,
    batchExecuteStatementResponse_secretArn,
    batchExecuteStatementResponse_httpStatus,
  )
where

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

-- | /See:/ 'newBatchExecuteStatement' smart constructor.
data BatchExecuteStatement = BatchExecuteStatement'
  { -- | The database user name. This parameter is required when authenticating
    -- using temporary credentials.
    BatchExecuteStatement -> Maybe Text
dbUser :: Prelude.Maybe Prelude.Text,
    -- | The name of the SQL statements. You can name the SQL statements when you
    -- create them to identify the query.
    BatchExecuteStatement -> Maybe Text
statementName :: Prelude.Maybe Prelude.Text,
    -- | The name or ARN of the secret that enables access to the database. This
    -- parameter is required when authenticating using Secrets Manager.
    BatchExecuteStatement -> Maybe Text
secretArn :: Prelude.Maybe Prelude.Text,
    -- | A value that indicates whether to send an event to the Amazon
    -- EventBridge event bus after the SQL statements run.
    BatchExecuteStatement -> Maybe Bool
withEvent :: Prelude.Maybe Prelude.Bool,
    -- | The cluster identifier. This parameter is required when authenticating
    -- using either Secrets Manager or temporary credentials.
    BatchExecuteStatement -> Text
clusterIdentifier :: Prelude.Text,
    -- | The name of the database. This parameter is required when authenticating
    -- using either Secrets Manager or temporary credentials.
    BatchExecuteStatement -> Text
database :: Prelude.Text,
    -- | One or more SQL statements to run.
    BatchExecuteStatement -> NonEmpty Text
sqls :: Prelude.NonEmpty Prelude.Text
  }
  deriving (BatchExecuteStatement -> BatchExecuteStatement -> Bool
(BatchExecuteStatement -> BatchExecuteStatement -> Bool)
-> (BatchExecuteStatement -> BatchExecuteStatement -> Bool)
-> Eq BatchExecuteStatement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchExecuteStatement -> BatchExecuteStatement -> Bool
$c/= :: BatchExecuteStatement -> BatchExecuteStatement -> Bool
== :: BatchExecuteStatement -> BatchExecuteStatement -> Bool
$c== :: BatchExecuteStatement -> BatchExecuteStatement -> Bool
Prelude.Eq, ReadPrec [BatchExecuteStatement]
ReadPrec BatchExecuteStatement
Int -> ReadS BatchExecuteStatement
ReadS [BatchExecuteStatement]
(Int -> ReadS BatchExecuteStatement)
-> ReadS [BatchExecuteStatement]
-> ReadPrec BatchExecuteStatement
-> ReadPrec [BatchExecuteStatement]
-> Read BatchExecuteStatement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchExecuteStatement]
$creadListPrec :: ReadPrec [BatchExecuteStatement]
readPrec :: ReadPrec BatchExecuteStatement
$creadPrec :: ReadPrec BatchExecuteStatement
readList :: ReadS [BatchExecuteStatement]
$creadList :: ReadS [BatchExecuteStatement]
readsPrec :: Int -> ReadS BatchExecuteStatement
$creadsPrec :: Int -> ReadS BatchExecuteStatement
Prelude.Read, Int -> BatchExecuteStatement -> ShowS
[BatchExecuteStatement] -> ShowS
BatchExecuteStatement -> String
(Int -> BatchExecuteStatement -> ShowS)
-> (BatchExecuteStatement -> String)
-> ([BatchExecuteStatement] -> ShowS)
-> Show BatchExecuteStatement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchExecuteStatement] -> ShowS
$cshowList :: [BatchExecuteStatement] -> ShowS
show :: BatchExecuteStatement -> String
$cshow :: BatchExecuteStatement -> String
showsPrec :: Int -> BatchExecuteStatement -> ShowS
$cshowsPrec :: Int -> BatchExecuteStatement -> ShowS
Prelude.Show, (forall x. BatchExecuteStatement -> Rep BatchExecuteStatement x)
-> (forall x. Rep BatchExecuteStatement x -> BatchExecuteStatement)
-> Generic BatchExecuteStatement
forall x. Rep BatchExecuteStatement x -> BatchExecuteStatement
forall x. BatchExecuteStatement -> Rep BatchExecuteStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchExecuteStatement x -> BatchExecuteStatement
$cfrom :: forall x. BatchExecuteStatement -> Rep BatchExecuteStatement x
Prelude.Generic)

-- |
-- Create a value of 'BatchExecuteStatement' 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:
--
-- 'dbUser', 'batchExecuteStatement_dbUser' - The database user name. This parameter is required when authenticating
-- using temporary credentials.
--
-- 'statementName', 'batchExecuteStatement_statementName' - The name of the SQL statements. You can name the SQL statements when you
-- create them to identify the query.
--
-- 'secretArn', 'batchExecuteStatement_secretArn' - The name or ARN of the secret that enables access to the database. This
-- parameter is required when authenticating using Secrets Manager.
--
-- 'withEvent', 'batchExecuteStatement_withEvent' - A value that indicates whether to send an event to the Amazon
-- EventBridge event bus after the SQL statements run.
--
-- 'clusterIdentifier', 'batchExecuteStatement_clusterIdentifier' - The cluster identifier. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
--
-- 'database', 'batchExecuteStatement_database' - The name of the database. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
--
-- 'sqls', 'batchExecuteStatement_sqls' - One or more SQL statements to run.
newBatchExecuteStatement ::
  -- | 'clusterIdentifier'
  Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  -- | 'sqls'
  Prelude.NonEmpty Prelude.Text ->
  BatchExecuteStatement
newBatchExecuteStatement :: Text -> Text -> NonEmpty Text -> BatchExecuteStatement
newBatchExecuteStatement
  Text
pClusterIdentifier_
  Text
pDatabase_
  NonEmpty Text
pSqls_ =
    BatchExecuteStatement' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Bool
-> Text
-> Text
-> NonEmpty Text
-> BatchExecuteStatement
BatchExecuteStatement'
      { $sel:dbUser:BatchExecuteStatement' :: Maybe Text
dbUser = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:statementName:BatchExecuteStatement' :: Maybe Text
statementName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:secretArn:BatchExecuteStatement' :: Maybe Text
secretArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:withEvent:BatchExecuteStatement' :: Maybe Bool
withEvent = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
        $sel:clusterIdentifier:BatchExecuteStatement' :: Text
clusterIdentifier = Text
pClusterIdentifier_,
        $sel:database:BatchExecuteStatement' :: Text
database = Text
pDatabase_,
        $sel:sqls:BatchExecuteStatement' :: NonEmpty Text
sqls = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pSqls_
      }

-- | The database user name. This parameter is required when authenticating
-- using temporary credentials.
batchExecuteStatement_dbUser :: Lens.Lens' BatchExecuteStatement (Prelude.Maybe Prelude.Text)
batchExecuteStatement_dbUser :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatement -> f BatchExecuteStatement
batchExecuteStatement_dbUser = (BatchExecuteStatement -> Maybe Text)
-> (BatchExecuteStatement -> Maybe Text -> BatchExecuteStatement)
-> Lens
     BatchExecuteStatement
     BatchExecuteStatement
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatement' {Maybe Text
dbUser :: Maybe Text
$sel:dbUser:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Text
dbUser} -> Maybe Text
dbUser) (\s :: BatchExecuteStatement
s@BatchExecuteStatement' {} Maybe Text
a -> BatchExecuteStatement
s {$sel:dbUser:BatchExecuteStatement' :: Maybe Text
dbUser = Maybe Text
a} :: BatchExecuteStatement)

-- | The name of the SQL statements. You can name the SQL statements when you
-- create them to identify the query.
batchExecuteStatement_statementName :: Lens.Lens' BatchExecuteStatement (Prelude.Maybe Prelude.Text)
batchExecuteStatement_statementName :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatement -> f BatchExecuteStatement
batchExecuteStatement_statementName = (BatchExecuteStatement -> Maybe Text)
-> (BatchExecuteStatement -> Maybe Text -> BatchExecuteStatement)
-> Lens
     BatchExecuteStatement
     BatchExecuteStatement
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatement' {Maybe Text
statementName :: Maybe Text
$sel:statementName:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Text
statementName} -> Maybe Text
statementName) (\s :: BatchExecuteStatement
s@BatchExecuteStatement' {} Maybe Text
a -> BatchExecuteStatement
s {$sel:statementName:BatchExecuteStatement' :: Maybe Text
statementName = Maybe Text
a} :: BatchExecuteStatement)

-- | The name or ARN of the secret that enables access to the database. This
-- parameter is required when authenticating using Secrets Manager.
batchExecuteStatement_secretArn :: Lens.Lens' BatchExecuteStatement (Prelude.Maybe Prelude.Text)
batchExecuteStatement_secretArn :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatement -> f BatchExecuteStatement
batchExecuteStatement_secretArn = (BatchExecuteStatement -> Maybe Text)
-> (BatchExecuteStatement -> Maybe Text -> BatchExecuteStatement)
-> Lens
     BatchExecuteStatement
     BatchExecuteStatement
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatement' {Maybe Text
secretArn :: Maybe Text
$sel:secretArn:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Text
secretArn} -> Maybe Text
secretArn) (\s :: BatchExecuteStatement
s@BatchExecuteStatement' {} Maybe Text
a -> BatchExecuteStatement
s {$sel:secretArn:BatchExecuteStatement' :: Maybe Text
secretArn = Maybe Text
a} :: BatchExecuteStatement)

-- | A value that indicates whether to send an event to the Amazon
-- EventBridge event bus after the SQL statements run.
batchExecuteStatement_withEvent :: Lens.Lens' BatchExecuteStatement (Prelude.Maybe Prelude.Bool)
batchExecuteStatement_withEvent :: (Maybe Bool -> f (Maybe Bool))
-> BatchExecuteStatement -> f BatchExecuteStatement
batchExecuteStatement_withEvent = (BatchExecuteStatement -> Maybe Bool)
-> (BatchExecuteStatement -> Maybe Bool -> BatchExecuteStatement)
-> Lens
     BatchExecuteStatement
     BatchExecuteStatement
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatement' {Maybe Bool
withEvent :: Maybe Bool
$sel:withEvent:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Bool
withEvent} -> Maybe Bool
withEvent) (\s :: BatchExecuteStatement
s@BatchExecuteStatement' {} Maybe Bool
a -> BatchExecuteStatement
s {$sel:withEvent:BatchExecuteStatement' :: Maybe Bool
withEvent = Maybe Bool
a} :: BatchExecuteStatement)

-- | The cluster identifier. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
batchExecuteStatement_clusterIdentifier :: Lens.Lens' BatchExecuteStatement Prelude.Text
batchExecuteStatement_clusterIdentifier :: (Text -> f Text)
-> BatchExecuteStatement -> f BatchExecuteStatement
batchExecuteStatement_clusterIdentifier = (BatchExecuteStatement -> Text)
-> (BatchExecuteStatement -> Text -> BatchExecuteStatement)
-> Lens BatchExecuteStatement BatchExecuteStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatement' {Text
clusterIdentifier :: Text
$sel:clusterIdentifier:BatchExecuteStatement' :: BatchExecuteStatement -> Text
clusterIdentifier} -> Text
clusterIdentifier) (\s :: BatchExecuteStatement
s@BatchExecuteStatement' {} Text
a -> BatchExecuteStatement
s {$sel:clusterIdentifier:BatchExecuteStatement' :: Text
clusterIdentifier = Text
a} :: BatchExecuteStatement)

-- | The name of the database. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
batchExecuteStatement_database :: Lens.Lens' BatchExecuteStatement Prelude.Text
batchExecuteStatement_database :: (Text -> f Text)
-> BatchExecuteStatement -> f BatchExecuteStatement
batchExecuteStatement_database = (BatchExecuteStatement -> Text)
-> (BatchExecuteStatement -> Text -> BatchExecuteStatement)
-> Lens BatchExecuteStatement BatchExecuteStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatement' {Text
database :: Text
$sel:database:BatchExecuteStatement' :: BatchExecuteStatement -> Text
database} -> Text
database) (\s :: BatchExecuteStatement
s@BatchExecuteStatement' {} Text
a -> BatchExecuteStatement
s {$sel:database:BatchExecuteStatement' :: Text
database = Text
a} :: BatchExecuteStatement)

-- | One or more SQL statements to run.
batchExecuteStatement_sqls :: Lens.Lens' BatchExecuteStatement (Prelude.NonEmpty Prelude.Text)
batchExecuteStatement_sqls :: (NonEmpty Text -> f (NonEmpty Text))
-> BatchExecuteStatement -> f BatchExecuteStatement
batchExecuteStatement_sqls = (BatchExecuteStatement -> NonEmpty Text)
-> (BatchExecuteStatement
    -> NonEmpty Text -> BatchExecuteStatement)
-> Lens
     BatchExecuteStatement
     BatchExecuteStatement
     (NonEmpty Text)
     (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatement' {NonEmpty Text
sqls :: NonEmpty Text
$sel:sqls:BatchExecuteStatement' :: BatchExecuteStatement -> NonEmpty Text
sqls} -> NonEmpty Text
sqls) (\s :: BatchExecuteStatement
s@BatchExecuteStatement' {} NonEmpty Text
a -> BatchExecuteStatement
s {$sel:sqls:BatchExecuteStatement' :: NonEmpty Text
sqls = NonEmpty Text
a} :: BatchExecuteStatement) ((NonEmpty Text -> f (NonEmpty Text))
 -> BatchExecuteStatement -> f BatchExecuteStatement)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> BatchExecuteStatement
-> f BatchExecuteStatement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest BatchExecuteStatement where
  type
    AWSResponse BatchExecuteStatement =
      BatchExecuteStatementResponse
  request :: BatchExecuteStatement -> Request BatchExecuteStatement
request = Service -> BatchExecuteStatement -> Request BatchExecuteStatement
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy BatchExecuteStatement
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchExecuteStatement)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse BatchExecuteStatement))
-> Logger
-> Service
-> Proxy BatchExecuteStatement
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchExecuteStatement)))
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 ->
          Maybe Text
-> Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Int
-> BatchExecuteStatementResponse
BatchExecuteStatementResponse'
            (Maybe Text
 -> Maybe Text
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Int
 -> BatchExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Int
      -> BatchExecuteStatementResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"DbUser")
            Either
  String
  (Maybe Text
   -> Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Int
   -> BatchExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Int
      -> BatchExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Database")
            Either
  String
  (Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Int
   -> BatchExecuteStatementResponse)
-> Either String (Maybe POSIX)
-> Either
     String
     (Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Int
      -> BatchExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"CreatedAt")
            Either
  String
  (Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Int
   -> BatchExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text -> Maybe Text -> Int -> BatchExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ClusterIdentifier")
            Either
  String
  (Maybe Text -> Maybe Text -> Int -> BatchExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Int -> BatchExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Id")
            Either String (Maybe Text -> Int -> BatchExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either String (Int -> BatchExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"SecretArn")
            Either String (Int -> BatchExecuteStatementResponse)
-> Either String Int -> Either String BatchExecuteStatementResponse
forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable BatchExecuteStatement

instance Prelude.NFData BatchExecuteStatement

instance Core.ToHeaders BatchExecuteStatement where
  toHeaders :: BatchExecuteStatement -> ResponseHeaders
toHeaders =
    ResponseHeaders -> BatchExecuteStatement -> 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
"RedshiftData.BatchExecuteStatement" ::
                          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 BatchExecuteStatement where
  toJSON :: BatchExecuteStatement -> Value
toJSON BatchExecuteStatement' {Maybe Bool
Maybe Text
NonEmpty Text
Text
sqls :: NonEmpty Text
database :: Text
clusterIdentifier :: Text
withEvent :: Maybe Bool
secretArn :: Maybe Text
statementName :: Maybe Text
dbUser :: Maybe Text
$sel:sqls:BatchExecuteStatement' :: BatchExecuteStatement -> NonEmpty Text
$sel:database:BatchExecuteStatement' :: BatchExecuteStatement -> Text
$sel:clusterIdentifier:BatchExecuteStatement' :: BatchExecuteStatement -> Text
$sel:withEvent:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Bool
$sel:secretArn:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Text
$sel:statementName:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Text
$sel:dbUser:BatchExecuteStatement' :: BatchExecuteStatement -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DbUser" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
dbUser,
            (Text
"StatementName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
statementName,
            (Text
"SecretArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
secretArn,
            (Text
"WithEvent" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
withEvent,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ClusterIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clusterIdentifier),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Database" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
database),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Sqls" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
sqls)
          ]
      )

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

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

-- | /See:/ 'newBatchExecuteStatementResponse' smart constructor.
data BatchExecuteStatementResponse = BatchExecuteStatementResponse'
  { -- | The database user name.
    BatchExecuteStatementResponse -> Maybe Text
dbUser :: Prelude.Maybe Prelude.Text,
    -- | The name of the database.
    BatchExecuteStatementResponse -> Maybe Text
database :: Prelude.Maybe Prelude.Text,
    -- | The date and time (UTC) the statement was created.
    BatchExecuteStatementResponse -> Maybe POSIX
createdAt :: Prelude.Maybe Core.POSIX,
    -- | The cluster identifier.
    BatchExecuteStatementResponse -> Maybe Text
clusterIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The identifier of the SQL statement whose results are to be fetched.
    -- This value is a universally unique identifier (UUID) generated by Amazon
    -- Redshift Data API. This identifier is returned by
    -- @BatchExecuteStatment@.
    BatchExecuteStatementResponse -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The name or ARN of the secret that enables access to the database.
    BatchExecuteStatementResponse -> Maybe Text
secretArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    BatchExecuteStatementResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchExecuteStatementResponse
-> BatchExecuteStatementResponse -> Bool
(BatchExecuteStatementResponse
 -> BatchExecuteStatementResponse -> Bool)
-> (BatchExecuteStatementResponse
    -> BatchExecuteStatementResponse -> Bool)
-> Eq BatchExecuteStatementResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchExecuteStatementResponse
-> BatchExecuteStatementResponse -> Bool
$c/= :: BatchExecuteStatementResponse
-> BatchExecuteStatementResponse -> Bool
== :: BatchExecuteStatementResponse
-> BatchExecuteStatementResponse -> Bool
$c== :: BatchExecuteStatementResponse
-> BatchExecuteStatementResponse -> Bool
Prelude.Eq, ReadPrec [BatchExecuteStatementResponse]
ReadPrec BatchExecuteStatementResponse
Int -> ReadS BatchExecuteStatementResponse
ReadS [BatchExecuteStatementResponse]
(Int -> ReadS BatchExecuteStatementResponse)
-> ReadS [BatchExecuteStatementResponse]
-> ReadPrec BatchExecuteStatementResponse
-> ReadPrec [BatchExecuteStatementResponse]
-> Read BatchExecuteStatementResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchExecuteStatementResponse]
$creadListPrec :: ReadPrec [BatchExecuteStatementResponse]
readPrec :: ReadPrec BatchExecuteStatementResponse
$creadPrec :: ReadPrec BatchExecuteStatementResponse
readList :: ReadS [BatchExecuteStatementResponse]
$creadList :: ReadS [BatchExecuteStatementResponse]
readsPrec :: Int -> ReadS BatchExecuteStatementResponse
$creadsPrec :: Int -> ReadS BatchExecuteStatementResponse
Prelude.Read, Int -> BatchExecuteStatementResponse -> ShowS
[BatchExecuteStatementResponse] -> ShowS
BatchExecuteStatementResponse -> String
(Int -> BatchExecuteStatementResponse -> ShowS)
-> (BatchExecuteStatementResponse -> String)
-> ([BatchExecuteStatementResponse] -> ShowS)
-> Show BatchExecuteStatementResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchExecuteStatementResponse] -> ShowS
$cshowList :: [BatchExecuteStatementResponse] -> ShowS
show :: BatchExecuteStatementResponse -> String
$cshow :: BatchExecuteStatementResponse -> String
showsPrec :: Int -> BatchExecuteStatementResponse -> ShowS
$cshowsPrec :: Int -> BatchExecuteStatementResponse -> ShowS
Prelude.Show, (forall x.
 BatchExecuteStatementResponse
 -> Rep BatchExecuteStatementResponse x)
-> (forall x.
    Rep BatchExecuteStatementResponse x
    -> BatchExecuteStatementResponse)
-> Generic BatchExecuteStatementResponse
forall x.
Rep BatchExecuteStatementResponse x
-> BatchExecuteStatementResponse
forall x.
BatchExecuteStatementResponse
-> Rep BatchExecuteStatementResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchExecuteStatementResponse x
-> BatchExecuteStatementResponse
$cfrom :: forall x.
BatchExecuteStatementResponse
-> Rep BatchExecuteStatementResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchExecuteStatementResponse' 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:
--
-- 'dbUser', 'batchExecuteStatementResponse_dbUser' - The database user name.
--
-- 'database', 'batchExecuteStatementResponse_database' - The name of the database.
--
-- 'createdAt', 'batchExecuteStatementResponse_createdAt' - The date and time (UTC) the statement was created.
--
-- 'clusterIdentifier', 'batchExecuteStatementResponse_clusterIdentifier' - The cluster identifier.
--
-- 'id', 'batchExecuteStatementResponse_id' - The identifier of the SQL statement whose results are to be fetched.
-- This value is a universally unique identifier (UUID) generated by Amazon
-- Redshift Data API. This identifier is returned by
-- @BatchExecuteStatment@.
--
-- 'secretArn', 'batchExecuteStatementResponse_secretArn' - The name or ARN of the secret that enables access to the database.
--
-- 'httpStatus', 'batchExecuteStatementResponse_httpStatus' - The response's http status code.
newBatchExecuteStatementResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchExecuteStatementResponse
newBatchExecuteStatementResponse :: Int -> BatchExecuteStatementResponse
newBatchExecuteStatementResponse Int
pHttpStatus_ =
  BatchExecuteStatementResponse' :: Maybe Text
-> Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Int
-> BatchExecuteStatementResponse
BatchExecuteStatementResponse'
    { $sel:dbUser:BatchExecuteStatementResponse' :: Maybe Text
dbUser =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:database:BatchExecuteStatementResponse' :: Maybe Text
database = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:createdAt:BatchExecuteStatementResponse' :: Maybe POSIX
createdAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:clusterIdentifier:BatchExecuteStatementResponse' :: Maybe Text
clusterIdentifier = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:id:BatchExecuteStatementResponse' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:secretArn:BatchExecuteStatementResponse' :: Maybe Text
secretArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchExecuteStatementResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The database user name.
batchExecuteStatementResponse_dbUser :: Lens.Lens' BatchExecuteStatementResponse (Prelude.Maybe Prelude.Text)
batchExecuteStatementResponse_dbUser :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatementResponse -> f BatchExecuteStatementResponse
batchExecuteStatementResponse_dbUser = (BatchExecuteStatementResponse -> Maybe Text)
-> (BatchExecuteStatementResponse
    -> Maybe Text -> BatchExecuteStatementResponse)
-> Lens
     BatchExecuteStatementResponse
     BatchExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatementResponse' {Maybe Text
dbUser :: Maybe Text
$sel:dbUser:BatchExecuteStatementResponse' :: BatchExecuteStatementResponse -> Maybe Text
dbUser} -> Maybe Text
dbUser) (\s :: BatchExecuteStatementResponse
s@BatchExecuteStatementResponse' {} Maybe Text
a -> BatchExecuteStatementResponse
s {$sel:dbUser:BatchExecuteStatementResponse' :: Maybe Text
dbUser = Maybe Text
a} :: BatchExecuteStatementResponse)

-- | The name of the database.
batchExecuteStatementResponse_database :: Lens.Lens' BatchExecuteStatementResponse (Prelude.Maybe Prelude.Text)
batchExecuteStatementResponse_database :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatementResponse -> f BatchExecuteStatementResponse
batchExecuteStatementResponse_database = (BatchExecuteStatementResponse -> Maybe Text)
-> (BatchExecuteStatementResponse
    -> Maybe Text -> BatchExecuteStatementResponse)
-> Lens
     BatchExecuteStatementResponse
     BatchExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatementResponse' {Maybe Text
database :: Maybe Text
$sel:database:BatchExecuteStatementResponse' :: BatchExecuteStatementResponse -> Maybe Text
database} -> Maybe Text
database) (\s :: BatchExecuteStatementResponse
s@BatchExecuteStatementResponse' {} Maybe Text
a -> BatchExecuteStatementResponse
s {$sel:database:BatchExecuteStatementResponse' :: Maybe Text
database = Maybe Text
a} :: BatchExecuteStatementResponse)

-- | The date and time (UTC) the statement was created.
batchExecuteStatementResponse_createdAt :: Lens.Lens' BatchExecuteStatementResponse (Prelude.Maybe Prelude.UTCTime)
batchExecuteStatementResponse_createdAt :: (Maybe UTCTime -> f (Maybe UTCTime))
-> BatchExecuteStatementResponse -> f BatchExecuteStatementResponse
batchExecuteStatementResponse_createdAt = (BatchExecuteStatementResponse -> Maybe POSIX)
-> (BatchExecuteStatementResponse
    -> Maybe POSIX -> BatchExecuteStatementResponse)
-> Lens
     BatchExecuteStatementResponse
     BatchExecuteStatementResponse
     (Maybe POSIX)
     (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatementResponse' {Maybe POSIX
createdAt :: Maybe POSIX
$sel:createdAt:BatchExecuteStatementResponse' :: BatchExecuteStatementResponse -> Maybe POSIX
createdAt} -> Maybe POSIX
createdAt) (\s :: BatchExecuteStatementResponse
s@BatchExecuteStatementResponse' {} Maybe POSIX
a -> BatchExecuteStatementResponse
s {$sel:createdAt:BatchExecuteStatementResponse' :: Maybe POSIX
createdAt = Maybe POSIX
a} :: BatchExecuteStatementResponse) ((Maybe POSIX -> f (Maybe POSIX))
 -> BatchExecuteStatementResponse
 -> f BatchExecuteStatementResponse)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> BatchExecuteStatementResponse
-> f BatchExecuteStatementResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The cluster identifier.
batchExecuteStatementResponse_clusterIdentifier :: Lens.Lens' BatchExecuteStatementResponse (Prelude.Maybe Prelude.Text)
batchExecuteStatementResponse_clusterIdentifier :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatementResponse -> f BatchExecuteStatementResponse
batchExecuteStatementResponse_clusterIdentifier = (BatchExecuteStatementResponse -> Maybe Text)
-> (BatchExecuteStatementResponse
    -> Maybe Text -> BatchExecuteStatementResponse)
-> Lens
     BatchExecuteStatementResponse
     BatchExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatementResponse' {Maybe Text
clusterIdentifier :: Maybe Text
$sel:clusterIdentifier:BatchExecuteStatementResponse' :: BatchExecuteStatementResponse -> Maybe Text
clusterIdentifier} -> Maybe Text
clusterIdentifier) (\s :: BatchExecuteStatementResponse
s@BatchExecuteStatementResponse' {} Maybe Text
a -> BatchExecuteStatementResponse
s {$sel:clusterIdentifier:BatchExecuteStatementResponse' :: Maybe Text
clusterIdentifier = Maybe Text
a} :: BatchExecuteStatementResponse)

-- | The identifier of the SQL statement whose results are to be fetched.
-- This value is a universally unique identifier (UUID) generated by Amazon
-- Redshift Data API. This identifier is returned by
-- @BatchExecuteStatment@.
batchExecuteStatementResponse_id :: Lens.Lens' BatchExecuteStatementResponse (Prelude.Maybe Prelude.Text)
batchExecuteStatementResponse_id :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatementResponse -> f BatchExecuteStatementResponse
batchExecuteStatementResponse_id = (BatchExecuteStatementResponse -> Maybe Text)
-> (BatchExecuteStatementResponse
    -> Maybe Text -> BatchExecuteStatementResponse)
-> Lens
     BatchExecuteStatementResponse
     BatchExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatementResponse' {Maybe Text
id :: Maybe Text
$sel:id:BatchExecuteStatementResponse' :: BatchExecuteStatementResponse -> Maybe Text
id} -> Maybe Text
id) (\s :: BatchExecuteStatementResponse
s@BatchExecuteStatementResponse' {} Maybe Text
a -> BatchExecuteStatementResponse
s {$sel:id:BatchExecuteStatementResponse' :: Maybe Text
id = Maybe Text
a} :: BatchExecuteStatementResponse)

-- | The name or ARN of the secret that enables access to the database.
batchExecuteStatementResponse_secretArn :: Lens.Lens' BatchExecuteStatementResponse (Prelude.Maybe Prelude.Text)
batchExecuteStatementResponse_secretArn :: (Maybe Text -> f (Maybe Text))
-> BatchExecuteStatementResponse -> f BatchExecuteStatementResponse
batchExecuteStatementResponse_secretArn = (BatchExecuteStatementResponse -> Maybe Text)
-> (BatchExecuteStatementResponse
    -> Maybe Text -> BatchExecuteStatementResponse)
-> Lens
     BatchExecuteStatementResponse
     BatchExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchExecuteStatementResponse' {Maybe Text
secretArn :: Maybe Text
$sel:secretArn:BatchExecuteStatementResponse' :: BatchExecuteStatementResponse -> Maybe Text
secretArn} -> Maybe Text
secretArn) (\s :: BatchExecuteStatementResponse
s@BatchExecuteStatementResponse' {} Maybe Text
a -> BatchExecuteStatementResponse
s {$sel:secretArn:BatchExecuteStatementResponse' :: Maybe Text
secretArn = Maybe Text
a} :: BatchExecuteStatementResponse)

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

instance Prelude.NFData BatchExecuteStatementResponse