{-# 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.SSM.SendAutomationSignal
-- 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)
--
-- Sends a signal to an Automation execution to change the current behavior
-- or status of the execution.
module Amazonka.SSM.SendAutomationSignal
  ( -- * Creating a Request
    SendAutomationSignal (..),
    newSendAutomationSignal,

    -- * Request Lenses
    sendAutomationSignal_payload,
    sendAutomationSignal_automationExecutionId,
    sendAutomationSignal_signalType,

    -- * Destructuring the Response
    SendAutomationSignalResponse (..),
    newSendAutomationSignalResponse,

    -- * Response Lenses
    sendAutomationSignalResponse_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.SSM.Types

-- | /See:/ 'newSendAutomationSignal' smart constructor.
data SendAutomationSignal = SendAutomationSignal'
  { -- | The data sent with the signal. The data schema depends on the type of
    -- signal used in the request.
    --
    -- For @Approve@ and @Reject@ signal types, the payload is an optional
    -- comment that you can send with the signal type. For example:
    --
    -- @Comment=\"Looks good\"@
    --
    -- For @StartStep@ and @Resume@ signal types, you must send the name of the
    -- Automation step to start or resume as the payload. For example:
    --
    -- @StepName=\"step1\"@
    --
    -- For the @StopStep@ signal type, you must send the step execution ID as
    -- the payload. For example:
    --
    -- @StepExecutionId=\"97fff367-fc5a-4299-aed8-0123456789ab\"@
    SendAutomationSignal -> Maybe (HashMap Text [Text])
payload :: Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]),
    -- | The unique identifier for an existing Automation execution that you want
    -- to send the signal to.
    SendAutomationSignal -> Text
automationExecutionId :: Prelude.Text,
    -- | The type of signal to send to an Automation execution.
    SendAutomationSignal -> SignalType
signalType :: SignalType
  }
  deriving (SendAutomationSignal -> SendAutomationSignal -> Bool
(SendAutomationSignal -> SendAutomationSignal -> Bool)
-> (SendAutomationSignal -> SendAutomationSignal -> Bool)
-> Eq SendAutomationSignal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendAutomationSignal -> SendAutomationSignal -> Bool
$c/= :: SendAutomationSignal -> SendAutomationSignal -> Bool
== :: SendAutomationSignal -> SendAutomationSignal -> Bool
$c== :: SendAutomationSignal -> SendAutomationSignal -> Bool
Prelude.Eq, ReadPrec [SendAutomationSignal]
ReadPrec SendAutomationSignal
Int -> ReadS SendAutomationSignal
ReadS [SendAutomationSignal]
(Int -> ReadS SendAutomationSignal)
-> ReadS [SendAutomationSignal]
-> ReadPrec SendAutomationSignal
-> ReadPrec [SendAutomationSignal]
-> Read SendAutomationSignal
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendAutomationSignal]
$creadListPrec :: ReadPrec [SendAutomationSignal]
readPrec :: ReadPrec SendAutomationSignal
$creadPrec :: ReadPrec SendAutomationSignal
readList :: ReadS [SendAutomationSignal]
$creadList :: ReadS [SendAutomationSignal]
readsPrec :: Int -> ReadS SendAutomationSignal
$creadsPrec :: Int -> ReadS SendAutomationSignal
Prelude.Read, Int -> SendAutomationSignal -> ShowS
[SendAutomationSignal] -> ShowS
SendAutomationSignal -> String
(Int -> SendAutomationSignal -> ShowS)
-> (SendAutomationSignal -> String)
-> ([SendAutomationSignal] -> ShowS)
-> Show SendAutomationSignal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendAutomationSignal] -> ShowS
$cshowList :: [SendAutomationSignal] -> ShowS
show :: SendAutomationSignal -> String
$cshow :: SendAutomationSignal -> String
showsPrec :: Int -> SendAutomationSignal -> ShowS
$cshowsPrec :: Int -> SendAutomationSignal -> ShowS
Prelude.Show, (forall x. SendAutomationSignal -> Rep SendAutomationSignal x)
-> (forall x. Rep SendAutomationSignal x -> SendAutomationSignal)
-> Generic SendAutomationSignal
forall x. Rep SendAutomationSignal x -> SendAutomationSignal
forall x. SendAutomationSignal -> Rep SendAutomationSignal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendAutomationSignal x -> SendAutomationSignal
$cfrom :: forall x. SendAutomationSignal -> Rep SendAutomationSignal x
Prelude.Generic)

