{-# 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.BackupStorage.GetChunk
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets the specified object\'s chunk.
module Amazonka.BackupStorage.GetChunk
  ( -- * Creating a Request
    GetChunk (..),
    newGetChunk,

    -- * Request Lenses
    getChunk_storageJobId,
    getChunk_chunkToken,

    -- * Destructuring the Response
    GetChunkResponse (..),
    newGetChunkResponse,

    -- * Response Lenses
    getChunkResponse_httpStatus,
    getChunkResponse_length,
    getChunkResponse_checksum,
    getChunkResponse_checksumAlgorithm,
    getChunkResponse_data,
  )
where

import Amazonka.BackupStorage.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetChunk' smart constructor.
data GetChunk = GetChunk'
  { -- | Storage job id
    GetChunk -> Text
storageJobId :: Prelude.Text,
    -- | Chunk token
    GetChunk -> Text
chunkToken :: Prelude.Text
  }
  deriving (GetChunk -> GetChunk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetChunk -> GetChunk -> Bool
$c/= :: GetChunk -> GetChunk -> Bool
== :: GetChunk -> GetChunk -> Bool
$c== :: GetChunk -> GetChunk -> Bool
Prelude.Eq, ReadPrec [GetChunk]
ReadPrec GetChunk
Int -> ReadS GetChunk
ReadS [GetChunk]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetChunk]
$creadListPrec :: ReadPrec [GetChunk]
readPrec :: ReadPrec GetChunk
$creadPrec :: ReadPrec GetChunk
readList :: ReadS [GetChunk]
$creadList :: ReadS [GetChunk]
readsPrec :: Int -> ReadS GetChunk
$creadsPrec :: Int -> ReadS GetChunk
Prelude.Read, Int -> GetChunk -> ShowS
[GetChunk] -> ShowS
GetChunk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetChunk] -> ShowS
$cshowList :: [GetChunk] -> ShowS
show :: GetChunk -> String
$cshow :: GetChunk -> String
showsPrec :: Int -> GetChunk -> ShowS
$cshowsPrec :: Int -> GetChunk -> ShowS
Prelude.Show, forall x. Rep GetChunk x -> GetChunk
forall x. GetChunk -> Rep GetChunk x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetChunk x -> GetChunk
$cfrom :: forall x. GetChunk -> Rep GetChunk x
Prelude.Generic)

-- |
-- Create a value of 'GetChunk' 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:
--
-- 'storageJobId', 'getChunk_storageJobId' - Storage job id
--
-- 'chunkToken', 'getChunk_chunkToken' - Chunk token
newGetChunk ::
  -- | 'storageJobId'
  Prelude.Text ->
  -- | 'chunkToken'
  Prelude.Text ->
  GetChunk
newGetChunk :: Text -> Text -> GetChunk
newGetChunk Text
pStorageJobId_ Text
pChunkToken_ =
  GetChunk'
    { $sel:storageJobId:GetChunk' :: Text
storageJobId = Text
pStorageJobId_,
      $sel:chunkToken:GetChunk' :: Text
chunkToken = Text
pChunkToken_
    }

-- | Storage job id
getChunk_storageJobId :: Lens.Lens' GetChunk Prelude.Text
getChunk_storageJobId :: Lens' GetChunk Text
getChunk_storageJobId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetChunk' {Text
storageJobId :: Text
$sel:storageJobId:GetChunk' :: GetChunk -> Text
storageJobId} -> Text
storageJobId) (\s :: GetChunk
s@GetChunk' {} Text
a -> GetChunk
s {$sel:storageJobId:GetChunk' :: Text
storageJobId = Text
a} :: GetChunk)

-- | Chunk token
getChunk_chunkToken :: Lens.Lens' GetChunk Prelude.Text
getChunk_chunkToken :: Lens' GetChunk Text
getChunk_chunkToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetChunk' {Text
chunkToken :: Text
$sel:chunkToken:GetChunk' :: GetChunk -> Text
chunkToken} -> Text
chunkToken) (\s :: GetChunk
s@GetChunk' {} Text
a -> GetChunk
s {$sel:chunkToken:GetChunk' :: Text
chunkToken = Text
a} :: GetChunk)

