{-# 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.CloudWatchEvents.CancelReplay
-- 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 replay.
module Amazonka.CloudWatchEvents.CancelReplay
  ( -- * Creating a Request
    CancelReplay (..),
    newCancelReplay,

    -- * Request Lenses
    cancelReplay_replayName,

    -- * Destructuring the Response
    CancelReplayResponse (..),
    newCancelReplayResponse,

    -- * Response Lenses
    cancelReplayResponse_state,
    cancelReplayResponse_replayArn,
    cancelReplayResponse_stateReason,
    cancelReplayResponse_httpStatus,
  )
where

import Amazonka.CloudWatchEvents.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:/ 'newCancelReplay' smart constructor.
data CancelReplay = CancelReplay'
  { -- | The name of the replay to cancel.
    CancelReplay -> Text
replayName :: Prelude.Text
  }
  deriving (CancelReplay -> CancelReplay -> Bool
(CancelReplay -> CancelReplay -> Bool)
-> (CancelReplay -> CancelReplay -> Bool) -> Eq CancelReplay
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelReplay -> CancelReplay -> Bool
$c/= :: CancelReplay -> CancelReplay -> Bool
== :: CancelReplay -> CancelReplay -> Bool
$c== :: CancelReplay -> CancelReplay -> Bool
Prelude.Eq, ReadPrec [CancelReplay]
ReadPrec CancelReplay
Int -> ReadS CancelReplay
ReadS [CancelReplay]
(Int -> ReadS CancelReplay)
-> ReadS [CancelReplay]
-> ReadPrec CancelReplay
-> ReadPrec [CancelReplay]
-> Read CancelReplay
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelReplay]
$creadListPrec :: ReadPrec [CancelReplay]
readPrec :: ReadPrec CancelReplay
$creadPrec :: ReadPrec CancelReplay
readList :: ReadS [CancelReplay]
$creadList :: ReadS [CancelReplay]
readsPrec :: Int -> ReadS CancelReplay
$creadsPrec :: Int -> ReadS CancelReplay
Prelude.Read, Int -> CancelReplay -> ShowS
[CancelReplay] -> ShowS
CancelReplay -> String
(Int -> CancelReplay -> ShowS)
-> (CancelReplay -> String)
-> ([CancelReplay] -> ShowS)
-> Show CancelReplay
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelReplay] -> ShowS
$cshowList :: [CancelReplay] -> ShowS
show :: CancelReplay -> String
$cshow :: CancelReplay -> String
showsPrec :: Int -> CancelReplay -> ShowS
$cshowsPrec :: Int -> CancelReplay -> ShowS
Prelude.Show, (forall x. CancelReplay -> Rep CancelReplay x)
-> (forall x. Rep CancelReplay x -> CancelReplay)
-> Generic CancelReplay
forall x. Rep CancelReplay x -> CancelReplay
forall x. CancelReplay -> Rep CancelReplay x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelReplay x -> CancelReplay
$cfrom :: forall x. CancelReplay -> Rep CancelReplay x
Prelude.Generic)

-- |
-- Create a value of 'CancelReplay' 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:
--
-- 'replayName', 'cancelReplay_replayName' - The name of the replay to cancel.
newCancelReplay ::
  -- | 'replayName'
  Prelude.Text ->
  CancelReplay
newCancelReplay :: Text -> CancelReplay
newCancelReplay Text
pReplayName_ =
  CancelReplay' :: Text -> CancelReplay
CancelReplay' {$sel:replayName:CancelReplay' :: Text
replayName = Text
pReplayName_}

-- | The name of the replay to cancel.
cancelReplay_replayName :: Lens.Lens' CancelReplay Prelude.Text
cancelReplay_replayName :: (Text -> f Text) -> CancelReplay -> f CancelReplay
cancelReplay_replayName = (CancelReplay -> Text)
-> (CancelReplay -> Text -> CancelReplay)
-> Lens CancelReplay CancelReplay Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelReplay' {Text
replayName :: Text
$sel:replayName:CancelReplay' :: CancelReplay -> Text
replayName} -> Text
replayName) (\s :: CancelReplay
s@CancelReplay' {} Text
a -> CancelReplay
s {$sel:replayName:CancelReplay' :: Text
replayName = Text
a} :: CancelReplay)

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

