{-# 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.ImageBuilder.CancelImageCreation
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- CancelImageCreation cancels the creation of Image. This operation can
-- only be used on images in a non-terminal state.
module Amazonka.ImageBuilder.CancelImageCreation
  ( -- * Creating a Request
    CancelImageCreation (..),
    newCancelImageCreation,

    -- * Request Lenses
    cancelImageCreation_imageBuildVersionArn,
    cancelImageCreation_clientToken,

    -- * Destructuring the Response
    CancelImageCreationResponse (..),
    newCancelImageCreationResponse,

    -- * Response Lenses
    cancelImageCreationResponse_clientToken,
    cancelImageCreationResponse_imageBuildVersionArn,
    cancelImageCreationResponse_requestId,
    cancelImageCreationResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCancelImageCreation' smart constructor.
data CancelImageCreation = CancelImageCreation'
  { -- | The Amazon Resource Name (ARN) of the image whose creation you want to
    -- cancel.
    CancelImageCreation -> Text
imageBuildVersionArn :: Prelude.Text,
    -- | Unique, case-sensitive identifier you provide to ensure idempotency of
    -- the request. For more information, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html Ensuring idempotency>
    -- in the /Amazon EC2 API Reference/.
    CancelImageCreation -> Text
clientToken :: Prelude.Text
  }
  deriving (CancelImageCreation -> CancelImageCreation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelImageCreation -> CancelImageCreation -> Bool
$c/= :: CancelImageCreation -> CancelImageCreation -> Bool
== :: CancelImageCreation -> CancelImageCreation -> Bool
$c== :: CancelImageCreation -> CancelImageCreation -> Bool
Prelude.Eq, ReadPrec [CancelImageCreation]
ReadPrec CancelImageCreation
Int -> ReadS CancelImageCreation
ReadS [CancelImageCreation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelImageCreation]
$creadListPrec :: ReadPrec [CancelImageCreation]
readPrec :: ReadPrec CancelImageCreation
$creadPrec :: ReadPrec CancelImageCreation
readList :: ReadS [CancelImageCreation]
$creadList :: ReadS [CancelImageCreation]
readsPrec :: Int -> ReadS CancelImageCreation
$creadsPrec :: Int -> ReadS CancelImageCreation
Prelude.Read, Int -> CancelImageCreation -> ShowS
[CancelImageCreation] -> ShowS
CancelImageCreation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelImageCreation] -> ShowS
$cshowList :: [CancelImageCreation] -> ShowS
show :: CancelImageCreation -> String
$cshow :: CancelImageCreation -> String
showsPrec :: Int -> CancelImageCreation -> ShowS
$cshowsPrec :: Int -> CancelImageCreation -> ShowS
Prelude.Show, forall x. Rep CancelImageCreation x -> CancelImageCreation
forall x. CancelImageCreation -> Rep CancelImageCreation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelImageCreation x -> CancelImageCreation
$cfrom :: forall x. CancelImageCreation -> Rep CancelImageCreation x
Prelude.Generic)

-- |
-- Create a value of 'CancelImageCreation' 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:
--
-- 'imageBuildVersionArn', 'cancelImageCreation_imageBuildVersionArn' - The Amazon Resource Name (ARN) of the image whose creation you want to
-- cancel.
--
-- 'clientToken', 'cancelImageCreation_clientToken' - Unique, case-sensitive identifier you provide to ensure idempotency of
-- the request. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html Ensuring idempotency>
-- in the /Amazon EC2 API Reference/.
newCancelImageCreation ::
  -- | 'imageBuildVersionArn'
  Prelude.Text ->
  -- | 'clientToken'
  Prelude.Text ->
  CancelImageCreation
newCancelImageCreation :: Text -> Text -> CancelImageCreation
newCancelImageCreation
  Text
pImageBuildVersionArn_
  Text
pClientToken_ =
    CancelImageCreation'
      { $sel:imageBuildVersionArn:CancelImageCreation' :: Text
imageBuildVersionArn =
          Text
pImageBuildVersionArn_,
        $sel:clientToken:CancelImageCreation' :: Text
clientToken = Text
pClientToken_
      }

-- | The Amazon Resource Name (ARN) of the image whose creation you want to
-- cancel.
cancelImageCreation_imageBuildVersionArn :: Lens.Lens' CancelImageCreation Prelude.Text
cancelImageCreation_imageBuildVersionArn :: Lens' CancelImageCreation Text
cancelImageCreation_imageBuildVersionArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelImageCreation' {Text
imageBuildVersionArn :: Text
$sel:imageBuildVersionArn:CancelImageCreation' :: CancelImageCreation -> Text
imageBuildVersionArn} -> Text
imageBuildVersionArn) (\s :: CancelImageCreation
s@CancelImageCreation' {} Text
a -> CancelImageCreation
s {$sel:imageBuildVersionArn:CancelImageCreation' :: Text
imageBuildVersionArn = Text
a} :: CancelImageCreation)

