{-# 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.QLDB.GetDigest
-- 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)
--
-- Returns the digest of a ledger at the latest committed block in the
-- journal. The response includes a 256-bit hash value and a block address.
module Amazonka.QLDB.GetDigest
  ( -- * Creating a Request
    GetDigest (..),
    newGetDigest,

    -- * Request Lenses
    getDigest_name,

    -- * Destructuring the Response
    GetDigestResponse (..),
    newGetDigestResponse,

    -- * Response Lenses
    getDigestResponse_httpStatus,
    getDigestResponse_digest,
    getDigestResponse_digestTipAddress,
  )
where

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

-- | /See:/ 'newGetDigest' smart constructor.
data GetDigest = GetDigest'
  { -- | The name of the ledger.
    GetDigest -> Text
name :: Prelude.Text
  }
  deriving (GetDigest -> GetDigest -> Bool
(GetDigest -> GetDigest -> Bool)
-> (GetDigest -> GetDigest -> Bool) -> Eq GetDigest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDigest -> GetDigest -> Bool
$c/= :: GetDigest -> GetDigest -> Bool
== :: GetDigest -> GetDigest -> Bool
$c== :: GetDigest -> GetDigest -> Bool
Prelude.Eq, ReadPrec [GetDigest]
ReadPrec GetDigest
Int -> ReadS GetDigest
ReadS [GetDigest]
(Int -> ReadS GetDigest)
-> ReadS [GetDigest]
-> ReadPrec GetDigest
-> ReadPrec [GetDigest]
-> Read GetDigest
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDigest]
$creadListPrec :: ReadPrec [GetDigest]
readPrec :: ReadPrec GetDigest
$creadPrec :: ReadPrec GetDigest
readList :: ReadS [GetDigest]
$creadList :: ReadS [GetDigest]
readsPrec :: Int -> ReadS GetDigest
$creadsPrec :: Int -> ReadS GetDigest
Prelude.Read, Int -> GetDigest -> ShowS
[GetDigest] -> ShowS
GetDigest -> String
(Int -> GetDigest -> ShowS)
-> (GetDigest -> String)
-> ([GetDigest] -> ShowS)
-> Show GetDigest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDigest] -> ShowS
$cshowList :: [GetDigest] -> ShowS
show :: GetDigest -> String
$cshow :: GetDigest -> String
showsPrec :: Int -> GetDigest -> ShowS
$cshowsPrec :: Int -> GetDigest -> ShowS
Prelude.Show, (forall x. GetDigest -> Rep GetDigest x)
-> (forall x. Rep GetDigest x -> GetDigest) -> Generic GetDigest
forall x. Rep GetDigest x -> GetDigest
forall x. GetDigest -> Rep GetDigest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDigest x -> GetDigest
$cfrom :: forall x. GetDigest -> Rep GetDigest x
Prelude.Generic)

-- |
-- Create a value of 'GetDigest' 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:
--
-- 'name', 'getDigest_name' - The name of the ledger.
newGetDigest ::
  -- | 'name'
  Prelude.Text ->
  GetDigest
newGetDigest :: Text -> GetDigest
newGetDigest Text
pName_ = GetDigest' :: Text -> GetDigest
GetDigest' {$sel:name:GetDigest' :: Text
name = Text
pName_}

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

instance Core.AWSRequest GetDigest where
  type AWSResponse GetDigest = GetDigestResponse
  request :: GetDigest -> Request GetDigest
request = Service -> GetDigest -> Request GetDigest
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetDigest
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDigest)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetDigest))
-> Logger
-> Service
-> Proxy GetDigest
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDigest)))
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 -> Base64 -> Sensitive ValueHolder -> GetDigestResponse
GetDigestResponse'
            (Int -> Base64 -> Sensitive ValueHolder -> GetDigestResponse)
-> Either String Int
-> Either
     String (Base64 -> Sensitive ValueHolder -> GetDigestResponse)
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 (Base64 -> Sensitive ValueHolder -> GetDigestResponse)
-> Either String Base64
-> Either String (Sensitive ValueHolder -> GetDigestResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Base64
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"Digest")
            Either String (Sensitive ValueHolder -> GetDigestResponse)
-> Either String (Sensitive ValueHolder)
-> Either String GetDigestResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Sensitive ValueHolder)
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"DigestTipAddress")
      )

instance Prelude.Hashable GetDigest

instance Prelude.NFData GetDigest

instance Core.ToHeaders GetDigest where
  toHeaders :: GetDigest -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetDigest -> 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.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON GetDigest where
  toJSON :: GetDigest -> Value
toJSON = Value -> GetDigest -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath GetDigest where
  toPath :: GetDigest -> ByteString
toPath GetDigest' {Text
name :: Text
$sel:name:GetDigest' :: GetDigest -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/ledgers/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
name, ByteString
"/digest"]

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

-- | /See:/ 'newGetDigestResponse' smart constructor.
data GetDigestResponse = GetDigestResponse'
  { -- | The response's http status code.
    GetDigestResponse -> Int
httpStatus :: Prelude.Int,
    -- | The 256-bit hash value representing the digest returned by a @GetDigest@
    -- request.
    GetDigestResponse -> Base64
digest :: Core.Base64,
    -- | The latest block location covered by the digest that you requested. An
    -- address is an Amazon Ion structure that has two fields: @strandId@ and
    -- @sequenceNo@.
    GetDigestResponse -> Sensitive ValueHolder
digestTipAddress :: Core.Sensitive ValueHolder
  }
  deriving (GetDigestResponse -> GetDigestResponse -> Bool
(GetDigestResponse -> GetDigestResponse -> Bool)
-> (GetDigestResponse -> GetDigestResponse -> Bool)
-> Eq GetDigestResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDigestResponse -> GetDigestResponse -> Bool
$c/= :: GetDigestResponse -> GetDigestResponse -> Bool
== :: GetDigestResponse -> GetDigestResponse -> Bool
$c== :: GetDigestResponse -> GetDigestResponse -> Bool
Prelude.Eq, Int -> GetDigestResponse -> ShowS
[GetDigestResponse] -> ShowS
GetDigestResponse -> String
(Int -> GetDigestResponse -> ShowS)
-> (GetDigestResponse -> String)
-> ([GetDigestResponse] -> ShowS)
-> Show GetDigestResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDigestResponse] -> ShowS
$cshowList :: [GetDigestResponse] -> ShowS
show :: GetDigestResponse -> String
$cshow :: GetDigestResponse -> String
showsPrec :: Int -> GetDigestResponse -> ShowS
$cshowsPrec :: Int -> GetDigestResponse -> ShowS
Prelude.Show, (forall x. GetDigestResponse -> Rep GetDigestResponse x)
-> (forall x. Rep GetDigestResponse x -> GetDigestResponse)
-> Generic GetDigestResponse
forall x. Rep GetDigestResponse x -> GetDigestResponse
forall x. GetDigestResponse -> Rep GetDigestResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDigestResponse x -> GetDigestResponse
$cfrom :: forall x. GetDigestResponse -> Rep GetDigestResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetDigestResponse' 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', 'getDigestResponse_httpStatus' - The response's http status code.
--
-- 'digest', 'getDigestResponse_digest' - The 256-bit hash value representing the digest returned by a @GetDigest@
-- request.--
-- -- /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.
--
-- 'digestTipAddress', 'getDigestResponse_digestTipAddress' - The latest block location covered by the digest that you requested. An
-- address is an Amazon Ion structure that has two fields: @strandId@ and
-- @sequenceNo@.
newGetDigestResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'digest'
  Prelude.ByteString ->
  -- | 'digestTipAddress'
  ValueHolder ->
  GetDigestResponse
newGetDigestResponse :: Int -> ByteString -> ValueHolder -> GetDigestResponse
newGetDigestResponse
  Int
pHttpStatus_
  ByteString
pDigest_
  ValueHolder
pDigestTipAddress_ =
    GetDigestResponse' :: Int -> Base64 -> Sensitive ValueHolder -> GetDigestResponse
GetDigestResponse'
      { $sel:httpStatus:GetDigestResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:digest:GetDigestResponse' :: Base64
digest = 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
pDigest_,
        $sel:digestTipAddress:GetDigestResponse' :: Sensitive ValueHolder
digestTipAddress =
          Tagged ValueHolder (Identity ValueHolder)
-> Tagged
     (Sensitive ValueHolder) (Identity (Sensitive ValueHolder))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged ValueHolder (Identity ValueHolder)
 -> Tagged
      (Sensitive ValueHolder) (Identity (Sensitive ValueHolder)))
-> ValueHolder -> Sensitive ValueHolder
forall t b. AReview t b -> b -> t
Lens.# ValueHolder
pDigestTipAddress_
      }

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

-- | The 256-bit hash value representing the digest returned by a @GetDigest@
-- request.--
-- -- /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.
getDigestResponse_digest :: Lens.Lens' GetDigestResponse Prelude.ByteString
getDigestResponse_digest :: (ByteString -> f ByteString)
-> GetDigestResponse -> f GetDigestResponse
getDigestResponse_digest = (GetDigestResponse -> Base64)
-> (GetDigestResponse -> Base64 -> GetDigestResponse)
-> Lens GetDigestResponse GetDigestResponse Base64 Base64
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDigestResponse' {Base64
digest :: Base64
$sel:digest:GetDigestResponse' :: GetDigestResponse -> Base64
digest} -> Base64
digest) (\s :: GetDigestResponse
s@GetDigestResponse' {} Base64
a -> GetDigestResponse
s {$sel:digest:GetDigestResponse' :: Base64
digest = Base64
a} :: GetDigestResponse) ((Base64 -> f Base64) -> GetDigestResponse -> f GetDigestResponse)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> GetDigestResponse
-> f GetDigestResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

-- | The latest block location covered by the digest that you requested. An
-- address is an Amazon Ion structure that has two fields: @strandId@ and
-- @sequenceNo@.
getDigestResponse_digestTipAddress :: Lens.Lens' GetDigestResponse ValueHolder
getDigestResponse_digestTipAddress :: (ValueHolder -> f ValueHolder)
-> GetDigestResponse -> f GetDigestResponse
getDigestResponse_digestTipAddress = (GetDigestResponse -> Sensitive ValueHolder)
-> (GetDigestResponse
    -> Sensitive ValueHolder -> GetDigestResponse)
-> Lens
     GetDigestResponse
     GetDigestResponse
     (Sensitive ValueHolder)
     (Sensitive ValueHolder)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDigestResponse' {Sensitive ValueHolder
digestTipAddress :: Sensitive ValueHolder
$sel:digestTipAddress:GetDigestResponse' :: GetDigestResponse -> Sensitive ValueHolder
digestTipAddress} -> Sensitive ValueHolder
digestTipAddress) (\s :: GetDigestResponse
s@GetDigestResponse' {} Sensitive ValueHolder
a -> GetDigestResponse
s {$sel:digestTipAddress:GetDigestResponse' :: Sensitive ValueHolder
digestTipAddress = Sensitive ValueHolder
a} :: GetDigestResponse) ((Sensitive ValueHolder -> f (Sensitive ValueHolder))
 -> GetDigestResponse -> f GetDigestResponse)
-> ((ValueHolder -> f ValueHolder)
    -> Sensitive ValueHolder -> f (Sensitive ValueHolder))
-> (ValueHolder -> f ValueHolder)
-> GetDigestResponse
-> f GetDigestResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ValueHolder -> f ValueHolder)
-> Sensitive ValueHolder -> f (Sensitive ValueHolder)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Prelude.NFData GetDigestResponse