{-# 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.IoTAnalytics.Types.LambdaActivity
-- 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.IoTAnalytics.Types.LambdaActivity where

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

-- | An activity that runs a Lambda function to modify the message.
--
-- /See:/ 'newLambdaActivity' smart constructor.
data LambdaActivity = LambdaActivity'
  { -- | The next activity in the pipeline.
    LambdaActivity -> Maybe Text
next :: Prelude.Maybe Prelude.Text,
    -- | The name of the lambda activity.
    LambdaActivity -> Text
name :: Prelude.Text,
    -- | The name of the Lambda function that is run on the message.
    LambdaActivity -> Text
lambdaName :: Prelude.Text,
    -- | The number of messages passed to the Lambda function for processing.
    --
    -- The Lambda function must be able to process all of these messages within
    -- five minutes, which is the maximum timeout duration for Lambda
    -- functions.
    LambdaActivity -> Natural
batchSize :: Prelude.Natural
  }
  deriving (LambdaActivity -> LambdaActivity -> Bool
(LambdaActivity -> LambdaActivity -> Bool)
-> (LambdaActivity -> LambdaActivity -> Bool) -> Eq LambdaActivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LambdaActivity -> LambdaActivity -> Bool
$c/= :: LambdaActivity -> LambdaActivity -> Bool
== :: LambdaActivity -> LambdaActivity -> Bool
$c== :: LambdaActivity -> LambdaActivity -> Bool
Prelude.Eq, ReadPrec [LambdaActivity]
ReadPrec LambdaActivity
Int -> ReadS LambdaActivity
ReadS [LambdaActivity]
(Int -> ReadS LambdaActivity)
-> ReadS [LambdaActivity]
-> ReadPrec LambdaActivity
-> ReadPrec [LambdaActivity]
-> Read LambdaActivity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LambdaActivity]
$creadListPrec :: ReadPrec [LambdaActivity]
readPrec :: ReadPrec LambdaActivity
$creadPrec :: ReadPrec LambdaActivity
readList :: ReadS [LambdaActivity]
$creadList :: ReadS [LambdaActivity]
readsPrec :: Int -> ReadS LambdaActivity
$creadsPrec :: Int -> ReadS LambdaActivity
Prelude.Read, Int -> LambdaActivity -> ShowS
[LambdaActivity] -> ShowS
LambdaActivity -> String
(Int -> LambdaActivity -> ShowS)
-> (LambdaActivity -> String)
-> ([LambdaActivity] -> ShowS)
-> Show LambdaActivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LambdaActivity] -> ShowS
$cshowList :: [LambdaActivity] -> ShowS
show :: LambdaActivity -> String
$cshow :: LambdaActivity -> String
showsPrec :: Int -> LambdaActivity -> ShowS
$cshowsPrec :: Int -> LambdaActivity -> ShowS
Prelude.Show, (forall x. LambdaActivity -> Rep LambdaActivity x)
-> (forall x. Rep LambdaActivity x -> LambdaActivity)
-> Generic LambdaActivity
forall x. Rep LambdaActivity x -> LambdaActivity
forall x. LambdaActivity -> Rep LambdaActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LambdaActivity x -> LambdaActivity
$cfrom :: forall x. LambdaActivity -> Rep LambdaActivity x
Prelude.Generic)

-- |
-- Create a value of 'LambdaActivity' 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:
--
-- 'next', 'lambdaActivity_next' - The next activity in the pipeline.
--
-- 'name', 'lambdaActivity_name' - The name of the lambda activity.
--
-- 'lambdaName', 'lambdaActivity_lambdaName' - The name of the Lambda function that is run on the message.
--
-- 'batchSize', 'lambdaActivity_batchSize' - The number of messages passed to the Lambda function for processing.
--
-- The Lambda function must be able to process all of these messages within
-- five minutes, which is the maximum timeout duration for Lambda
-- functions.
newLambdaActivity ::
  -- | 'name'
  Prelude.Text ->
  -- | 'lambdaName'
  Prelude.Text ->
  -- | 'batchSize'
  Prelude.Natural ->
  LambdaActivity
newLambdaActivity :: Text -> Text -> Natural -> LambdaActivity
newLambdaActivity Text
pName_ Text
pLambdaName_ Natural
pBatchSize_ =
  LambdaActivity' :: Maybe Text -> Text -> Text -> Natural -> LambdaActivity
LambdaActivity'
    { $sel:next:LambdaActivity' :: Maybe Text
next = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:LambdaActivity' :: Text
name = Text
pName_,
      $sel:lambdaName:LambdaActivity' :: Text
lambdaName = Text
pLambdaName_,
      $sel:batchSize:LambdaActivity' :: Natural
batchSize = Natural
pBatchSize_
    }