instance Core.AWSRequest GetChunk where
  type AWSResponse GetChunk = GetChunkResponse
  request :: (Service -> Service) -> GetChunk -> Request GetChunk
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetChunk
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetChunk)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int
 -> ResponseHeaders
 -> ResponseBody
 -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveBody
      ( \Int
s ResponseHeaders
h ResponseBody
x ->
          Int
-> Integer
-> Text
-> DataChecksumAlgorithm
-> ResponseBody
-> GetChunkResponse
GetChunkResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String a
Data..# HeaderName
"x-amz-data-length")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String a
Data..# HeaderName
"x-amz-checksum")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String a
Data..# HeaderName
"x-amz-checksum-algorithm")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure ResponseBody
x)
      )

instance Prelude.Hashable GetChunk where
  hashWithSalt :: Int -> GetChunk -> Int
hashWithSalt Int
_salt GetChunk' {Text
chunkToken :: Text
storageJobId :: Text
$sel:chunkToken:GetChunk' :: GetChunk -> Text
$sel:storageJobId:GetChunk' :: GetChunk -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
storageJobId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
chunkToken

instance Prelude.NFData GetChunk where
  rnf :: GetChunk -> ()
rnf GetChunk' {Text
chunkToken :: Text
storageJobId :: Text
$sel:chunkToken:GetChunk' :: GetChunk -> Text
$sel:storageJobId:GetChunk' :: GetChunk -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
storageJobId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
chunkToken

instance Data.ToHeaders GetChunk where
  toHeaders :: GetChunk -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToPath GetChunk where
  toPath :: GetChunk -> ByteString
toPath GetChunk' {Text
chunkToken :: Text
storageJobId :: Text
$sel:chunkToken:GetChunk' :: GetChunk -> Text
$sel:storageJobId:GetChunk' :: GetChunk -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/restore-jobs/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
storageJobId,
        ByteString
"/chunk/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
chunkToken
      ]

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

-- | /See:/ 'newGetChunkResponse' smart constructor.
data GetChunkResponse = GetChunkResponse'
  { -- | The response's http status code.
    GetChunkResponse -> Int
httpStatus :: Prelude.Int,
    -- | Data length
    GetChunkResponse -> Integer
length :: Prelude.Integer,
    -- | Data checksum
    GetChunkResponse -> Text
checksum :: Prelude.Text,
    -- | Checksum algorithm
    GetChunkResponse -> DataChecksumAlgorithm
checksumAlgorithm :: DataChecksumAlgorithm,
    -- | Chunk data
    GetChunkResponse -> ResponseBody
data' :: Data.ResponseBody
  }
  deriving (Int -> GetChunkResponse -> ShowS
[GetChunkResponse] -> ShowS
GetChunkResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetChunkResponse] -> ShowS
$cshowList :: [GetChunkResponse] -> ShowS
show :: GetChunkResponse -> String
$cshow :: GetChunkResponse -> String
showsPrec :: Int -> GetChunkResponse -> ShowS
$cshowsPrec :: Int -> GetChunkResponse -> ShowS
Prelude.Show, forall x. Rep GetChunkResponse x -> GetChunkResponse
forall x. GetChunkResponse -> Rep GetChunkResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetChunkResponse x -> GetChunkResponse
$cfrom :: forall x. GetChunkResponse -> Rep GetChunkResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetChunkResponse' 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', 'getChunkResponse_httpStatus' - The response's http status code.
--
-- 'length', 'getChunkResponse_length' - Data length
--
-- 'checksum', 'getChunkResponse_checksum' - Data checksum
--
-- 'checksumAlgorithm', 'getChunkResponse_checksumAlgorithm' - Checksum algorithm
--
-- 'data'', 'getChunkResponse_data' - Chunk data
newGetChunkResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'length'
  Prelude.Integer ->
  -- | 'checksum'
  Prelude.Text ->
  -- | 'checksumAlgorithm'
  DataChecksumAlgorithm ->
  -- | 'data''
  Data.ResponseBody ->
  GetChunkResponse
newGetChunkResponse :: Int
-> Integer
-> Text
-> DataChecksumAlgorithm
-> ResponseBody
-> GetChunkResponse
newGetChunkResponse
  Int
pHttpStatus_
  Integer
pLength_
  Text
pChecksum_
  DataChecksumAlgorithm
pChecksumAlgorithm_
  ResponseBody
pData_ =
    GetChunkResponse'
      { $sel:httpStatus:GetChunkResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:length:GetChunkResponse' :: Integer
length = Integer
pLength_,
        $sel:checksum:GetChunkResponse' :: Text
checksum = Text
pChecksum_,
        $sel:checksumAlgorithm:GetChunkResponse' :: DataChecksumAlgorithm
checksumAlgorithm = DataChecksumAlgorithm
pChecksumAlgorithm_,
        $sel:data':GetChunkResponse' :: ResponseBody
data' = ResponseBody
pData_
      }

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

-- | Data length
getChunkResponse_length :: Lens.Lens' GetChunkResponse Prelude.Integer
getChunkResponse_length :: Lens' GetChunkResponse Integer
getChunkResponse_length = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetChunkResponse' {Integer
length :: Integer
$sel:length:GetChunkResponse' :: GetChunkResponse -> Integer
length} -> Integer
length) (\s :: GetChunkResponse
s@GetChunkResponse' {} Integer
a -> GetChunkResponse
s {$sel:length:GetChunkResponse' :: Integer
length = Integer
a} :: GetChunkResponse)

-- | Data checksum
getChunkResponse_checksum :: Lens.Lens' GetChunkResponse Prelude.Text
getChunkResponse_checksum :: Lens' GetChunkResponse Text
getChunkResponse_checksum = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetChunkResponse' {Text
checksum :: Text
$sel:checksum:GetChunkResponse' :: GetChunkResponse -> Text
checksum} -> Text
checksum) (\s :: GetChunkResponse
s@GetChunkResponse' {} Text
a -> GetChunkResponse
s {$sel:checksum:GetChunkResponse' :: Text
checksum = Text
a} :: GetChunkResponse)

-- | Checksum algorithm
getChunkResponse_checksumAlgorithm :: Lens.Lens' GetChunkResponse DataChecksumAlgorithm
getChunkResponse_checksumAlgorithm :: Lens' GetChunkResponse DataChecksumAlgorithm
getChunkResponse_checksumAlgorithm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetChunkResponse' {DataChecksumAlgorithm
checksumAlgorithm :: DataChecksumAlgorithm
$sel:checksumAlgorithm:GetChunkResponse' :: GetChunkResponse -> DataChecksumAlgorithm
checksumAlgorithm} -> DataChecksumAlgorithm
checksumAlgorithm) (\s :: GetChunkResponse
s@GetChunkResponse' {} DataChecksumAlgorithm
a -> GetChunkResponse
s {$sel:checksumAlgorithm:GetChunkResponse' :: DataChecksumAlgorithm
checksumAlgorithm = DataChecksumAlgorithm
a} :: GetChunkResponse)

-- | Chunk data
getChunkResponse_data :: Lens.Lens' GetChunkResponse Data.ResponseBody
getChunkResponse_data :: Lens' GetChunkResponse ResponseBody
getChunkResponse_data = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetChunkResponse' {ResponseBody
data' :: ResponseBody
$sel:data':GetChunkResponse' :: GetChunkResponse -> ResponseBody
data'} -> ResponseBody
data') (\s :: GetChunkResponse
s@GetChunkResponse' {} ResponseBody
a -> GetChunkResponse
s {$sel:data':GetChunkResponse' :: ResponseBody
data' = ResponseBody
a} :: GetChunkResponse)