{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
      { $sel:payload:SendAutomationSignal' :: Maybe (HashMap Text [Text])
payload = 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 :: Lens' SendAutomationSignal (Maybe (HashMap Text [Text]))
sendAutomationSignal_payload = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' SendAutomationSignal Text
sendAutomationSignal_automationExecutionId = 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 :: Lens' SendAutomationSignal SignalType
sendAutomationSignal_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 :: (Service -> Service)
-> SendAutomationSignal -> Request SendAutomationSignal
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy SendAutomationSignal
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SendAutomationSignal)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> SendAutomationSignalResponse
SendAutomationSignalResponse'
            forall (f :: * -> *) a b. Functor 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 SendAutomationSignal where
  hashWithSalt :: Int -> SendAutomationSignal -> Int
hashWithSalt Int
_salt 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])
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text [Text])
payload
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
automationExecutionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SignalType
signalType

instance Prelude.NFData SendAutomationSignal where
  rnf :: SendAutomationSignal -> ()
rnf 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])
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text [Text])
payload
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
automationExecutionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SignalType
signalType

instance Data.ToHeaders SendAutomationSignal where
  toHeaders :: SendAutomationSignal -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AmazonSSM.SendAutomationSignal" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Payload" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text [Text])
payload,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"AutomationExecutionId"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
automationExecutionId
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"SignalType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SignalType
signalType)
          ]
      )

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

instance Data.ToQuery SendAutomationSignal where
  toQuery :: SendAutomationSignal -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:httpStatus:SendAutomationSignalResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
sendAutomationSignalResponse_httpStatus :: Lens.Lens' SendAutomationSignalResponse Prelude.Int
sendAutomationSignalResponse_httpStatus :: Lens' SendAutomationSignalResponse Int
sendAutomationSignalResponse_httpStatus = 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 where
  rnf :: SendAutomationSignalResponse -> ()
rnf SendAutomationSignalResponse' {Int
httpStatus :: Int
$sel:httpStatus:SendAutomationSignalResponse' :: SendAutomationSignalResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus