{-# 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.Snowball.Types.LambdaResource
-- 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.Snowball.Types.LambdaResource where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Snowball.Types.EventTriggerDefinition

-- | Identifies
--
-- /See:/ 'newLambdaResource' smart constructor.
data LambdaResource = LambdaResource'
  { -- | The array of ARNs for S3Resource objects to trigger the LambdaResource
    -- objects associated with this job.
    LambdaResource -> Maybe [EventTriggerDefinition]
eventTriggers :: Prelude.Maybe [EventTriggerDefinition],
    -- | An Amazon Resource Name (ARN) that represents an AWS Lambda function to
    -- be triggered by PUT object actions on the associated local Amazon S3
    -- resource.
    LambdaResource -> Maybe Text
lambdaArn :: Prelude.Maybe Prelude.Text
  }
  deriving (LambdaResource -> LambdaResource -> Bool
(LambdaResource -> LambdaResource -> Bool)
-> (LambdaResource -> LambdaResource -> Bool) -> Eq LambdaResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LambdaResource -> LambdaResource -> Bool
$c/= :: LambdaResource -> LambdaResource -> Bool
== :: LambdaResource -> LambdaResource -> Bool
$c== :: LambdaResource -> LambdaResource -> Bool
Prelude.Eq, ReadPrec [LambdaResource]
ReadPrec LambdaResource
Int -> ReadS LambdaResource
ReadS [LambdaResource]
(Int -> ReadS LambdaResource)
-> ReadS [LambdaResource]
-> ReadPrec LambdaResource
-> ReadPrec [LambdaResource]
-> Read LambdaResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LambdaResource]
$creadListPrec :: ReadPrec [LambdaResource]
readPrec :: ReadPrec LambdaResource
$creadPrec :: ReadPrec LambdaResource
readList :: ReadS [LambdaResource]
$creadList :: ReadS [LambdaResource]
readsPrec :: Int -> ReadS LambdaResource
$creadsPrec :: Int -> ReadS LambdaResource
Prelude.Read, Int -> LambdaResource -> ShowS
[LambdaResource] -> ShowS
LambdaResource -> String
(Int -> LambdaResource -> ShowS)
-> (LambdaResource -> String)
-> ([LambdaResource] -> ShowS)
-> Show LambdaResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LambdaResource] -> ShowS
$cshowList :: [LambdaResource] -> ShowS
show :: LambdaResource -> String
$cshow :: LambdaResource -> String
showsPrec :: Int -> LambdaResource -> ShowS
$cshowsPrec :: Int -> LambdaResource -> ShowS
Prelude.Show, (forall x. LambdaResource -> Rep LambdaResource x)
-> (forall x. Rep LambdaResource x -> LambdaResource)
-> Generic LambdaResource
forall x. Rep LambdaResource x -> LambdaResource
forall x. LambdaResource -> Rep LambdaResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LambdaResource x -> LambdaResource
$cfrom :: forall x. LambdaResource -> Rep LambdaResource x
Prelude.Generic)

-- |
-- Create a value of 'LambdaResource' 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:
--
-- 'eventTriggers', 'lambdaResource_eventTriggers' - The array of ARNs for S3Resource objects to trigger the LambdaResource
-- objects associated with this job.
--
-- 'lambdaArn', 'lambdaResource_lambdaArn' - An Amazon Resource Name (ARN) that represents an AWS Lambda function to
-- be triggered by PUT object actions on the associated local Amazon S3
-- resource.
newLambdaResource ::
  LambdaResource
newLambdaResource :: LambdaResource
newLambdaResource =
  LambdaResource' :: Maybe [EventTriggerDefinition] -> Maybe Text -> LambdaResource
LambdaResource'
    { $sel:eventTriggers:LambdaResource' :: Maybe [EventTriggerDefinition]
eventTriggers = Maybe [EventTriggerDefinition]
forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaArn:LambdaResource' :: Maybe Text
lambdaArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The array of ARNs for S3Resource objects to trigger the LambdaResource
-- objects associated with this job.
lambdaResource_eventTriggers :: Lens.Lens' LambdaResource (Prelude.Maybe [EventTriggerDefinition])
lambdaResource_eventTriggers :: (Maybe [EventTriggerDefinition]
 -> f (Maybe [EventTriggerDefinition]))
-> LambdaResource -> f LambdaResource
lambdaResource_eventTriggers = (LambdaResource -> Maybe [EventTriggerDefinition])
-> (LambdaResource
    -> Maybe [EventTriggerDefinition] -> LambdaResource)
-> Lens
     LambdaResource
     LambdaResource
     (Maybe [EventTriggerDefinition])
     (Maybe [EventTriggerDefinition])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaResource' {Maybe [EventTriggerDefinition]
eventTriggers :: Maybe [EventTriggerDefinition]
$sel:eventTriggers:LambdaResource' :: LambdaResource -> Maybe [EventTriggerDefinition]
eventTriggers} -> Maybe [EventTriggerDefinition]
eventTriggers) (\s :: LambdaResource
s@LambdaResource' {} Maybe [EventTriggerDefinition]
a -> LambdaResource
s {$sel:eventTriggers:LambdaResource' :: Maybe [EventTriggerDefinition]
eventTriggers = Maybe [EventTriggerDefinition]
a} :: LambdaResource) ((Maybe [EventTriggerDefinition]
  -> f (Maybe [EventTriggerDefinition]))
 -> LambdaResource -> f LambdaResource)