-- |
-- Create a value of 'SendAutomationSignal' 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:
--
-- 'payload', 'sendAutomationSignal_payload' - The data sent with the signal. The data schema depends on the type of
-- signal used in the request.
--
-- For @Approve@ and @Reject@ signal types, the payload is an optional
-- comment that you can send with the signal type. For example:
--
-- @Comment=\"Looks good\"@
--
-- For @StartStep@ and @Resume@ signal types, you must send the name of the
-- Automation step to start or resume as the payload. For example:
--
-- @StepName=\"step1\"@
--
-- For the @StopStep@ signal type, you must send the step execution ID as
-- the payload. For example:
--
-- @StepExecutionId=\"97fff367-fc5a-4299-aed8-0123456789ab\"@
--
-- 'automationExecutionId', 'sendAutomationSignal_automationExecutionId' - The unique identifier for an existing Automation execution that you want
-- to send the signal to.
--
-- 'signalType', 'sendAutomationSignal_signalType' - The type of signal to send to an Automation execution.
newSendAutomationSignal ::
  -- | 'automationExecutionId'
  Prelude.Text ->
  -- | 'signalType'
  SignalType ->
  SendAutomationSignal
newSendAutomationSignal :: Text -> SignalType -> SendAutomationSignal
newSendAutomationSignal
  Text
pAutomationExecutionId_
  SignalType
pSignalType_ =
    SendAutomationSignal' :: Maybe (HashMap Text [Text])
-> Text -> SignalType -> SendAutomationSignal
SendAutomationSignal'
      { $sel:payload:SendAutomationSignal' :: Maybe (HashMap Text [Text])
payload = Maybe (HashMap Text [Text])
forall a. Maybe a
Prelude.Nothing,
        $sel:automationExecutionId:SendAutomationSignal' :: Text
automationExecutionId = Text
pAutomationExecutionId_,
        $sel:signalType:SendAutomationSignal' :: SignalType
signalType = SignalType
pSignalType_
      }

-- | The data sent with the signal. The data schema depends on the type of
-- signal used in the request.
--
-- For @Approve@ and @Reject@ signal types, the payload is an optional
-- comment that you can send with the signal type. For example:
--
-- @Comment=\"Looks good\"@
--
-- For @StartStep@ and @Resume@ signal types, you must send the name of the
-- Automation step to start or resume as the payload. For example:
--
-- @StepName=\"step1\"@
--
-- For the @StopStep@ signal type, you must send the step execution ID as
-- the payload. For example:
--
-- @StepExecutionId=\"97fff367-fc5a-4299-aed8-0123456789ab\"@
sendAutomationSignal_payload :: Lens.Lens' SendAutomationSignal (Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]))
sendAutomationSignal_payload :: (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> SendAutomationSignal -> f SendAutomationSignal
sendAutomationSignal_payload = (SendAutomationSignal -> Maybe (HashMap Text [Text]))
-> (SendAutomationSignal
    -> Maybe (HashMap Text [Text]) -> SendAutomationSignal)
-> Lens
     SendAutomationSignal
     SendAutomationSignal
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendAutomationSignal' {Maybe (HashMap Text [Text])
payload :: Maybe (HashMap Text [Text])
$sel:payload:SendAutomationSignal' :: SendAutomationSignal -> Maybe (HashMap Text [Text])
payload} -> Maybe (HashMap Text [Text])
payload) (\s :: SendAutomationSignal
s@SendAutomationSignal' {} Maybe (HashMap Text [Text])
a -> SendAutomationSignal
s {$sel:payload:SendAutomationSignal' :: Maybe (HashMap Text [Text])
payload = Maybe (HashMap Text [Text])
a} :: SendAutomationSignal) ((Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
 -> SendAutomationSignal -> f SendAutomationSignal)
-> ((Maybe (HashMap Text [Text])
     -> f (Maybe (HashMap Text [Text])))
    -> Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> SendAutomationSignal
-> f SendAutomationSignal
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
-> Iso
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The unique identifier for an existing Automation execution that you want
-- to send the signal to.
sendAutomationSignal_automationExecutionId :: Lens.Lens' SendAutomationSignal Prelude.Text
sendAutomationSignal_automationExecutionId :: (Text -> f Text) -> SendAutomationSignal -> f SendAutomationSignal
sendAutomationSignal_automationExecutionId = (SendAutomationSignal -> Text)
-> (SendAutomationSignal -> Text -> SendAutomationSignal)
-> Lens SendAutomationSignal SendAutomationSignal Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendAutomationSignal' {Text
automationExecutionId :: Text
$sel:automationExecutionId:SendAutomationSignal' :: SendAutomationSignal -> Text
automationExecutionId} -> Text
automationExecutionId) (\s :: SendAutomationSignal
s@SendAutomationSignal' {} Text
a -> SendAutomationSignal
s {$sel:automationExecutionId:SendAutomationSignal' :: Text
automationExecutionId = Text
a} :: SendAutomationSignal)

