{-# 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.RDSData.CommitTransaction
-- 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)
--
-- Ends a SQL transaction started with the @BeginTransaction@ operation and
-- commits the changes.
module Amazonka.RDSData.CommitTransaction
  ( -- * Creating a Request
    CommitTransaction (..),
    newCommitTransaction,

    -- * Request Lenses
    commitTransaction_resourceArn,
    commitTransaction_secretArn,
    commitTransaction_transactionId,

    -- * Destructuring the Response
    CommitTransactionResponse (..),
    newCommitTransactionResponse,

    -- * Response Lenses
    commitTransactionResponse_transactionStatus,
    commitTransactionResponse_httpStatus,
  )
where

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

-- | The request parameters represent the input of a commit transaction
-- request.
--
-- /See:/ 'newCommitTransaction' smart constructor.
data CommitTransaction = CommitTransaction'
  { -- | The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
    CommitTransaction -> Text
resourceArn :: Prelude.Text,
    -- | The name or ARN of the secret that enables access to the DB cluster.
    CommitTransaction -> Text
secretArn :: Prelude.Text,
    -- | The identifier of the transaction to end and commit.
    CommitTransaction -> Text
transactionId :: Prelude.Text
  }
  deriving (CommitTransaction -> CommitTransaction -> Bool
(CommitTransaction -> CommitTransaction -> Bool)
-> (CommitTransaction -> CommitTransaction -> Bool)
-> Eq CommitTransaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommitTransaction -> CommitTransaction -> Bool
$c/= :: CommitTransaction -> CommitTransaction -> Bool
== :: CommitTransaction -> CommitTransaction -> Bool
$c== :: CommitTransaction -> CommitTransaction -> Bool
Prelude.Eq, ReadPrec [CommitTransaction]
ReadPrec CommitTransaction
Int -> ReadS CommitTransaction
ReadS [CommitTransaction]
(Int -> ReadS CommitTransaction)
-> ReadS [CommitTransaction]
-> ReadPrec CommitTransaction
-> ReadPrec [CommitTransaction]
-> Read CommitTransaction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CommitTransaction]
$creadListPrec :: ReadPrec [CommitTransaction]
readPrec :: ReadPrec CommitTransaction
$creadPrec :: ReadPrec CommitTransaction
readList :: ReadS [CommitTransaction]
$creadList :: ReadS [CommitTransaction]
readsPrec :: Int -> ReadS CommitTransaction
$creadsPrec :: Int -> ReadS CommitTransaction
Prelude.Read, Int -> CommitTransaction -> ShowS
[CommitTransaction] -> ShowS
CommitTransaction -> String
(Int -> CommitTransaction -> ShowS)
-> (CommitTransaction -> String)
-> ([CommitTransaction] -> ShowS)
-> Show CommitTransaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommitTransaction] -> ShowS
$cshowList :: [CommitTransaction] -> ShowS
show :: CommitTransaction -> String
$cshow :: CommitTransaction -> String
showsPrec :: Int -> CommitTransaction -> ShowS
$cshowsPrec :: Int -> CommitTransaction -> ShowS
Prelude.Show, (forall x. CommitTransaction -> Rep CommitTransaction x)
-> (forall x. Rep CommitTransaction x -> CommitTransaction)
-> Generic CommitTransaction
forall x. Rep CommitTransaction x -> CommitTransaction
forall x. CommitTransaction -> Rep CommitTransaction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CommitTransaction x -> CommitTransaction
$cfrom :: forall x. CommitTransaction -> Rep CommitTransaction x
Prelude.Generic)

-- |
-- Create a value of 'CommitTransaction' 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:
--
-- 'resourceArn', 'commitTransaction_resourceArn' - The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
--
-- 'secretArn', 'commitTransaction_secretArn' - The name or ARN of the secret that enables access to the DB cluster.
--
-- 'transactionId', 'commitTransaction_transactionId' - The identifier of the transaction to end and commit.
newCommitTransaction ::
  -- | 'resourceArn'
  Prelude.Text ->
  -- | 'secretArn'
  Prelude.Text ->
  -- | 'transactionId'
  Prelude.Text ->
  CommitTransaction
newCommitTransaction :: Text -> Text -> Text -> CommitTransaction
newCommitTransaction
  Text