-> ((Maybe [EventTriggerDefinition]
     -> f (Maybe [EventTriggerDefinition]))
    -> Maybe [EventTriggerDefinition]
    -> f (Maybe [EventTriggerDefinition]))
-> (Maybe [EventTriggerDefinition]
    -> f (Maybe [EventTriggerDefinition]))
-> LambdaResource
-> f LambdaResource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [EventTriggerDefinition]
  [EventTriggerDefinition]
  [EventTriggerDefinition]
  [EventTriggerDefinition]
-> Iso
     (Maybe [EventTriggerDefinition])
     (Maybe [EventTriggerDefinition])
     (Maybe [EventTriggerDefinition])
     (Maybe [EventTriggerDefinition])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [EventTriggerDefinition]
  [EventTriggerDefinition]
  [EventTriggerDefinition]
  [EventTriggerDefinition]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An Amazon Resource Name (ARN) that represents an AWS Lambda function to
-- be triggered by PUT object actions on the associated local Amazon S3
-- resource.
lambdaResource_lambdaArn :: Lens.Lens' LambdaResource (Prelude.Maybe Prelude.Text)
lambdaResource_lambdaArn :: (Maybe Text -> f (Maybe Text))
-> LambdaResource -> f LambdaResource
lambdaResource_lambdaArn = (LambdaResource -> Maybe Text)
-> (LambdaResource -> Maybe Text -> LambdaResource)
-> Lens LambdaResource LambdaResource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaResource' {Maybe Text
lambdaArn :: Maybe Text
$sel:lambdaArn:LambdaResource' :: LambdaResource -> Maybe Text
lambdaArn} -> Maybe Text
lambdaArn) (\s :: LambdaResource
s@LambdaResource' {} Maybe Text
a -> LambdaResource
s {$sel:lambdaArn:LambdaResource' :: Maybe Text
lambdaArn = Maybe Text
a} :: LambdaResource)

instance Core.FromJSON LambdaResource where
  parseJSON :: Value -> Parser LambdaResource
parseJSON =
    String
-> (Object -> Parser LambdaResource)
-> Value
-> Parser LambdaResource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LambdaResource"
      ( \Object
x ->
          Maybe [EventTriggerDefinition] -> Maybe Text -> LambdaResource
LambdaResource'
            (Maybe [EventTriggerDefinition] -> Maybe Text -> LambdaResource)
-> Parser (Maybe [EventTriggerDefinition])
-> Parser (Maybe Text -> LambdaResource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [EventTriggerDefinition]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventTriggers" Parser (Maybe (Maybe [EventTriggerDefinition]))
-> Maybe [EventTriggerDefinition]
-> Parser (Maybe [EventTriggerDefinition])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [EventTriggerDefinition]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> LambdaResource)
-> Parser (Maybe Text) -> Parser LambdaResource
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
"LambdaArn")
      )

instance Prelude.Hashable LambdaResource

instance Prelude.NFData LambdaResource

instance Core.ToJSON LambdaResource where
  toJSON :: LambdaResource -> Value
toJSON LambdaResource' {Maybe [EventTriggerDefinition]
Maybe Text
lambdaArn :: Maybe Text
eventTriggers :: Maybe [EventTriggerDefinition]
$sel:lambdaArn:LambdaResource' :: LambdaResource -> Maybe Text
$sel:eventTriggers:LambdaResource' :: LambdaResource -> Maybe [EventTriggerDefinition]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EventTriggers" Text -> [EventTriggerDefinition] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([EventTriggerDefinition] -> Pair)
-> Maybe [EventTriggerDefinition] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [EventTriggerDefinition]
eventTriggers,
            (Text
"LambdaArn" 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
lambdaArn
          ]
      )