-- | The type of signal to send to an Automation execution.
sendAutomationSignal_signalType :: Lens.Lens' SendAutomationSignal SignalType
sendAutomationSignal_signalType :: (SignalType -> f SignalType)
-> SendAutomationSignal -> f SendAutomationSignal
sendAutomationSignal_signalType = (SendAutomationSignal -> SignalType)
-> (SendAutomationSignal -> SignalType -> SendAutomationSignal)
-> Lens
     SendAutomationSignal SendAutomationSignal SignalType SignalType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendAutomationSignal' {SignalType
signalType :: SignalType
$sel:signalType:SendAutomationSignal' :: SendAutomationSignal -> SignalType
signalType} -> SignalType
signalType) (\s :: SendAutomationSignal
s@SendAutomationSignal' {} SignalType
a -> SendAutomationSignal
s {$sel:signalType:SendAutomationSignal' :: SignalType
signalType = SignalType
a} :: SendAutomationSignal)

instance Core.AWSRequest SendAutomationSignal where
  type
    AWSResponse SendAutomationSignal =
      SendAutomationSignalResponse
  request :: SendAutomationSignal -> Request SendAutomationSignal
request = Service -> SendAutomationSignal -> Request SendAutomationSignal
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SendAutomationSignal
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SendAutomationSignal)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse SendAutomationSignal))
-> Logger
-> Service
-> Proxy SendAutomationSignal
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SendAutomationSignal)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> SendAutomationSignalResponse
SendAutomationSignalResponse'
            (Int -> SendAutomationSignalResponse)
-> Either String Int -> Either String SendAutomationSignalResponse
forall (f :: * -> *) a b. Functor 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 SendAutomationSignal

instance Prelude.NFData SendAutomationSignal

instance Core.ToHeaders SendAutomationSignal where
  toHeaders :: SendAutomationSignal -> ResponseHeaders
toHeaders =
    ResponseHeaders -> SendAutomationSignal -> 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
"AmazonSSM.SendAutomationSignal" ::
                          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 SendAutomationSignal where
  toJSON :: SendAutomationSignal -> Value
toJSON SendAutomationSignal' {Maybe (HashMap Text [Text])
Text
SignalType
signalType :: SignalType
automationExecutionId :: Text
payload :: Maybe (HashMap Text [Text])
$sel:signalType:SendAutomationSignal' :: SendAutomationSignal -> SignalType
$sel:automationExecutionId:SendAutomationSignal' :: SendAutomationSignal -> Text
$sel:payload:SendAutomationSignal' :: SendAutomationSignal -> Maybe (HashMap Text [Text])
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Payload" Text -> HashMap Text [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text [Text] -> Pair)
-> Maybe (HashMap Text [Text]) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text [Text])
payload,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"AutomationExecutionId"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
automationExecutionId
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"SignalType" Text -> SignalType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SignalType
signalType)
          ]
      )

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

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

