{-# 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.StorageGateway.CancelRetrieval
-- 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)
--
-- Cancels retrieval of a virtual tape from the virtual tape shelf (VTS) to
-- a gateway after the retrieval process is initiated. The virtual tape is
-- returned to the VTS. This operation is only supported in the tape
-- gateway type.
module Amazonka.StorageGateway.CancelRetrieval
  ( -- * Creating a Request
    CancelRetrieval (..),
    newCancelRetrieval,

    -- * Request Lenses
    cancelRetrieval_gatewayARN,
    cancelRetrieval_tapeARN,

    -- * Destructuring the Response
    CancelRetrievalResponse (..),
    newCancelRetrievalResponse,

    -- * Response Lenses
    cancelRetrievalResponse_tapeARN,
    cancelRetrievalResponse_httpStatus,
  )
where

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

-- | CancelRetrievalInput
--
-- /See:/ 'newCancelRetrieval' smart constructor.
data CancelRetrieval = CancelRetrieval'
  { CancelRetrieval -> Text
gatewayARN :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the virtual tape you want to cancel
    -- retrieval for.
    CancelRetrieval -> Text
tapeARN :: Prelude.Text
  }
  deriving (CancelRetrieval -> CancelRetrieval -> Bool
(CancelRetrieval -> CancelRetrieval -> Bool)
-> (CancelRetrieval -> CancelRetrieval -> Bool)
-> Eq CancelRetrieval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelRetrieval -> CancelRetrieval -> Bool
$c/= :: CancelRetrieval -> CancelRetrieval -> Bool
== :: CancelRetrieval -> CancelRetrieval -> Bool
$c== :: CancelRetrieval -> CancelRetrieval -> Bool
Prelude.Eq, ReadPrec [CancelRetrieval]
ReadPrec CancelRetrieval
Int -> ReadS CancelRetrieval
ReadS [CancelRetrieval]
(Int -> ReadS CancelRetrieval)
-> ReadS [CancelRetrieval]
-> ReadPrec CancelRetrieval
-> ReadPrec [CancelRetrieval]
-> Read CancelRetrieval
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelRetrieval]
$creadListPrec :: ReadPrec [CancelRetrieval]
readPrec :: ReadPrec CancelRetrieval
$creadPrec :: ReadPrec CancelRetrieval
readList :: ReadS [CancelRetrieval]
$creadList :: ReadS [CancelRetrieval]
readsPrec :: Int -> ReadS CancelRetrieval
$creadsPrec :: Int -> ReadS CancelRetrieval
Prelude.Read, Int -> CancelRetrieval -> ShowS
[CancelRetrieval] -> ShowS
CancelRetrieval -> String
(Int -> CancelRetrieval -> ShowS)
-> (CancelRetrieval -> String)
-> ([CancelRetrieval] -> ShowS)
-> Show CancelRetrieval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelRetrieval] -> ShowS
$cshowList :: [CancelRetrieval] -> ShowS
show :: CancelRetrieval -> String
$cshow :: CancelRetrieval -> String
showsPrec :: Int -> CancelRetrieval -> ShowS
$cshowsPrec :: Int -> CancelRetrieval -> ShowS
Prelude.Show, (forall x. CancelRetrieval -> Rep CancelRetrieval x)
-> (forall x. Rep CancelRetrieval x -> CancelRetrieval)
-> Generic CancelRetrieval
forall x. Rep CancelRetrieval x -> CancelRetrieval
forall x. CancelRetrieval -> Rep CancelRetrieval x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelRetrieval x -> CancelRetrieval
$cfrom :: forall x. CancelRetrieval -> Rep CancelRetrieval x
Prelude.Generic)

-- |
-- Create a value of 'CancelRetrieval' 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:
--
-- 'gatewayARN', 'cancelRetrieval_gatewayARN' - Undocumented member.
--
-- 'tapeARN', 'cancelRetrieval_tapeARN' - The Amazon Resource Name (ARN) of the virtual tape you want to cancel
-- retrieval for.
newCancelRetrieval ::
  -- | 'gatewayARN'
  Prelude.Text ->
  -- | 'tapeARN'
  Prelude.Text ->
  CancelRetrieval