-- | Unique, case-sensitive identifier you provide to ensure idempotency of
-- the request. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html Ensuring idempotency>
-- in the /Amazon EC2 API Reference/.
cancelImageCreation_clientToken :: Lens.Lens' CancelImageCreation Prelude.Text
cancelImageCreation_clientToken :: Lens' CancelImageCreation Text
cancelImageCreation_clientToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelImageCreation' {Text
clientToken :: Text
$sel:clientToken:CancelImageCreation' :: CancelImageCreation -> Text
clientToken} -> Text
clientToken) (\s :: CancelImageCreation
s@CancelImageCreation' {} Text
a -> CancelImageCreation
s {$sel:clientToken:CancelImageCreation' :: Text
clientToken = Text
a} :: CancelImageCreation)

instance Core.AWSRequest CancelImageCreation where
  type
    AWSResponse CancelImageCreation =
      CancelImageCreationResponse
  request :: (Service -> Service)
-> CancelImageCreation -> Request CancelImageCreation
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CancelImageCreation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CancelImageCreation)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Int -> CancelImageCreationResponse
CancelImageCreationResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"clientToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"imageBuildVersionArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"requestId")
            forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable CancelImageCreation where
  hashWithSalt :: Int -> CancelImageCreation -> Int
hashWithSalt Int
_salt CancelImageCreation' {Text
clientToken :: Text
imageBuildVersionArn :: Text
$sel:clientToken:CancelImageCreation' :: CancelImageCreation -> Text
$sel:imageBuildVersionArn:CancelImageCreation' :: CancelImageCreation -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
imageBuildVersionArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
clientToken

instance Prelude.NFData CancelImageCreation where
  rnf :: CancelImageCreation -> ()
rnf CancelImageCreation' {Text
clientToken :: Text
imageBuildVersionArn :: Text
$sel:clientToken:CancelImageCreation' :: CancelImageCreation -> Text
$sel:imageBuildVersionArn:CancelImageCreation' :: CancelImageCreation -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
imageBuildVersionArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
clientToken

instance Data.ToHeaders CancelImageCreation where
  toHeaders :: CancelImageCreation -> 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.ToJSON CancelImageCreation where
  toJSON :: CancelImageCreation -> Value
toJSON CancelImageCreation' {Text
clientToken :: Text
imageBuildVersionArn :: Text
$sel:clientToken:CancelImageCreation' :: CancelImageCreation -> Text
$sel:imageBuildVersionArn:CancelImageCreation' :: CancelImageCreation -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"imageBuildVersionArn"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
imageBuildVersionArn
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"clientToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
clientToken)
          ]
      )

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

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