-- | /See:/ 'newSendAutomationSignalResponse' smart constructor.
data SendAutomationSignalResponse = SendAutomationSignalResponse'
  { -- | The response's http status code.
    SendAutomationSignalResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SendAutomationSignalResponse
-> SendAutomationSignalResponse -> Bool
(SendAutomationSignalResponse
 -> SendAutomationSignalResponse -> Bool)
-> (SendAutomationSignalResponse
    -> SendAutomationSignalResponse -> Bool)
-> Eq SendAutomationSignalResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendAutomationSignalResponse
-> SendAutomationSignalResponse -> Bool
$c/= :: SendAutomationSignalResponse
-> SendAutomationSignalResponse -> Bool
== :: SendAutomationSignalResponse
-> SendAutomationSignalResponse -> Bool
$c== :: SendAutomationSignalResponse
-> SendAutomationSignalResponse -> Bool
Prelude.Eq, ReadPrec [SendAutomationSignalResponse]
ReadPrec SendAutomationSignalResponse
Int -> ReadS SendAutomationSignalResponse
ReadS [SendAutomationSignalResponse]
(Int -> ReadS SendAutomationSignalResponse)
-> ReadS [SendAutomationSignalResponse]
-> ReadPrec SendAutomationSignalResponse
-> ReadPrec [SendAutomationSignalResponse]
-> Read SendAutomationSignalResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendAutomationSignalResponse]
$creadListPrec :: ReadPrec [SendAutomationSignalResponse]
readPrec :: ReadPrec SendAutomationSignalResponse
$creadPrec :: ReadPrec SendAutomationSignalResponse
readList :: ReadS [SendAutomationSignalResponse]
$creadList :: ReadS [SendAutomationSignalResponse]
readsPrec :: Int -> ReadS SendAutomationSignalResponse
$creadsPrec :: Int -> ReadS SendAutomationSignalResponse
Prelude.Read, Int -> SendAutomationSignalResponse -> ShowS
[SendAutomationSignalResponse] -> ShowS
SendAutomationSignalResponse -> String
(Int -> SendAutomationSignalResponse -> ShowS)
-> (SendAutomationSignalResponse -> String)
-> ([SendAutomationSignalResponse] -> ShowS)
-> Show SendAutomationSignalResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendAutomationSignalResponse] -> ShowS
$cshowList :: [SendAutomationSignalResponse] -> ShowS
show :: SendAutomationSignalResponse -> String
$cshow :: SendAutomationSignalResponse -> String
showsPrec :: Int -> SendAutomationSignalResponse -> ShowS
$cshowsPrec :: Int -> SendAutomationSignalResponse -> ShowS
Prelude.Show, (forall x.
 SendAutomationSignalResponse -> Rep SendAutomationSignalResponse x)
-> (forall x.
    Rep SendAutomationSignalResponse x -> SendAutomationSignalResponse)
-> Generic SendAutomationSignalResponse
forall x.
Rep SendAutomationSignalResponse x -> SendAutomationSignalResponse
forall x.
SendAutomationSignalResponse -> Rep SendAutomationSignalResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SendAutomationSignalResponse x -> SendAutomationSignalResponse
$cfrom :: forall x.
SendAutomationSignalResponse -> Rep SendAutomationSignalResponse x
Prelude.Generic)

-- |
-- Create a value of 'SendAutomationSignalResponse' 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', 'sendAutomationSignalResponse_httpStatus' - The response's http status code.
newSendAutomationSignalResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SendAutomationSignalResponse
newSendAutomationSignalResponse :: Int -> SendAutomationSignalResponse
newSendAutomationSignalResponse Int
pHttpStatus_ =
  SendAutomationSignalResponse' :: Int -> SendAutomationSignalResponse
SendAutomationSignalResponse'
    { $sel:httpStatus:SendAutomationSignalResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData SendAutomationSignalResponse