{-# 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.IotAnalyticsAction
-- 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.IotAnalyticsAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Sends message data to an IoT Analytics channel.
--
-- /See:/ 'newIotAnalyticsAction' smart constructor.
data IotAnalyticsAction = IotAnalyticsAction'
  { -- | Whether to process the action as a batch. The default value is @false@.
    --
    -- When @batchMode@ is @true@ and the rule SQL statement evaluates to an
    -- Array, each Array element is delivered as a separate message when passed
    -- by
    -- <https://docs.aws.amazon.com/iotanalytics/latest/APIReference/API_BatchPutMessage.html BatchPutMessage>
    -- to the IoT Analytics channel. The resulting array can\'t have more than
    -- 100 messages.
    IotAnalyticsAction -> Maybe Bool
batchMode :: Prelude.Maybe Prelude.Bool,
    -- | (deprecated) The ARN of the IoT Analytics channel to which message data
    -- will be sent.
    IotAnalyticsAction -> Maybe Text
channelArn :: Prelude.Maybe Prelude.Text,
    -- | The name of the IoT Analytics channel to which message data will be
    -- sent.
    IotAnalyticsAction -> Maybe Text
channelName :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the role which has a policy that grants IoT Analytics
    -- permission to send message data via IoT Analytics
    -- (iotanalytics:BatchPutMessage).
    IotAnalyticsAction -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text
  }
  deriving (IotAnalyticsAction -> IotAnalyticsAction -> Bool
(IotAnalyticsAction -> IotAnalyticsAction -> Bool)
-> (IotAnalyticsAction -> IotAnalyticsAction -> Bool)
-> Eq IotAnalyticsAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IotAnalyticsAction -> IotAnalyticsAction -> Bool
$c/= :: IotAnalyticsAction -> IotAnalyticsAction -> Bool
== :: IotAnalyticsAction -> IotAnalyticsAction -> Bool
$c== :: IotAnalyticsAction -> IotAnalyticsAction -> Bool
Prelude.Eq, ReadPrec [IotAnalyticsAction]
ReadPrec IotAnalyticsAction
Int -> ReadS IotAnalyticsAction
ReadS [IotAnalyticsAction]
(Int -> ReadS IotAnalyticsAction)
-> ReadS [IotAnalyticsAction]
-> ReadPrec IotAnalyticsAction
-> ReadPrec [IotAnalyticsAction]
-> Read IotAnalyticsAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IotAnalyticsAction]
$creadListPrec :: ReadPrec [IotAnalyticsAction]
readPrec :: ReadPrec IotAnalyticsAction
$creadPrec :: ReadPrec IotAnalyticsAction
readList :: ReadS [IotAnalyticsAction]
$creadList :: ReadS [IotAnalyticsAction]
readsPrec :: Int -> ReadS IotAnalyticsAction
$creadsPrec :: Int -> ReadS IotAnalyticsAction
Prelude.Read, Int -> IotAnalyticsAction -> ShowS
[IotAnalyticsAction] -> ShowS
IotAnalyticsAction -> String
(Int -> IotAnalyticsAction -> ShowS)
-> (IotAnalyticsAction -> String)
-> ([IotAnalyticsAction] -> ShowS)
-> Show IotAnalyticsAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IotAnalyticsAction] -> ShowS
$cshowList :: [IotAnalyticsAction] -> ShowS
show :: IotAnalyticsAction -> String
$cshow :: IotAnalyticsAction -> String
showsPrec :: Int -> IotAnalyticsAction -> ShowS
$cshowsPrec :: Int -> IotAnalyticsAction -> ShowS
Prelude.Show, (forall x. IotAnalyticsAction -> Rep IotAnalyticsAction x)
-> (forall x. Rep IotAnalyticsAction x -> IotAnalyticsAction)
-> Generic IotAnalyticsAction
forall x. Rep IotAnalyticsAction x -> IotAnalyticsAction
forall x. IotAnalyticsAction -> Rep IotAnalyticsAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IotAnalyticsAction x -> IotAnalyticsAction
$cfrom :: forall x. IotAnalyticsAction -> Rep IotAnalyticsAction x
Prelude.Generic)

