{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.IoTEvents.Types.IotEventsAction
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoTEvents.Types.IotEventsAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTEvents.Types.Payload
import qualified Amazonka.Prelude as Prelude

-- | Sends an AWS IoT Events input, passing in information about the detector
-- model instance and the event that triggered the action.
--
-- /See:/ 'newIotEventsAction' smart constructor.
data IotEventsAction = IotEventsAction'
  { -- | You can configure the action payload when you send a message to an AWS
    -- IoT Events input.
    IotEventsAction -> Maybe Payload
payload :: Prelude.Maybe Payload,
    -- | The name of the AWS IoT Events input where the data is sent.
    IotEventsAction -> Text
inputName :: Prelude.Text
  }
  deriving (IotEventsAction -> IotEventsAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IotEventsAction -> IotEventsAction -> Bool
$c/= :: IotEventsAction -> IotEventsAction -> Bool
== :: IotEventsAction -> IotEventsAction -> Bool
$c== :: IotEventsAction -> IotEventsAction -> Bool
Prelude.Eq, ReadPrec [IotEventsAction]
ReadPrec IotEventsAction
Int -> ReadS IotEventsAction
ReadS [IotEventsAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IotEventsAction]
$creadListPrec :: ReadPrec [IotEventsAction]
readPrec :: ReadPrec IotEventsAction
$creadPrec :: ReadPrec IotEventsAction
readList :: ReadS [IotEventsAction]
$creadList :: ReadS [IotEventsAction]
readsPrec :: Int -> ReadS IotEventsAction
$creadsPrec :: Int -> ReadS IotEventsAction
Prelude.Read, Int -> IotEventsAction -> ShowS
[IotEventsAction] -> ShowS
IotEventsAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IotEventsAction] -> ShowS
$cshowList :: [IotEventsAction] -> ShowS
show :: IotEventsAction -> String
$cshow :: IotEventsAction -> String
showsPrec :: Int -> IotEventsAction -> ShowS
$cshowsPrec :: Int -> IotEventsAction -> ShowS
Prelude.Show, forall x. Rep IotEventsAction x -> IotEventsAction
forall x. IotEventsAction -> Rep IotEventsAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IotEventsAction x -> IotEventsAction
$cfrom :: forall x. IotEventsAction -> Rep IotEventsAction x
Prelude.Generic)

-- |
-- Create a value of 'IotEventsAction' 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', 'iotEventsAction_payload' - You can configure the action payload when you send a message to an AWS
-- IoT Events input.
--
-- 'inputName', 'iotEventsAction_inputName' - The name of the AWS IoT Events input where the data is sent.
newIotEventsAction ::
  -- | 'inputName'
  Prelude.Text ->
  IotEventsAction
newIotEventsAction :: Text -> IotEventsAction
newIotEventsAction Text
pInputName_ =
  IotEventsAction'
    { $sel:payload:IotEventsAction' :: Maybe Payload
payload = forall a. Maybe a
Prelude.Nothing,
      $sel:inputName:IotEventsAction' :: Text
inputName = Text
pInputName_
    }

-- | You can configure the action payload when you send a message to an AWS
-- IoT Events input.
iotEventsAction_payload :: Lens.Lens' IotEventsAction (Prelude.Maybe Payload)
iotEventsAction_payload :: Lens' IotEventsAction (Maybe Payload)
iotEventsAction_payload = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotEventsAction' {Maybe Payload
payload :: Maybe Payload
$sel:payload:IotEventsAction' :: IotEventsAction -> Maybe Payload
payload} -> Maybe Payload
payload) (\s :: IotEventsAction
s@IotEventsAction' {} Maybe Payload
a -> IotEventsAction
s {$sel:payload:IotEventsAction' :: Maybe Payload
payload = Maybe Payload
a} :: IotEventsAction)

-- | The name of the AWS IoT Events input where the data is sent.
iotEventsAction_inputName :: Lens.Lens' IotEventsAction Prelude.Text
iotEventsAction_inputName :: Lens' IotEventsAction Text
iotEventsAction_inputName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotEventsAction' {Text
inputName :: Text
$sel:inputName:IotEventsAction' :: IotEventsAction -> Text
inputName} -> Text
inputName) (\s :: IotEventsAction
s@IotEventsAction' {} Text
a -> IotEventsAction
s {$sel:inputName:IotEventsAction' :: Text
inputName = Text
a} :: IotEventsAction)

instance Data.FromJSON IotEventsAction where
  parseJSON :: Value -> Parser IotEventsAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IotEventsAction"
      ( \Object
x ->
          Maybe Payload -> Text -> IotEventsAction
IotEventsAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"payload")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"inputName")
      )

instance Prelude.Hashable IotEventsAction where
  hashWithSalt :: Int -> IotEventsAction -> Int
hashWithSalt Int
_salt IotEventsAction' {Maybe Payload
Text
inputName :: Text
payload :: Maybe Payload
$sel:inputName:IotEventsAction' :: IotEventsAction -> Text
$sel:payload:IotEventsAction' :: IotEventsAction -> Maybe Payload
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Payload
payload
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
inputName

instance Prelude.NFData IotEventsAction where
  rnf :: IotEventsAction -> ()
rnf IotEventsAction' {Maybe Payload
Text
inputName :: Text
payload :: Maybe Payload
$sel:inputName:IotEventsAction' :: IotEventsAction -> Text
$sel:payload:IotEventsAction' :: IotEventsAction -> Maybe Payload
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Payload
payload
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
inputName

instance Data.ToJSON IotEventsAction where
  toJSON :: IotEventsAction -> Value
toJSON IotEventsAction' {Maybe Payload
Text
inputName :: Text
payload :: Maybe Payload
$sel:inputName:IotEventsAction' :: IotEventsAction -> Text
$sel:payload:IotEventsAction' :: IotEventsAction -> Maybe Payload
..} =
    [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 Payload
payload,
            forall a. a -> Maybe a
Prelude.Just (Key
"inputName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
inputName)
          ]
      )