{-# 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.IoT.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.IoT.Types.IotEventsAction 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

-- | Sends an input to an IoT Events detector.
--
-- /See:/ 'newIotEventsAction' smart constructor.
data IotEventsAction = IotEventsAction'
  { -- | Whether to process the event actions as a batch. The default value is
    -- @false@.
    --
    -- When @batchMode@ is @true@, you can\'t specify a @messageId@.
    --
    -- When @batchMode@ is @true@ and the rule SQL statement evaluates to an
    -- Array, each Array element is treated as a separate message when it\'s
    -- sent to IoT Events by calling
    -- <https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_BatchPutMessage.html BatchPutMessage>
    -- . The resulting array can\'t have more than 10 messages.
    IotEventsAction -> Maybe Bool
batchMode :: Prelude.Maybe Prelude.Bool,
    -- | The ID of the message. The default @messageId@ is a new UUID value.
    --
    -- When @batchMode@ is @true@, you can\'t specify a @messageId@--a new UUID
    -- value will be assigned.
    --
    -- Assign a value to this property to ensure that only one input (message)
    -- with a given @messageId@ will be processed by an IoT Events detector.
    IotEventsAction -> Maybe Text
messageId :: Prelude.Maybe Prelude.Text,
    -- | The name of the IoT Events input.
    IotEventsAction -> Text
inputName :: Prelude.Text,
    -- | The ARN of the role that grants IoT permission to send an input to an
    -- IoT Events detector. (\"Action\":\"iotevents:BatchPutMessage\").
    IotEventsAction -> Text
roleArn :: 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:
--
-- 'batchMode', 'iotEventsAction_batchMode' - Whether to process the event actions as a batch. The default value is
-- @false@.
--
-- When @batchMode@ is @true@, you can\'t specify a @messageId@.
--
-- When @batchMode@ is @true@ and the rule SQL statement evaluates to an
-- Array, each Array element is treated as a separate message when it\'s
-- sent to IoT Events by calling
-- <https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_BatchPutMessage.html BatchPutMessage>
-- . The resulting array can\'t have more than 10 messages.
--
-- 'messageId', 'iotEventsAction_messageId' - The ID of the message. The default @messageId@ is a new UUID value.
--
-- When @batchMode@ is @true@, you can\'t specify a @messageId@--a new UUID
-- value will be assigned.
--
-- Assign a value to this property to ensure that only one input (message)
-- with a given @messageId@ will be processed by an IoT Events detector.
--
-- 'inputName', 'iotEventsAction_inputName' - The name of the IoT Events input.
--
-- 'roleArn', 'iotEventsAction_roleArn' - The ARN of the role that grants IoT permission to send an input to an
-- IoT Events detector. (\"Action\":\"iotevents:BatchPutMessage\").
newIotEventsAction ::
  -- | 'inputName'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  IotEventsAction
newIotEventsAction :: Text -> Text -> IotEventsAction
newIotEventsAction Text
pInputName_ Text
pRoleArn_ =
  IotEventsAction'
    { $sel:batchMode:IotEventsAction' :: Maybe Bool
batchMode = forall a. Maybe a
Prelude.Nothing,
      $sel:messageId:IotEventsAction' :: Maybe Text
messageId = forall a. Maybe a
Prelude.Nothing,
      $sel:inputName:IotEventsAction' :: Text
inputName = Text
pInputName_,
      $sel:roleArn:IotEventsAction' :: Text
roleArn = Text
pRoleArn_
    }

-- | Whether to process the event actions as a batch. The default value is
-- @false@.
--
-- When @batchMode@ is @true@, you can\'t specify a @messageId@.
--
-- When @batchMode@ is @true@ and the rule SQL statement evaluates to an
-- Array, each Array element is treated as a separate message when it\'s
-- sent to IoT Events by calling
-- <https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_BatchPutMessage.html BatchPutMessage>
-- . The resulting array can\'t have more than 10 messages.
iotEventsAction_batchMode :: Lens.Lens' IotEventsAction (Prelude.Maybe Prelude.Bool)
iotEventsAction_batchMode :: Lens' IotEventsAction (Maybe Bool)
iotEventsAction_batchMode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotEventsAction' {Maybe Bool
batchMode :: Maybe Bool
$sel:batchMode:IotEventsAction' :: IotEventsAction -> Maybe Bool
batchMode} -> Maybe Bool
batchMode) (\s :: IotEventsAction
s@IotEventsAction' {} Maybe Bool
a -> IotEventsAction
s {$sel:batchMode:IotEventsAction' :: Maybe Bool
batchMode = Maybe Bool
a} :: IotEventsAction)

-- | The ID of the message. The default @messageId@ is a new UUID value.
--
-- When @batchMode@ is @true@, you can\'t specify a @messageId@--a new UUID
-- value will be assigned.
--
-- Assign a value to this property to ensure that only one input (message)
-- with a given @messageId@ will be processed by an IoT Events detector.
iotEventsAction_messageId :: Lens.Lens' IotEventsAction (Prelude.Maybe Prelude.Text)
iotEventsAction_messageId :: Lens' IotEventsAction (Maybe Text)
iotEventsAction_messageId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotEventsAction' {Maybe Text
messageId :: Maybe Text
$sel:messageId:IotEventsAction' :: IotEventsAction -> Maybe Text
messageId} -> Maybe Text
messageId) (\s :: IotEventsAction
s@IotEventsAction' {} Maybe Text
a -> IotEventsAction
s {$sel:messageId:IotEventsAction' :: Maybe Text
messageId = Maybe Text
a} :: IotEventsAction)

-- | The name of the IoT Events input.
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)

-- | The ARN of the role that grants IoT permission to send an input to an
-- IoT Events detector. (\"Action\":\"iotevents:BatchPutMessage\").
iotEventsAction_roleArn :: Lens.Lens' IotEventsAction Prelude.Text
iotEventsAction_roleArn :: Lens' IotEventsAction Text
iotEventsAction_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotEventsAction' {Text
roleArn :: Text
$sel:roleArn:IotEventsAction' :: IotEventsAction -> Text
roleArn} -> Text
roleArn) (\s :: IotEventsAction
s@IotEventsAction' {} Text
a -> IotEventsAction
s {$sel:roleArn:IotEventsAction' :: Text
roleArn = 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 Bool -> Maybe Text -> Text -> 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
"batchMode")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"messageId")
            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")
            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
"roleArn")
      )

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

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

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