pResourceArn_
  Text
pSecretArn_
  Text
pTransactionId_ =
    CommitTransaction' :: Text -> Text -> Text -> CommitTransaction
CommitTransaction'
      { $sel:resourceArn:CommitTransaction' :: Text
resourceArn = Text
pResourceArn_,
        $sel:secretArn:CommitTransaction' :: Text
secretArn = Text
pSecretArn_,
        $sel:transactionId:CommitTransaction' :: Text
transactionId = Text
pTransactionId_
      }

-- | The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
commitTransaction_resourceArn :: Lens.Lens' CommitTransaction Prelude.Text
commitTransaction_resourceArn :: (Text -> f Text) -> CommitTransaction -> f CommitTransaction
commitTransaction_resourceArn = (CommitTransaction -> Text)
-> (CommitTransaction -> Text -> CommitTransaction)
-> Lens CommitTransaction CommitTransaction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitTransaction' {Text
resourceArn :: Text
$sel:resourceArn:CommitTransaction' :: CommitTransaction -> Text
resourceArn} -> Text
resourceArn) (\s :: CommitTransaction
s@CommitTransaction' {} Text
a -> CommitTransaction
s {$sel:resourceArn:CommitTransaction' :: Text
resourceArn = Text
a} :: CommitTransaction)

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

-- | The identifier of the transaction to end and commit.
commitTransaction_transactionId :: Lens.Lens' CommitTransaction Prelude.Text
commitTransaction_transactionId :: (Text -> f Text) -> CommitTransaction -> f CommitTransaction
commitTransaction_transactionId = (CommitTransaction -> Text)
-> (CommitTransaction -> Text -> CommitTransaction)
-> Lens CommitTransaction CommitTransaction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitTransaction' {Text
transactionId :: Text
$sel:transactionId:CommitTransaction' :: CommitTransaction -> Text
transactionId} -> Text
transactionId) (\s :: CommitTransaction
s@CommitTransaction' {} Text
a -> CommitTransaction
s {$sel:transactionId:CommitTransaction' :: Text
transactionId = Text
a} :: CommitTransaction)

instance Core.AWSRequest CommitTransaction where
  type
    AWSResponse CommitTransaction =
      CommitTransactionResponse
  request :: CommitTransaction -> Request CommitTransaction
request = Service -> CommitTransaction -> Request CommitTransaction
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CommitTransaction
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CommitTransaction)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CommitTransaction))
-> Logger
-> Service
-> Proxy CommitTransaction
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CommitTransaction)))
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 -> Int -> CommitTransactionResponse
CommitTransactionResponse'
            (Maybe Text -> Int -> CommitTransactionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CommitTransactionResponse)
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
"transactionStatus")
            Either String (Int -> CommitTransactionResponse)
-> Either String Int -> Either String CommitTransactionResponse
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 CommitTransaction

instance Prelude.NFData CommitTransaction

instance Core.ToHeaders CommitTransaction where
  toHeaders :: CommitTransaction -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CommitTransaction -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 CommitTransaction where
  toJSON :: CommitTransaction -> Value
toJSON CommitTransaction' {Text
transactionId :: Text
secretArn :: Text
resourceArn :: Text
$sel:transactionId:CommitTransaction' :: CommitTransaction -> Text
$sel:secretArn:CommitTransaction' :: CommitTransaction -> Text
$sel:resourceArn:CommitTransaction' :: CommitTransaction -> 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
"resourceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resourceArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"secretArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
secretArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"transactionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
transactionId)
          ]
      )

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

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

