{-# 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.CloudControl.CancelResourceRequest
-- 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 the specified resource operation request. For more information,
-- see
-- <https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/resource-operations-manage-requests.html#resource-operations-manage-requests-cancel Canceling resource operation requests>
-- in the /Amazon Web Services Cloud Control API User Guide/.
--
-- Only resource operations requests with a status of @PENDING@ or
-- @IN_PROGRESS@ can be cancelled.
module Amazonka.CloudControl.CancelResourceRequest
  ( -- * Creating a Request
    CancelResourceRequest (..),
    newCancelResourceRequest,

    -- * Request Lenses
    cancelResourceRequest_requestToken,

    -- * Destructuring the Response
    CancelResourceRequestResponse (..),
    newCancelResourceRequestResponse,

    -- * Response Lenses
    cancelResourceRequestResponse_progressEvent,
    cancelResourceRequestResponse_httpStatus,
  )
where

import Amazonka.CloudControl.Types
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

-- | /See:/ 'newCancelResourceRequest' smart constructor.
data CancelResourceRequest = CancelResourceRequest'
  { -- | The @RequestToken@ of the @ProgressEvent@ object returned by the
    -- resource operation request.
    CancelResourceRequest -> Text
requestToken :: Prelude.Text
  }
  deriving (CancelResourceRequest -> CancelResourceRequest -> Bool
(CancelResourceRequest -> CancelResourceRequest -> Bool)
-> (CancelResourceRequest -> CancelResourceRequest -> Bool)
-> Eq CancelResourceRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelResourceRequest -> CancelResourceRequest -> Bool
$c/= :: CancelResourceRequest -> CancelResourceRequest -> Bool
== :: CancelResourceRequest -> CancelResourceRequest -> Bool
$c== :: CancelResourceRequest -> CancelResourceRequest -> Bool
Prelude.Eq, ReadPrec [CancelResourceRequest]
ReadPrec CancelResourceRequest
Int -> ReadS CancelResourceRequest
ReadS [CancelResourceRequest]
(Int -> ReadS CancelResourceRequest)
-> ReadS [CancelResourceRequest]
-> ReadPrec CancelResourceRequest
-> ReadPrec [CancelResourceRequest]
-> Read CancelResourceRequest
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelResourceRequest]
$creadListPrec :: ReadPrec [CancelResourceRequest]
readPrec :: ReadPrec CancelResourceRequest
$creadPrec :: ReadPrec CancelResourceRequest
readList :: ReadS [CancelResourceRequest]
$creadList :: ReadS [CancelResourceRequest]
readsPrec :: Int -> ReadS CancelResourceRequest
$creadsPrec :: Int -> ReadS CancelResourceRequest
Prelude.Read, Int -> CancelResourceRequest -> ShowS
[CancelResourceRequest] -> ShowS
CancelResourceRequest -> String
(Int -> CancelResourceRequest -> ShowS)
-> (CancelResourceRequest -> String)
-> ([CancelResourceRequest] -> ShowS)
-> Show CancelResourceRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelResourceRequest] -> ShowS
$cshowList :: [CancelResourceRequest] -> ShowS
show :: CancelResourceRequest -> String
$cshow :: CancelResourceRequest -> String
showsPrec :: Int -> CancelResourceRequest -> ShowS
$cshowsPrec :: Int -> CancelResourceRequest -> ShowS
Prelude.Show, (forall x. CancelResourceRequest -> Rep CancelResourceRequest x)
-> (forall x. Rep CancelResourceRequest x -> CancelResourceRequest)
-> Generic CancelResourceRequest
forall x. Rep CancelResourceRequest x -> CancelResourceRequest
forall x. CancelResourceRequest -> Rep CancelResourceRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelResourceRequest x -> CancelResourceRequest
$cfrom :: forall x. CancelResourceRequest -> Rep CancelResourceRequest x
Prelude.Generic)