instance Prelude.NFData CancelReplay

instance Core.ToHeaders CancelReplay where
  toHeaders :: CancelReplay -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CancelReplay -> 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
"AWSEvents.CancelReplay" :: 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 CancelReplay where
  toJSON :: CancelReplay -> Value
toJSON CancelReplay' {Text
replayName :: Text
$sel:replayName:CancelReplay' :: CancelReplay -> 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
"ReplayName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
replayName)]
      )

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

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

-- | /See:/ 'newCancelReplayResponse' smart constructor.
data CancelReplayResponse = CancelReplayResponse'
  { -- | The current state of the replay.
    CancelReplayResponse -> Maybe ReplayState
state :: Prelude.Maybe ReplayState,
    -- | The ARN of the replay to cancel.
    CancelReplayResponse -> Maybe Text
replayArn :: Prelude.Maybe Prelude.Text,
    -- | The reason that the replay is in the current state.
    CancelReplayResponse -> Maybe Text
stateReason :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CancelReplayResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelReplayResponse -> CancelReplayResponse -> Bool
(CancelReplayResponse -> CancelReplayResponse -> Bool)
-> (CancelReplayResponse -> CancelReplayResponse -> Bool)
-> Eq CancelReplayResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelReplayResponse -> CancelReplayResponse -> Bool
$c/= :: CancelReplayResponse -> CancelReplayResponse -> Bool
== :: CancelReplayResponse -> CancelReplayResponse -> Bool
$c== :: CancelReplayResponse -> CancelReplayResponse -> Bool
Prelude.Eq, ReadPrec [CancelReplayResponse]
ReadPrec CancelReplayResponse
Int -> ReadS CancelReplayResponse
ReadS [CancelReplayResponse]
(Int -> ReadS CancelReplayResponse)
-> ReadS [CancelReplayResponse]
-> ReadPrec CancelReplayResponse
-> ReadPrec [CancelReplayResponse]
-> Read CancelReplayResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelReplayResponse]
$creadListPrec :: ReadPrec [CancelReplayResponse]
readPrec :: ReadPrec CancelReplayResponse
$creadPrec :: ReadPrec CancelReplayResponse
readList :: ReadS [CancelReplayResponse]
$creadList :: ReadS [CancelReplayResponse]
readsPrec :: Int -> ReadS CancelReplayResponse
$creadsPrec :: Int -> ReadS CancelReplayResponse
Prelude.Read, Int -> CancelReplayResponse -> ShowS
[CancelReplayResponse] -> ShowS
CancelReplayResponse -> String
(Int -> CancelReplayResponse -> ShowS)
-> (CancelReplayResponse -> String)
-> ([CancelReplayResponse] -> ShowS)
-> Show CancelReplayResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelReplayResponse] -> ShowS
$cshowList :: [CancelReplayResponse] -> ShowS
show :: CancelReplayResponse -> String
$cshow :: CancelReplayResponse -> String
showsPrec :: Int -> CancelReplayResponse -> ShowS
$cshowsPrec :: Int -> CancelReplayResponse -> ShowS
Prelude.Show, (forall x. CancelReplayResponse -> Rep CancelReplayResponse x)
-> (forall x. Rep CancelReplayResponse x -> CancelReplayResponse)
-> Generic CancelReplayResponse
forall x. Rep CancelReplayResponse x -> CancelReplayResponse
forall x. CancelReplayResponse -> Rep CancelReplayResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelReplayResponse x -> CancelReplayResponse
$cfrom :: forall x. CancelReplayResponse -> Rep CancelReplayResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelReplayResponse' 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:
--
-- 'state', 'cancelReplayResponse_state' - The current state of the replay.
--
-- 'replayArn', 'cancelReplayResponse_replayArn' - The ARN of the replay to cancel.
--
-- 'stateReason', 'cancelReplayResponse_stateReason' - The reason that the replay is in the current state.
--
-- 'httpStatus', 'cancelReplayResponse_httpStatus' - The response's http status code.
newCancelReplayResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelReplayResponse
newCancelReplayResponse :: Int -> CancelReplayResponse
newCancelReplayResponse Int
pHttpStatus_ =
  CancelReplayResponse' :: Maybe ReplayState
-> Maybe Text -> Maybe Text -> Int -> CancelReplayResponse
CancelReplayResponse'
    { $sel:state:CancelReplayResponse' :: Maybe ReplayState
state = Maybe ReplayState
forall a. Maybe a
Prelude.Nothing,
      $sel:replayArn:CancelReplayResponse' :: Maybe Text
replayArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stateReason:CancelReplayResponse' :: Maybe Text
stateReason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelReplayResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The current state of the replay.
cancelReplayResponse_state :: Lens.Lens' CancelReplayResponse (Prelude.Maybe ReplayState)
cancelReplayResponse_state :: (Maybe ReplayState -> f (Maybe ReplayState))
-> CancelReplayResponse -> f CancelReplayResponse
cancelReplayResponse_state = (CancelReplayResponse -> Maybe ReplayState)
-> (CancelReplayResponse
    -> Maybe ReplayState -> CancelReplayResponse)
-> Lens
     CancelReplayResponse
     CancelReplayResponse
     (Maybe ReplayState)
     (Maybe ReplayState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelReplayResponse' {Maybe ReplayState
state :: Maybe ReplayState
$sel:state:CancelReplayResponse' :: CancelReplayResponse -> Maybe ReplayState
state} -> Maybe ReplayState
state) (\s :: CancelReplayResponse
s@CancelReplayResponse' {} Maybe ReplayState
a -> CancelReplayResponse
s {$sel:state:CancelReplayResponse' :: Maybe ReplayState
state = Maybe ReplayState
a} :: CancelReplayResponse)

-- | The ARN of the replay to cancel.
cancelReplayResponse_replayArn :: Lens.Lens' CancelReplayResponse (Prelude.Maybe Prelude.Text)
cancelReplayResponse_replayArn :: (Maybe Text -> f (Maybe Text))
-> CancelReplayResponse -> f CancelReplayResponse
cancelReplayResponse_replayArn = (CancelReplayResponse -> Maybe Text)
-> (CancelReplayResponse -> Maybe Text -> CancelReplayResponse)
-> Lens
     CancelReplayResponse CancelReplayResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelReplayResponse' {Maybe Text
replayArn :: Maybe Text
$sel:replayArn:CancelReplayResponse' :: CancelReplayResponse -> Maybe Text
replayArn} -> Maybe Text
replayArn) (\s :: CancelReplayResponse
s@CancelReplayResponse' {} Maybe Text
a -> CancelReplayResponse
s {$sel:replayArn:CancelReplayResponse' :: Maybe Text
replayArn = Maybe Text
a} :: CancelReplayResponse)

-- | The reason that the replay is in the current state.
cancelReplayResponse_stateReason :: Lens.Lens' CancelReplayResponse (Prelude.Maybe Prelude.Text)
cancelReplayResponse_stateReason :: (Maybe Text -> f (Maybe Text))
-> CancelReplayResponse -> f CancelReplayResponse
cancelReplayResponse_stateReason = (CancelReplayResponse -> Maybe Text)
-> (CancelReplayResponse -> Maybe Text -> CancelReplayResponse)
-> Lens
     CancelReplayResponse CancelReplayResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelReplayResponse' {Maybe Text
stateReason :: Maybe Text
$sel:stateReason:CancelReplayResponse' :: CancelReplayResponse -> Maybe Text
stateReason} -> Maybe Text
stateReason) (\s :: CancelReplayResponse
s@CancelReplayResponse' {} Maybe Text
a -> CancelReplayResponse
s {$sel:stateReason:CancelReplayResponse' :: Maybe Text
stateReason = Maybe Text
a} :: CancelReplayResponse)

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

instance Prelude.NFData CancelReplayResponse