-- | The response elements represent the output of a commit transaction
-- request.
--
-- /See:/ 'newCommitTransactionResponse' smart constructor.
data CommitTransactionResponse = CommitTransactionResponse'
  { -- | The status of the commit operation.
    CommitTransactionResponse -> Maybe Text
transactionStatus :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CommitTransactionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CommitTransactionResponse -> CommitTransactionResponse -> Bool
(CommitTransactionResponse -> CommitTransactionResponse -> Bool)
-> (CommitTransactionResponse -> CommitTransactionResponse -> Bool)
-> Eq CommitTransactionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommitTransactionResponse -> CommitTransactionResponse -> Bool
$c/= :: CommitTransactionResponse -> CommitTransactionResponse -> Bool
== :: CommitTransactionResponse -> CommitTransactionResponse -> Bool
$c== :: CommitTransactionResponse -> CommitTransactionResponse -> Bool
Prelude.Eq, ReadPrec [CommitTransactionResponse]
ReadPrec CommitTransactionResponse
Int -> ReadS CommitTransactionResponse
ReadS [CommitTransactionResponse]
(Int -> ReadS CommitTransactionResponse)
-> ReadS [CommitTransactionResponse]
-> ReadPrec CommitTransactionResponse
-> ReadPrec [CommitTransactionResponse]
-> Read CommitTransactionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CommitTransactionResponse]
$creadListPrec :: ReadPrec [CommitTransactionResponse]
readPrec :: ReadPrec CommitTransactionResponse
$creadPrec :: ReadPrec CommitTransactionResponse
readList :: ReadS [CommitTransactionResponse]
$creadList :: ReadS [CommitTransactionResponse]
readsPrec :: Int -> ReadS CommitTransactionResponse
$creadsPrec :: Int -> ReadS CommitTransactionResponse
Prelude.Read, Int -> CommitTransactionResponse -> ShowS
[CommitTransactionResponse] -> ShowS
CommitTransactionResponse -> String
(Int -> CommitTransactionResponse -> ShowS)
-> (CommitTransactionResponse -> String)
-> ([CommitTransactionResponse] -> ShowS)
-> Show CommitTransactionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommitTransactionResponse] -> ShowS
$cshowList :: [CommitTransactionResponse] -> ShowS
show :: CommitTransactionResponse -> String
$cshow :: CommitTransactionResponse -> String
showsPrec :: Int -> CommitTransactionResponse -> ShowS
$cshowsPrec :: Int -> CommitTransactionResponse -> ShowS
Prelude.Show, (forall x.
 CommitTransactionResponse -> Rep CommitTransactionResponse x)
-> (forall x.
    Rep CommitTransactionResponse x -> CommitTransactionResponse)
-> Generic CommitTransactionResponse
forall x.
Rep CommitTransactionResponse x -> CommitTransactionResponse
forall x.
CommitTransactionResponse -> Rep CommitTransactionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CommitTransactionResponse x -> CommitTransactionResponse
$cfrom :: forall x.
CommitTransactionResponse -> Rep CommitTransactionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CommitTransactionResponse' 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:
--
-- 'transactionStatus', 'commitTransactionResponse_transactionStatus' - The status of the commit operation.
--
-- 'httpStatus', 'commitTransactionResponse_httpStatus' - The response's http status code.
newCommitTransactionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CommitTransactionResponse
newCommitTransactionResponse :: Int -> CommitTransactionResponse
newCommitTransactionResponse Int
pHttpStatus_ =
  CommitTransactionResponse' :: Maybe Text -> Int -> CommitTransactionResponse
CommitTransactionResponse'
    { $sel:transactionStatus:CommitTransactionResponse' :: Maybe Text
transactionStatus =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CommitTransactionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The status of the commit operation.
commitTransactionResponse_transactionStatus :: Lens.Lens' CommitTransactionResponse (Prelude.Maybe Prelude.Text)
commitTransactionResponse_transactionStatus :: (Maybe Text -> f (Maybe Text))
-> CommitTransactionResponse -> f CommitTransactionResponse
commitTransactionResponse_transactionStatus = (CommitTransactionResponse -> Maybe Text)
-> (CommitTransactionResponse
    -> Maybe Text -> CommitTransactionResponse)
-> Lens
     CommitTransactionResponse
     CommitTransactionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitTransactionResponse' {Maybe Text
transactionStatus :: Maybe Text
$sel:transactionStatus:CommitTransactionResponse' :: CommitTransactionResponse -> Maybe Text
transactionStatus} -> Maybe Text
transactionStatus) (\s :: CommitTransactionResponse
s@CommitTransactionResponse' {} Maybe Text
a -> CommitTransactionResponse
s {$sel:transactionStatus:CommitTransactionResponse' :: Maybe Text
transactionStatus = Maybe Text
a} :: CommitTransactionResponse)

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

instance Prelude.NFData CommitTransactionResponse