-- |
-- Create a value of 'IotAnalyticsAction' 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', 'iotAnalyticsAction_batchMode' - Whether to process the action as a batch. The default value is @false@.
--
-- When @batchMode@ is @true@ and the rule SQL statement evaluates to an
-- Array, each Array element is delivered as a separate message when passed
-- by
-- <https://docs.aws.amazon.com/iotanalytics/latest/APIReference/API_BatchPutMessage.html BatchPutMessage>
-- to the IoT Analytics channel. The resulting array can\'t have more than
-- 100 messages.
--
-- 'channelArn', 'iotAnalyticsAction_channelArn' - (deprecated) The ARN of the IoT Analytics channel to which message data
-- will be sent.
--
-- 'channelName', 'iotAnalyticsAction_channelName' - The name of the IoT Analytics channel to which message data will be
-- sent.
--
-- 'roleArn', 'iotAnalyticsAction_roleArn' - The ARN of the role which has a policy that grants IoT Analytics
-- permission to send message data via IoT Analytics
-- (iotanalytics:BatchPutMessage).
newIotAnalyticsAction ::
  IotAnalyticsAction
newIotAnalyticsAction :: IotAnalyticsAction
newIotAnalyticsAction =
  IotAnalyticsAction' :: Maybe Bool
-> Maybe Text -> Maybe Text -> Maybe Text -> IotAnalyticsAction
IotAnalyticsAction'
    { $sel:batchMode:IotAnalyticsAction' :: Maybe Bool
batchMode = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:channelArn:IotAnalyticsAction' :: Maybe Text
channelArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:channelName:IotAnalyticsAction' :: Maybe Text
channelName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:IotAnalyticsAction' :: Maybe Text
roleArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Whether to process the action as a batch. The default value is @false@.
--
-- When @batchMode@ is @true@ and the rule SQL statement evaluates to an
-- Array, each Array element is delivered as a separate message when passed
-- by
-- <https://docs.aws.amazon.com/iotanalytics/latest/APIReference/API_BatchPutMessage.html BatchPutMessage>
-- to the IoT Analytics channel. The resulting array can\'t have more than
-- 100 messages.
iotAnalyticsAction_batchMode :: Lens.Lens' IotAnalyticsAction (Prelude.Maybe Prelude.Bool)
iotAnalyticsAction_batchMode :: (Maybe Bool -> f (Maybe Bool))
-> IotAnalyticsAction -> f IotAnalyticsAction
iotAnalyticsAction_batchMode = (IotAnalyticsAction -> Maybe Bool)
-> (IotAnalyticsAction -> Maybe Bool -> IotAnalyticsAction)
-> Lens
     IotAnalyticsAction IotAnalyticsAction (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotAnalyticsAction' {Maybe Bool
batchMode :: Maybe Bool
$sel:batchMode:IotAnalyticsAction' :: IotAnalyticsAction -> Maybe Bool
batchMode} -> Maybe Bool
batchMode) (\s :: IotAnalyticsAction
s@IotAnalyticsAction' {} Maybe Bool
a -> IotAnalyticsAction
s {$sel:batchMode:IotAnalyticsAction' :: Maybe Bool
batchMode = Maybe Bool
a} :: IotAnalyticsAction)

-- | (deprecated) The ARN of the IoT Analytics channel to which message data
-- will be sent.
iotAnalyticsAction_channelArn :: Lens.Lens' IotAnalyticsAction (Prelude.Maybe Prelude.Text)
iotAnalyticsAction_channelArn :: (Maybe Text -> f (Maybe Text))
-> IotAnalyticsAction -> f IotAnalyticsAction
iotAnalyticsAction_channelArn = (IotAnalyticsAction -> Maybe Text)
-> (IotAnalyticsAction -> Maybe Text -> IotAnalyticsAction)
-> Lens
     IotAnalyticsAction IotAnalyticsAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotAnalyticsAction' {Maybe Text
channelArn :: Maybe Text
$sel:channelArn:IotAnalyticsAction' :: IotAnalyticsAction -> Maybe Text
channelArn} -> Maybe Text
channelArn) (\s :: IotAnalyticsAction
s@IotAnalyticsAction' {} Maybe Text
a -> IotAnalyticsAction
s {$sel:channelArn:IotAnalyticsAction' :: Maybe Text
channelArn = Maybe Text
a} :: IotAnalyticsAction)

-- | The name of the IoT Analytics channel to which message data will be
-- sent.
iotAnalyticsAction_channelName :: Lens.Lens' IotAnalyticsAction (Prelude.Maybe Prelude.Text)
iotAnalyticsAction_channelName :: (Maybe Text -> f (Maybe Text))
-> IotAnalyticsAction -> f IotAnalyticsAction
iotAnalyticsAction_channelName = (IotAnalyticsAction -> Maybe Text)
-> (IotAnalyticsAction -> Maybe Text -> IotAnalyticsAction)
-> Lens
     IotAnalyticsAction IotAnalyticsAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotAnalyticsAction' {Maybe Text
channelName :: Maybe Text
$sel:channelName:IotAnalyticsAction' :: IotAnalyticsAction -> Maybe Text
channelName} -> Maybe Text
channelName) (\s :: IotAnalyticsAction
s@IotAnalyticsAction' {} Maybe Text
a -> IotAnalyticsAction
s {$sel:channelName:IotAnalyticsAction' :: Maybe Text
channelName = Maybe Text
a} :: IotAnalyticsAction)

-- | The ARN of the role which has a policy that grants IoT Analytics
-- permission to send message data via IoT Analytics
-- (iotanalytics:BatchPutMessage).
iotAnalyticsAction_roleArn :: Lens.Lens' IotAnalyticsAction (Prelude.Maybe Prelude.Text)
iotAnalyticsAction_roleArn :: (Maybe Text -> f (Maybe Text))
-> IotAnalyticsAction -> f IotAnalyticsAction
iotAnalyticsAction_roleArn = (IotAnalyticsAction -> Maybe Text)
-> (IotAnalyticsAction -> Maybe Text -> IotAnalyticsAction)
-> Lens
     IotAnalyticsAction IotAnalyticsAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotAnalyticsAction' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:IotAnalyticsAction' :: IotAnalyticsAction -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: IotAnalyticsAction
s@IotAnalyticsAction' {} Maybe Text
a -> IotAnalyticsAction
s {$sel:roleArn:IotAnalyticsAction' :: Maybe Text
roleArn = Maybe Text
a} :: IotAnalyticsAction)

instance Core.FromJSON IotAnalyticsAction where
  parseJSON :: Value -> Parser IotAnalyticsAction
parseJSON =
    String
-> (Object -> Parser IotAnalyticsAction)
-> Value
-> Parser IotAnalyticsAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IotAnalyticsAction"
      ( \Object
x ->
          Maybe Bool
-> Maybe Text -> Maybe Text -> Maybe Text -> IotAnalyticsAction
IotAnalyticsAction'
            (Maybe Bool
 -> Maybe Text -> Maybe Text -> Maybe Text -> IotAnalyticsAction)
-> Parser (Maybe Bool)
-> Parser
     (Maybe Text -> Maybe Text -> Maybe Text -> IotAnalyticsAction)
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 -> Maybe Text -> Maybe Text -> IotAnalyticsAction)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> IotAnalyticsAction)
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
"channelArn")
            Parser (Maybe Text -> Maybe Text -> IotAnalyticsAction)
-> Parser (Maybe Text) -> Parser (Maybe Text -> IotAnalyticsAction)
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
"channelName")
            Parser (Maybe Text -> IotAnalyticsAction)
-> Parser (Maybe Text) -> Parser IotAnalyticsAction
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
"roleArn")
      )

instance Prelude.Hashable IotAnalyticsAction

instance Prelude.NFData IotAnalyticsAction

instance Core.ToJSON IotAnalyticsAction where
  toJSON :: IotAnalyticsAction -> Value
toJSON IotAnalyticsAction' {Maybe Bool
Maybe Text
roleArn :: Maybe Text
channelName :: Maybe Text
channelArn :: Maybe Text
batchMode :: Maybe Bool
$sel:roleArn:IotAnalyticsAction' :: IotAnalyticsAction -> Maybe Text
$sel:channelName:IotAnalyticsAction' :: IotAnalyticsAction -> Maybe Text
$sel:channelArn:IotAnalyticsAction' :: IotAnalyticsAction -> Maybe Text
$sel:batchMode:IotAnalyticsAction' :: IotAnalyticsAction -> 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
"channelArn" 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
channelArn,
            (Text
"channelName" 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
channelName,
            (Text
"roleArn" 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
roleArn
          ]
      )