-- | The next activity in the pipeline.
lambdaActivity_next :: Lens.Lens' LambdaActivity (Prelude.Maybe Prelude.Text)
lambdaActivity_next :: (Maybe Text -> f (Maybe Text))
-> LambdaActivity -> f LambdaActivity
lambdaActivity_next = (LambdaActivity -> Maybe Text)
-> (LambdaActivity -> Maybe Text -> LambdaActivity)
-> Lens LambdaActivity LambdaActivity (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaActivity' {Maybe Text
next :: Maybe Text
$sel:next:LambdaActivity' :: LambdaActivity -> Maybe Text
next} -> Maybe Text
next) (\s :: LambdaActivity
s@LambdaActivity' {} Maybe Text
a -> LambdaActivity
s {$sel:next:LambdaActivity' :: Maybe Text
next = Maybe Text
a} :: LambdaActivity)

-- | The name of the lambda activity.
lambdaActivity_name :: Lens.Lens' LambdaActivity Prelude.Text
lambdaActivity_name :: (Text -> f Text) -> LambdaActivity -> f LambdaActivity
lambdaActivity_name = (LambdaActivity -> Text)
-> (LambdaActivity -> Text -> LambdaActivity)
-> Lens LambdaActivity LambdaActivity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaActivity' {Text
name :: Text
$sel:name:LambdaActivity' :: LambdaActivity -> Text
name} -> Text
name) (\s :: LambdaActivity
s@LambdaActivity' {} Text
a -> LambdaActivity
s {$sel:name:LambdaActivity' :: Text
name = Text
a} :: LambdaActivity)

-- | The name of the Lambda function that is run on the message.
lambdaActivity_lambdaName :: Lens.Lens' LambdaActivity Prelude.Text
lambdaActivity_lambdaName :: (Text -> f Text) -> LambdaActivity -> f LambdaActivity
lambdaActivity_lambdaName = (LambdaActivity -> Text)
-> (LambdaActivity -> Text -> LambdaActivity)
-> Lens LambdaActivity LambdaActivity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaActivity' {Text
lambdaName :: Text
$sel:lambdaName:LambdaActivity' :: LambdaActivity -> Text
lambdaName} -> Text
lambdaName) (\s :: LambdaActivity
s@LambdaActivity' {} Text
a -> LambdaActivity
s {$sel:lambdaName:LambdaActivity' :: Text
lambdaName = Text
a} :: LambdaActivity)

-- | The number of messages passed to the Lambda function for processing.
--
-- The Lambda function must be able to process all of these messages within
-- five minutes, which is the maximum timeout duration for Lambda
-- functions.
lambdaActivity_batchSize :: Lens.Lens' LambdaActivity Prelude.Natural
lambdaActivity_batchSize :: (Natural -> f Natural) -> LambdaActivity -> f LambdaActivity
lambdaActivity_batchSize = (LambdaActivity -> Natural)
-> (LambdaActivity -> Natural -> LambdaActivity)
-> Lens LambdaActivity LambdaActivity Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaActivity' {Natural
batchSize :: Natural
$sel:batchSize:LambdaActivity' :: LambdaActivity -> Natural
batchSize} -> Natural
batchSize) (\s :: LambdaActivity
s@LambdaActivity' {} Natural
a -> LambdaActivity
s {$sel:batchSize:LambdaActivity' :: Natural
batchSize = Natural
a} :: LambdaActivity)

instance Core.FromJSON LambdaActivity where
  parseJSON :: Value -> Parser LambdaActivity
parseJSON =
    String
-> (Object -> Parser LambdaActivity)
-> Value
-> Parser LambdaActivity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LambdaActivity"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> Natural -> LambdaActivity
LambdaActivity'
            (Maybe Text -> Text -> Text -> Natural -> LambdaActivity)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> Natural -> LambdaActivity)
forall (f :: * -> *) a b. Functor 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
"next")
            Parser (Text -> Text -> Natural -> LambdaActivity)
-> Parser Text -> Parser (Text -> Natural -> LambdaActivity)
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
"name")
            Parser (Text -> Natural -> LambdaActivity)
-> Parser Text -> Parser (Natural -> LambdaActivity)
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
"lambdaName")
            Parser (Natural -> LambdaActivity)
-> Parser Natural -> Parser LambdaActivity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"batchSize")
      )

instance Prelude.Hashable LambdaActivity

instance Prelude.NFData LambdaActivity

instance Core.ToJSON LambdaActivity where
  toJSON :: LambdaActivity -> Value
toJSON LambdaActivity' {Natural
Maybe Text
Text
batchSize :: Natural
lambdaName :: Text
name :: Text
next :: Maybe Text
$sel:batchSize:LambdaActivity' :: LambdaActivity -> Natural
$sel:lambdaName:LambdaActivity' :: LambdaActivity -> Text
$sel:name:LambdaActivity' :: LambdaActivity -> Text
$sel:next:LambdaActivity' :: LambdaActivity -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"next" 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
next,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"lambdaName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
lambdaName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"batchSize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
batchSize)
          ]
      )