newCancelRetrieval :: Text -> Text -> CancelRetrieval
newCancelRetrieval Text
pGatewayARN_ Text
pTapeARN_ =
  CancelRetrieval' :: Text -> Text -> CancelRetrieval
CancelRetrieval'
    { $sel:gatewayARN:CancelRetrieval' :: Text
gatewayARN = Text
pGatewayARN_,
      $sel:tapeARN:CancelRetrieval' :: Text
tapeARN = Text
pTapeARN_
    }

-- | Undocumented member.
cancelRetrieval_gatewayARN :: Lens.Lens' CancelRetrieval Prelude.Text
cancelRetrieval_gatewayARN :: (Text -> f Text) -> CancelRetrieval -> f CancelRetrieval
cancelRetrieval_gatewayARN = (CancelRetrieval -> Text)
-> (CancelRetrieval -> Text -> CancelRetrieval)
-> Lens CancelRetrieval CancelRetrieval Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelRetrieval' {Text
gatewayARN :: Text
$sel:gatewayARN:CancelRetrieval' :: CancelRetrieval -> Text
gatewayARN} -> Text
gatewayARN) (\s :: CancelRetrieval
s@CancelRetrieval' {} Text
a -> CancelRetrieval
s {$sel:gatewayARN:CancelRetrieval' :: Text
gatewayARN = Text
a} :: CancelRetrieval)

-- | The Amazon Resource Name (ARN) of the virtual tape you want to cancel
-- retrieval for.
cancelRetrieval_tapeARN :: Lens.Lens' CancelRetrieval Prelude.Text
cancelRetrieval_tapeARN :: (Text -> f Text) -> CancelRetrieval -> f CancelRetrieval
cancelRetrieval_tapeARN = (CancelRetrieval -> Text)
-> (CancelRetrieval -> Text -> CancelRetrieval)
-> Lens CancelRetrieval CancelRetrieval Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelRetrieval' {Text
tapeARN :: Text
$sel:tapeARN:CancelRetrieval' :: CancelRetrieval -> Text
tapeARN} -> Text
tapeARN) (\s :: CancelRetrieval
s@CancelRetrieval' {} Text
a -> CancelRetrieval
s {$sel:tapeARN:CancelRetrieval' :: Text
tapeARN = Text
a} :: CancelRetrieval)

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

instance Prelude.NFData CancelRetrieval

instance Core.ToHeaders CancelRetrieval where
  toHeaders :: CancelRetrieval -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CancelRetrieval -> 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
"StorageGateway_20130630.CancelRetrieval" ::
                          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 CancelRetrieval where
  toJSON :: CancelRetrieval -> Value
toJSON CancelRetrieval' {Text
tapeARN :: Text
gatewayARN :: Text
$sel:tapeARN:CancelRetrieval' :: CancelRetrieval -> Text
$sel:gatewayARN:CancelRetrieval' :: CancelRetrieval -> 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
"GatewayARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
gatewayARN),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TapeARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tapeARN)
          ]
      )

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

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