-- |
-- Create a value of 'CancelResourceRequest' 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:
--
-- 'requestToken', 'cancelResourceRequest_requestToken' - The @RequestToken@ of the @ProgressEvent@ object returned by the
-- resource operation request.
newCancelResourceRequest ::
  -- | 'requestToken'
  Prelude.Text ->
  CancelResourceRequest
newCancelResourceRequest :: Text -> CancelResourceRequest
newCancelResourceRequest Text
pRequestToken_ =
  CancelResourceRequest' :: Text -> CancelResourceRequest
CancelResourceRequest'
    { $sel:requestToken:CancelResourceRequest' :: Text
requestToken =
        Text
pRequestToken_
    }

-- | The @RequestToken@ of the @ProgressEvent@ object returned by the
-- resource operation request.
cancelResourceRequest_requestToken :: Lens.Lens' CancelResourceRequest Prelude.Text
cancelResourceRequest_requestToken :: (Text -> f Text)
-> CancelResourceRequest -> f CancelResourceRequest
cancelResourceRequest_requestToken = (CancelResourceRequest -> Text)
-> (CancelResourceRequest -> Text -> CancelResourceRequest)
-> Lens CancelResourceRequest CancelResourceRequest Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelResourceRequest' {Text
requestToken :: Text
$sel:requestToken:CancelResourceRequest' :: CancelResourceRequest -> Text
requestToken} -> Text
requestToken) (\s :: CancelResourceRequest
s@CancelResourceRequest' {} Text
a -> CancelResourceRequest
s {$sel:requestToken:CancelResourceRequest' :: Text
requestToken = Text
a} :: CancelResourceRequest)

instance Core.AWSRequest CancelResourceRequest where
  type
    AWSResponse CancelResourceRequest =
      CancelResourceRequestResponse
  request :: CancelResourceRequest -> Request CancelResourceRequest
request = Service -> CancelResourceRequest -> Request CancelResourceRequest
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CancelResourceRequest
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CancelResourceRequest)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CancelResourceRequest))
-> Logger
-> Service
-> Proxy CancelResourceRequest
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CancelResourceRequest)))
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 ProgressEvent -> Int -> CancelResourceRequestResponse
CancelResourceRequestResponse'
            (Maybe ProgressEvent -> Int -> CancelResourceRequestResponse)
-> Either String (Maybe ProgressEvent)
-> Either String (Int -> CancelResourceRequestResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe ProgressEvent)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ProgressEvent")
            Either String (Int -> CancelResourceRequestResponse)
-> Either String Int -> Either String CancelResourceRequestResponse
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 CancelResourceRequest

instance Prelude.NFData CancelResourceRequest

instance Core.ToHeaders CancelResourceRequest where
  toHeaders :: CancelResourceRequest -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CancelResourceRequest -> 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
"CloudApiService.CancelResourceRequest" ::
                          Prelude.ByteString
                      ),
            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 CancelResourceRequest where
  toJSON :: CancelResourceRequest -> Value
toJSON CancelResourceRequest' {Text
requestToken :: Text
$sel:requestToken:CancelResourceRequest' :: CancelResourceRequest -> 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
"RequestToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
requestToken)]
      )

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

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