-- | /See:/ 'newCancelImageCreationResponse' smart constructor.
data CancelImageCreationResponse = CancelImageCreationResponse'
  { -- | The idempotency token that was used for this request.
    CancelImageCreationResponse -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the image whose creation has been
    -- cancelled.
    CancelImageCreationResponse -> Maybe Text
imageBuildVersionArn :: Prelude.Maybe Prelude.Text,
    -- | The request ID that uniquely identifies this request.
    CancelImageCreationResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CancelImageCreationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelImageCreationResponse -> CancelImageCreationResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelImageCreationResponse -> CancelImageCreationResponse -> Bool
$c/= :: CancelImageCreationResponse -> CancelImageCreationResponse -> Bool
== :: CancelImageCreationResponse -> CancelImageCreationResponse -> Bool
$c== :: CancelImageCreationResponse -> CancelImageCreationResponse -> Bool
Prelude.Eq, ReadPrec [CancelImageCreationResponse]
ReadPrec CancelImageCreationResponse
Int -> ReadS CancelImageCreationResponse
ReadS [CancelImageCreationResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelImageCreationResponse]
$creadListPrec :: ReadPrec [CancelImageCreationResponse]
readPrec :: ReadPrec CancelImageCreationResponse
$creadPrec :: ReadPrec CancelImageCreationResponse
readList :: ReadS [CancelImageCreationResponse]
$creadList :: ReadS [CancelImageCreationResponse]
readsPrec :: Int -> ReadS CancelImageCreationResponse
$creadsPrec :: Int -> ReadS CancelImageCreationResponse
Prelude.Read, Int -> CancelImageCreationResponse -> ShowS
[CancelImageCreationResponse] -> ShowS
CancelImageCreationResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelImageCreationResponse] -> ShowS
$cshowList :: [CancelImageCreationResponse] -> ShowS
show :: CancelImageCreationResponse -> String
$cshow :: CancelImageCreationResponse -> String
showsPrec :: Int -> CancelImageCreationResponse -> ShowS
$cshowsPrec :: Int -> CancelImageCreationResponse -> ShowS
Prelude.Show, forall x.
Rep CancelImageCreationResponse x -> CancelImageCreationResponse
forall x.
CancelImageCreationResponse -> Rep CancelImageCreationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelImageCreationResponse x -> CancelImageCreationResponse
$cfrom :: forall x.
CancelImageCreationResponse -> Rep CancelImageCreationResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelImageCreationResponse' 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:
--
-- 'clientToken', 'cancelImageCreationResponse_clientToken' - The idempotency token that was used for this request.
--
-- 'imageBuildVersionArn', 'cancelImageCreationResponse_imageBuildVersionArn' - The Amazon Resource Name (ARN) of the image whose creation has been
-- cancelled.
--
-- 'requestId', 'cancelImageCreationResponse_requestId' - The request ID that uniquely identifies this request.
--
-- 'httpStatus', 'cancelImageCreationResponse_httpStatus' - The response's http status code.
newCancelImageCreationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelImageCreationResponse
newCancelImageCreationResponse :: Int -> CancelImageCreationResponse
newCancelImageCreationResponse Int
pHttpStatus_ =
  CancelImageCreationResponse'
    { $sel:clientToken:CancelImageCreationResponse' :: Maybe Text
clientToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:imageBuildVersionArn:CancelImageCreationResponse' :: Maybe Text
imageBuildVersionArn = forall a. Maybe a
Prelude.Nothing,
      $sel:requestId:CancelImageCreationResponse' :: Maybe Text
requestId = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelImageCreationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The idempotency token that was used for this request.
cancelImageCreationResponse_clientToken :: Lens.Lens' CancelImageCreationResponse (Prelude.Maybe Prelude.Text)
cancelImageCreationResponse_clientToken :: Lens' CancelImageCreationResponse (Maybe Text)
cancelImageCreationResponse_clientToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelImageCreationResponse' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:CancelImageCreationResponse' :: CancelImageCreationResponse -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: CancelImageCreationResponse
s@CancelImageCreationResponse' {} Maybe Text
a -> CancelImageCreationResponse
s {$sel:clientToken:CancelImageCreationResponse' :: Maybe Text
clientToken = Maybe Text
a} :: CancelImageCreationResponse)

-- | The Amazon Resource Name (ARN) of the image whose creation has been
-- cancelled.
cancelImageCreationResponse_imageBuildVersionArn :: Lens.Lens' CancelImageCreationResponse (Prelude.Maybe Prelude.Text)
cancelImageCreationResponse_imageBuildVersionArn :: Lens' CancelImageCreationResponse (Maybe Text)
cancelImageCreationResponse_imageBuildVersionArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelImageCreationResponse' {Maybe Text
imageBuildVersionArn :: Maybe Text
$sel:imageBuildVersionArn:CancelImageCreationResponse' :: CancelImageCreationResponse -> Maybe Text
imageBuildVersionArn} -> Maybe Text
imageBuildVersionArn) (\s :: CancelImageCreationResponse
s@CancelImageCreationResponse' {} Maybe Text
a -> CancelImageCreationResponse
s {$sel:imageBuildVersionArn:CancelImageCreationResponse' :: Maybe Text
imageBuildVersionArn = Maybe Text
a} :: CancelImageCreationResponse)

-- | The request ID that uniquely identifies this request.
cancelImageCreationResponse_requestId :: Lens.Lens' CancelImageCreationResponse (Prelude.Maybe Prelude.Text)
cancelImageCreationResponse_requestId :: Lens' CancelImageCreationResponse (Maybe Text)
cancelImageCreationResponse_requestId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelImageCreationResponse' {Maybe Text
requestId :: Maybe Text
$sel:requestId:CancelImageCreationResponse' :: CancelImageCreationResponse -> Maybe Text
requestId} -> Maybe Text
requestId) (\s :: CancelImageCreationResponse
s@CancelImageCreationResponse' {} Maybe Text
a -> CancelImageCreationResponse
s {$sel:requestId:CancelImageCreationResponse' :: Maybe Text
requestId = Maybe Text
a} :: CancelImageCreationResponse)

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

instance Prelude.NFData CancelImageCreationResponse where
  rnf :: CancelImageCreationResponse -> ()
rnf CancelImageCreationResponse' {Int
Maybe Text
httpStatus :: Int
requestId :: Maybe Text
imageBuildVersionArn :: Maybe Text
clientToken :: Maybe Text
$sel:httpStatus:CancelImageCreationResponse' :: CancelImageCreationResponse -> Int
$sel:requestId:CancelImageCreationResponse' :: CancelImageCreationResponse -> Maybe Text
$sel:imageBuildVersionArn:CancelImageCreationResponse' :: CancelImageCreationResponse -> Maybe Text
$sel:clientToken:CancelImageCreationResponse' :: CancelImageCreationResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
imageBuildVersionArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
requestId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus