{-# 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.QLDBSession.Types.CommitTransactionRequest
-- 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.QLDBSession.Types.CommitTransactionRequest where

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

-- | Contains the details of the transaction to commit.
--
-- /See:/ 'newCommitTransactionRequest' smart constructor.
data CommitTransactionRequest = CommitTransactionRequest'
  { -- | Specifies the transaction ID of the transaction to commit.
    CommitTransactionRequest -> Text
transactionId :: Prelude.Text,
    -- | Specifies the commit digest for the transaction to commit. For every
    -- active transaction, the commit digest must be passed. QLDB validates
    -- @CommitDigest@ and rejects the commit with an error if the digest
    -- computed on the client does not match the digest computed by QLDB.
    --
    -- The purpose of the @CommitDigest@ parameter is to ensure that QLDB
    -- commits a transaction if and only if the server has processed the exact
    -- set of statements sent by the client, in the same order that client sent
    -- them, and with no duplicates.
    CommitTransactionRequest -> Base64
commitDigest :: Core.Base64
  }
  deriving (CommitTransactionRequest -> CommitTransactionRequest -> Bool
(CommitTransactionRequest -> CommitTransactionRequest -> Bool)
-> (CommitTransactionRequest -> CommitTransactionRequest -> Bool)
-> Eq CommitTransactionRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommitTransactionRequest -> CommitTransactionRequest -> Bool
$c/= :: CommitTransactionRequest -> CommitTransactionRequest -> Bool
== :: CommitTransactionRequest -> CommitTransactionRequest -> Bool
$c== :: CommitTransactionRequest -> CommitTransactionRequest -> Bool
Prelude.Eq, ReadPrec [CommitTransactionRequest]
ReadPrec CommitTransactionRequest
Int -> ReadS CommitTransactionRequest
ReadS [CommitTransactionRequest]
(Int -> ReadS CommitTransactionRequest)
-> ReadS [CommitTransactionRequest]
-> ReadPrec CommitTransactionRequest
-> ReadPrec [CommitTransactionRequest]
-> Read CommitTransactionRequest
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CommitTransactionRequest]
$creadListPrec :: ReadPrec [CommitTransactionRequest]
readPrec :: ReadPrec CommitTransactionRequest
$creadPrec :: ReadPrec CommitTransactionRequest
readList :: ReadS [CommitTransactionRequest]
$creadList :: ReadS [CommitTransactionRequest]
readsPrec :: Int -> ReadS CommitTransactionRequest
$creadsPrec :: Int -> ReadS CommitTransactionRequest
Prelude.Read, Int -> CommitTransactionRequest -> ShowS
[CommitTransactionRequest] -> ShowS
CommitTransactionRequest -> String
(Int -> CommitTransactionRequest -> ShowS)
-> (CommitTransactionRequest -> String)
-> ([CommitTransactionRequest] -> ShowS)
-> Show CommitTransactionRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommitTransactionRequest] -> ShowS
$cshowList :: [CommitTransactionRequest] -> ShowS
show :: CommitTransactionRequest -> String
$cshow :: CommitTransactionRequest -> String
showsPrec :: Int -> CommitTransactionRequest -> ShowS
$cshowsPrec :: Int -> CommitTransactionRequest -> ShowS
Prelude.Show, (forall x.
 CommitTransactionRequest -> Rep CommitTransactionRequest x)
-> (forall x.
    Rep CommitTransactionRequest x -> CommitTransactionRequest)
-> Generic CommitTransactionRequest
forall x.
Rep CommitTransactionRequest x -> CommitTransactionRequest
forall x.
CommitTransactionRequest -> Rep CommitTransactionRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CommitTransactionRequest x -> CommitTransactionRequest
$cfrom :: forall x.
CommitTransactionRequest -> Rep CommitTransactionRequest x
Prelude.Generic)

-- |
-- Create a value of 'CommitTransactionRequest' 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:
--
-- 'transactionId', 'commitTransactionRequest_transactionId' - Specifies the transaction ID of the transaction to commit.
--
-- 'commitDigest', 'commitTransactionRequest_commitDigest' - Specifies the commit digest for the transaction to commit. For every
-- active transaction, the commit digest must be passed. QLDB validates
-- @CommitDigest@ and rejects the commit with an error if the digest
-- computed on the client does not match the digest computed by QLDB.
--
-- The purpose of the @CommitDigest@ parameter is to ensure that QLDB
-- commits a transaction if and only if the server has processed the exact
-- set of statements sent by the client, in the same order that client sent
-- them, and with no duplicates.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
newCommitTransactionRequest ::
  -- | 'transactionId'
  Prelude.Text ->
  -- | 'commitDigest'
  Prelude.ByteString ->
  CommitTransactionRequest
newCommitTransactionRequest :: Text -> ByteString -> CommitTransactionRequest
newCommitTransactionRequest
  Text
pTransactionId_
  ByteString
pCommitDigest_ =
    CommitTransactionRequest' :: Text -> Base64 -> CommitTransactionRequest
CommitTransactionRequest'
      { $sel:transactionId:CommitTransactionRequest' :: Text
transactionId =
          Text
pTransactionId_,
        $sel:commitDigest:CommitTransactionRequest' :: Base64
commitDigest = Tagged ByteString (Identity ByteString)
-> Tagged Base64 (Identity Base64)
Iso' Base64 ByteString
Core._Base64 (Tagged ByteString (Identity ByteString)
 -> Tagged Base64 (Identity Base64))
-> ByteString -> Base64
forall t b. AReview t b -> b -> t
Lens.# ByteString
pCommitDigest_
      }

-- | Specifies the transaction ID of the transaction to commit.
commitTransactionRequest_transactionId :: Lens.Lens' CommitTransactionRequest Prelude.Text
commitTransactionRequest_transactionId :: (Text -> f Text)
-> CommitTransactionRequest -> f CommitTransactionRequest
commitTransactionRequest_transactionId = (CommitTransactionRequest -> Text)
-> (CommitTransactionRequest -> Text -> CommitTransactionRequest)
-> Lens CommitTransactionRequest CommitTransactionRequest Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitTransactionRequest' {Text
transactionId :: Text
$sel:transactionId:CommitTransactionRequest' :: CommitTransactionRequest -> Text
transactionId} -> Text
transactionId) (\s :: CommitTransactionRequest
s@CommitTransactionRequest' {} Text
a -> CommitTransactionRequest
s {$sel:transactionId:CommitTransactionRequest' :: Text
transactionId = Text
a} :: CommitTransactionRequest)

-- | Specifies the commit digest for the transaction to commit. For every
-- active transaction, the commit digest must be passed. QLDB validates
-- @CommitDigest@ and rejects the commit with an error if the digest
-- computed on the client does not match the digest computed by QLDB.
--
-- The purpose of the @CommitDigest@ parameter is to ensure that QLDB
-- commits a transaction if and only if the server has processed the exact
-- set of statements sent by the client, in the same order that client sent
-- them, and with no duplicates.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
commitTransactionRequest_commitDigest :: Lens.Lens' CommitTransactionRequest Prelude.ByteString
commitTransactionRequest_commitDigest :: (ByteString -> f ByteString)
-> CommitTransactionRequest -> f CommitTransactionRequest
commitTransactionRequest_commitDigest = (CommitTransactionRequest -> Base64)
-> (CommitTransactionRequest -> Base64 -> CommitTransactionRequest)
-> Lens
     CommitTransactionRequest CommitTransactionRequest Base64 Base64
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitTransactionRequest' {Base64
commitDigest :: Base64
$sel:commitDigest:CommitTransactionRequest' :: CommitTransactionRequest -> Base64
commitDigest} -> Base64
commitDigest) (\s :: CommitTransactionRequest
s@CommitTransactionRequest' {} Base64
a -> CommitTransactionRequest
s {$sel:commitDigest:CommitTransactionRequest' :: Base64
commitDigest = Base64
a} :: CommitTransactionRequest) ((Base64 -> f Base64)
 -> CommitTransactionRequest -> f CommitTransactionRequest)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> CommitTransactionRequest
-> f CommitTransactionRequest
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

instance Prelude.Hashable CommitTransactionRequest

instance Prelude.NFData CommitTransactionRequest

instance Core.ToJSON CommitTransactionRequest where
  toJSON :: CommitTransactionRequest -> Value
toJSON CommitTransactionRequest' {Text
Base64
commitDigest :: Base64
transactionId :: Text
$sel:commitDigest:CommitTransactionRequest' :: CommitTransactionRequest -> Base64
$sel:transactionId:CommitTransactionRequest' :: CommitTransactionRequest -> 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
"TransactionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
transactionId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"CommitDigest" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Base64
commitDigest)
          ]
      )