-- | /See:/ 'newCancelResourceRequestResponse' smart constructor.
data CancelResourceRequestResponse = CancelResourceRequestResponse'
  { CancelResourceRequestResponse -> Maybe ProgressEvent
progressEvent :: Prelude.Maybe ProgressEvent,
    -- | The response's http status code.
    CancelResourceRequestResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelResourceRequestResponse
-> CancelResourceRequestResponse -> Bool
(CancelResourceRequestResponse
 -> CancelResourceRequestResponse -> Bool)
-> (CancelResourceRequestResponse
    -> CancelResourceRequestResponse -> Bool)
-> Eq CancelResourceRequestResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelResourceRequestResponse
-> CancelResourceRequestResponse -> Bool
$c/= :: CancelResourceRequestResponse
-> CancelResourceRequestResponse -> Bool
== :: CancelResourceRequestResponse
-> CancelResourceRequestResponse -> Bool
$c== :: CancelResourceRequestResponse
-> CancelResourceRequestResponse -> Bool
Prelude.Eq, Int -> CancelResourceRequestResponse -> ShowS
[CancelResourceRequestResponse] -> ShowS
CancelResourceRequestResponse -> String
(Int -> CancelResourceRequestResponse -> ShowS)
-> (CancelResourceRequestResponse -> String)
-> ([CancelResourceRequestResponse] -> ShowS)
-> Show CancelResourceRequestResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelResourceRequestResponse] -> ShowS
$cshowList :: [CancelResourceRequestResponse] -> ShowS
show :: CancelResourceRequestResponse -> String
$cshow :: CancelResourceRequestResponse -> String
showsPrec :: Int -> CancelResourceRequestResponse -> ShowS
$cshowsPrec :: Int -> CancelResourceRequestResponse -> ShowS
Prelude.Show, (forall x.
 CancelResourceRequestResponse
 -> Rep CancelResourceRequestResponse x)
-> (forall x.
    Rep CancelResourceRequestResponse x
    -> CancelResourceRequestResponse)
-> Generic CancelResourceRequestResponse
forall x.
Rep CancelResourceRequestResponse x
-> CancelResourceRequestResponse
forall x.
CancelResourceRequestResponse
-> Rep CancelResourceRequestResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelResourceRequestResponse x
-> CancelResourceRequestResponse
$cfrom :: forall x.
CancelResourceRequestResponse
-> Rep CancelResourceRequestResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelResourceRequestResponse' 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:
--
-- 'progressEvent', 'cancelResourceRequestResponse_progressEvent' - Undocumented member.
--
-- 'httpStatus', 'cancelResourceRequestResponse_httpStatus' - The response's http status code.
newCancelResourceRequestResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelResourceRequestResponse
newCancelResourceRequestResponse :: Int -> CancelResourceRequestResponse
newCancelResourceRequestResponse Int
pHttpStatus_ =
  CancelResourceRequestResponse' :: Maybe ProgressEvent -> Int -> CancelResourceRequestResponse
CancelResourceRequestResponse'
    { $sel:progressEvent:CancelResourceRequestResponse' :: Maybe ProgressEvent
progressEvent =
        Maybe ProgressEvent
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelResourceRequestResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
cancelResourceRequestResponse_progressEvent :: Lens.Lens' CancelResourceRequestResponse (Prelude.Maybe ProgressEvent)
cancelResourceRequestResponse_progressEvent :: (Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> CancelResourceRequestResponse -> f CancelResourceRequestResponse
cancelResourceRequestResponse_progressEvent = (CancelResourceRequestResponse -> Maybe ProgressEvent)
-> (CancelResourceRequestResponse
    -> Maybe ProgressEvent -> CancelResourceRequestResponse)
-> Lens
     CancelResourceRequestResponse
     CancelResourceRequestResponse
     (Maybe ProgressEvent)
     (Maybe ProgressEvent)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelResourceRequestResponse' {Maybe ProgressEvent
progressEvent :: Maybe ProgressEvent
$sel:progressEvent:CancelResourceRequestResponse' :: CancelResourceRequestResponse -> Maybe ProgressEvent
progressEvent} -> Maybe ProgressEvent
progressEvent) (\s :: CancelResourceRequestResponse
s@CancelResourceRequestResponse' {} Maybe ProgressEvent
a -> CancelResourceRequestResponse
s {$sel:progressEvent:CancelResourceRequestResponse' :: Maybe ProgressEvent
progressEvent = Maybe ProgressEvent
a} :: CancelResourceRequestResponse)

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

instance Prelude.NFData CancelResourceRequestResponse