-- | CancelRetrievalOutput
--
-- /See:/ 'newCancelRetrievalResponse' smart constructor.
data CancelRetrievalResponse = CancelRetrievalResponse'
  { -- | The Amazon Resource Name (ARN) of the virtual tape for which retrieval
    -- was canceled.
    CancelRetrievalResponse -> Maybe Text
tapeARN :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CancelRetrievalResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelRetrievalResponse -> CancelRetrievalResponse -> Bool
(CancelRetrievalResponse -> CancelRetrievalResponse -> Bool)
-> (CancelRetrievalResponse -> CancelRetrievalResponse -> Bool)
-> Eq CancelRetrievalResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelRetrievalResponse -> CancelRetrievalResponse -> Bool
$c/= :: CancelRetrievalResponse -> CancelRetrievalResponse -> Bool
== :: CancelRetrievalResponse -> CancelRetrievalResponse -> Bool
$c== :: CancelRetrievalResponse -> CancelRetrievalResponse -> Bool
Prelude.Eq, ReadPrec [CancelRetrievalResponse]
ReadPrec CancelRetrievalResponse
Int -> ReadS CancelRetrievalResponse
ReadS [CancelRetrievalResponse]
(Int -> ReadS CancelRetrievalResponse)
-> ReadS [CancelRetrievalResponse]
-> ReadPrec CancelRetrievalResponse
-> ReadPrec [CancelRetrievalResponse]
-> Read CancelRetrievalResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelRetrievalResponse]
$creadListPrec :: ReadPrec [CancelRetrievalResponse]
readPrec :: ReadPrec CancelRetrievalResponse
$creadPrec :: ReadPrec CancelRetrievalResponse
readList :: ReadS [CancelRetrievalResponse]
$creadList :: ReadS [CancelRetrievalResponse]
readsPrec :: Int -> ReadS CancelRetrievalResponse
$creadsPrec :: Int -> ReadS CancelRetrievalResponse
Prelude.Read, Int -> CancelRetrievalResponse -> ShowS
[CancelRetrievalResponse] -> ShowS
CancelRetrievalResponse -> String
(Int -> CancelRetrievalResponse -> ShowS)
-> (CancelRetrievalResponse -> String)
-> ([CancelRetrievalResponse] -> ShowS)
-> Show CancelRetrievalResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelRetrievalResponse] -> ShowS
$cshowList :: [CancelRetrievalResponse] -> ShowS
show :: CancelRetrievalResponse -> String
$cshow :: CancelRetrievalResponse -> String
showsPrec :: Int -> CancelRetrievalResponse -> ShowS
$cshowsPrec :: Int -> CancelRetrievalResponse -> ShowS
Prelude.Show, (forall x.
 CancelRetrievalResponse -> Rep CancelRetrievalResponse x)
-> (forall x.
    Rep CancelRetrievalResponse x -> CancelRetrievalResponse)
-> Generic CancelRetrievalResponse
forall x. Rep CancelRetrievalResponse x -> CancelRetrievalResponse
forall x. CancelRetrievalResponse -> Rep CancelRetrievalResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelRetrievalResponse x -> CancelRetrievalResponse
$cfrom :: forall x. CancelRetrievalResponse -> Rep CancelRetrievalResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelRetrievalResponse' 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:
--
-- 'tapeARN', 'cancelRetrievalResponse_tapeARN' - The Amazon Resource Name (ARN) of the virtual tape for which retrieval
-- was canceled.
--
-- 'httpStatus', 'cancelRetrievalResponse_httpStatus' - The response's http status code.
newCancelRetrievalResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelRetrievalResponse
newCancelRetrievalResponse :: Int -> CancelRetrievalResponse
newCancelRetrievalResponse Int
pHttpStatus_ =
  CancelRetrievalResponse' :: Maybe Text -> Int -> CancelRetrievalResponse
CancelRetrievalResponse'
    { $sel:tapeARN:CancelRetrievalResponse' :: Maybe Text
tapeARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelRetrievalResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the virtual tape for which retrieval
-- was canceled.
cancelRetrievalResponse_tapeARN :: Lens.Lens' CancelRetrievalResponse (Prelude.Maybe Prelude.Text)
cancelRetrievalResponse_tapeARN :: (Maybe Text -> f (Maybe Text))
-> CancelRetrievalResponse -> f CancelRetrievalResponse
cancelRetrievalResponse_tapeARN = (CancelRetrievalResponse -> Maybe Text)
-> (CancelRetrievalResponse
    -> Maybe Text -> CancelRetrievalResponse)
-> Lens
     CancelRetrievalResponse
     CancelRetrievalResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelRetrievalResponse' {Maybe Text
tapeARN :: Maybe Text
$sel:tapeARN:CancelRetrievalResponse' :: CancelRetrievalResponse -> Maybe Text
tapeARN} -> Maybe Text
tapeARN) (\s :: CancelRetrievalResponse
s@CancelRetrievalResponse' {} Maybe Text
a -> CancelRetrievalResponse
s {$sel:tapeARN:CancelRetrievalResponse' :: Maybe Text
tapeARN = Maybe Text
a} :: CancelRetrievalResponse)

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

instance Prelude.NFData CancelRetrievalResponse