{-# 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.LambdaAction
-- 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.IoTEvents.Types.LambdaAction where

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

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

-- |
-- Create a value of 'LambdaAction' 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', 'lambdaAction_payload' - You can configure the action payload when you send a message to a Lambda
-- function.
--
-- 'functionArn', 'lambdaAction_functionArn' - The ARN of the Lambda function that is executed.
newLambdaAction ::
  -- | 'functionArn'
  Prelude.Text ->
  LambdaAction
newLambdaAction :: Text -> LambdaAction
newLambdaAction Text
pFunctionArn_ =
  LambdaAction' :: Maybe Payload -> Text -> LambdaAction
LambdaAction'
    { $sel:payload:LambdaAction' :: Maybe Payload
payload = Maybe Payload
forall a. Maybe a
Prelude.Nothing,
      $sel:functionArn:LambdaAction' :: Text
functionArn = Text
pFunctionArn_
    }

-- | You can configure the action payload when you send a message to a Lambda
-- function.
lambdaAction_payload :: Lens.Lens' LambdaAction (Prelude.Maybe Payload)
lambdaAction_payload :: (Maybe Payload -> f (Maybe Payload))
-> LambdaAction -> f LambdaAction
lambdaAction_payload = (LambdaAction -> Maybe Payload)
-> (LambdaAction -> Maybe Payload -> LambdaAction)
-> Lens LambdaAction LambdaAction (Maybe Payload) (Maybe Payload)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaAction' {Maybe Payload
payload :: Maybe Payload
$sel:payload:LambdaAction' :: LambdaAction -> Maybe Payload
payload} -> Maybe Payload
payload) (\s :: LambdaAction
s@LambdaAction' {} Maybe Payload
a -> LambdaAction
s {$sel:payload:LambdaAction' :: Maybe Payload
payload = Maybe Payload
a} :: LambdaAction)

-- | The ARN of the Lambda function that is executed.
lambdaAction_functionArn :: Lens.Lens' LambdaAction Prelude.Text
lambdaAction_functionArn :: (Text -> f Text) -> LambdaAction -> f LambdaAction
lambdaAction_functionArn = (LambdaAction -> Text)
-> (LambdaAction -> Text -> LambdaAction)
-> Lens LambdaAction LambdaAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaAction' {Text
functionArn :: Text
$sel:functionArn:LambdaAction' :: LambdaAction -> Text
functionArn} -> Text
functionArn) (\s :: LambdaAction
s@LambdaAction' {} Text
a -> LambdaAction
s {$sel:functionArn:LambdaAction' :: Text
functionArn = Text
a} :: LambdaAction)

instance Core.FromJSON LambdaAction where
  parseJSON :: Value -> Parser LambdaAction
parseJSON =
    String
-> (Object -> Parser LambdaAction) -> Value -> Parser LambdaAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LambdaAction"
      ( \Object
x ->
          Maybe Payload -> Text -> LambdaAction
LambdaAction'
            (Maybe Payload -> Text -> LambdaAction)
-> Parser (Maybe Payload) -> Parser (Text -> LambdaAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Payload)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"payload")
            Parser (Text -> LambdaAction) -> Parser Text -> Parser LambdaAction
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
"functionArn")
      )

instance Prelude.Hashable LambdaAction

instance Prelude.NFData LambdaAction

instance Core.ToJSON LambdaAction where
  toJSON :: LambdaAction -> Value
toJSON LambdaAction' {Maybe Payload
Text
functionArn :: Text
payload :: Maybe Payload
$sel:functionArn:LambdaAction' :: LambdaAction -> Text
$sel:payload:LambdaAction' :: LambdaAction -> Maybe Payload
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"payload" Text -> Payload -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Payload -> Pair) -> Maybe Payload -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Payload
payload,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"functionArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
functionArn)
          ]
      )