{-# 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-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)
module Amazonka.IoT.Types.IotEventsAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(IotEventsAction -> IotEventsAction -> Bool)
-> (IotEventsAction -> IotEventsAction -> Bool)
-> Eq IotEventsAction
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]
(Int -> ReadS IotEventsAction)
-> ReadS [IotEventsAction]
-> ReadPrec IotEventsAction
-> ReadPrec [IotEventsAction]
-> Read 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
(Int -> IotEventsAction -> ShowS)
-> (IotEventsAction -> String)
-> ([IotEventsAction] -> ShowS)
-> Show IotEventsAction
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. IotEventsAction -> Rep IotEventsAction x)
-> (forall x. Rep IotEventsAction x -> IotEventsAction)
-> Generic IotEventsAction
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' :: Maybe Bool -> Maybe Text -> Text -> Text -> IotEventsAction
IotEventsAction'
    { $sel:batchMode:IotEventsAction' :: Maybe Bool
batchMode = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:messageId:IotEventsAction' :: Maybe Text
messageId = Maybe Text
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 :: (Maybe Bool -> f (Maybe Bool))
-> IotEventsAction -> f IotEventsAction
iotEventsAction_batchMode = (IotEventsAction -> Maybe Bool)
-> (IotEventsAction -> Maybe Bool -> IotEventsAction)
-> Lens IotEventsAction IotEventsAction (Maybe Bool) (Maybe Bool)
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 :: (Maybe Text -> f (Maybe Text))
-> IotEventsAction -> f IotEventsAction
iotEventsAction_messageId = (IotEventsAction -> Maybe Text)
-> (IotEventsAction -> Maybe Text -> IotEventsAction)
-> Lens IotEventsAction IotEventsAction (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> IotEventsAction -> f IotEventsAction
iotEventsAction_inputName = (IotEventsAction -> Text)
-> (IotEventsAction -> Text -> IotEventsAction)
-> Lens IotEventsAction IotEventsAction Text Text
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 :: (Text -> f Text) -> IotEventsAction -> f IotEventsAction
iotEventsAction_roleArn = (IotEventsAction -> Text)
-> (IotEventsAction -> Text -> IotEventsAction)
-> Lens IotEventsAction IotEventsAction Text Text
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 Core.FromJSON IotEventsAction where
  parseJSON :: Value -> Parser IotEventsAction
parseJSON =
    String
-> (Object -> Parser IotEventsAction)
-> Value
-> Parser IotEventsAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IotEventsAction"
      ( \Object
x ->
          Maybe Bool -> Maybe Text -> Text -> Text -> IotEventsAction
IotEventsAction'
            (Maybe Bool -> Maybe Text -> Text -> Text -> IotEventsAction)
-> Parser (Maybe Bool)
-> Parser (Maybe Text -> Text -> Text -> IotEventsAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"batchMode")
            Parser (Maybe Text -> Text -> Text -> IotEventsAction)
-> Parser (Maybe Text) -> Parser (Text -> Text -> IotEventsAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"messageId")
            Parser (Text -> Text -> IotEventsAction)
-> Parser Text -> Parser (Text -> IotEventsAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"inputName")
            Parser (Text -> IotEventsAction)
-> Parser Text -> Parser IotEventsAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"roleArn")
      )

instance Prelude.Hashable IotEventsAction

instance Prelude.NFData IotEventsAction

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"batchMode" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
batchMode,
            (Text
"messageId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
messageId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"inputName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
inputName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )