{-# 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.GreengrassV2.Types.LambdaEventSource
-- 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.GreengrassV2.Types.LambdaEventSource where

import qualified Amazonka.Core as Core
import Amazonka.GreengrassV2.Types.LambdaEventSourceType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about an event source for an Lambda function. The
-- event source defines the topics on which this Lambda function subscribes
-- to receive messages that run the function.
--
-- /See:/ 'newLambdaEventSource' smart constructor.
data LambdaEventSource = LambdaEventSource'
  { -- | The topic to which to subscribe to receive event messages.
    LambdaEventSource -> Text
topic :: Prelude.Text,
    -- | The type of event source. Choose from the following options:
    --
    -- -   @PUB_SUB@ – Subscribe to local publish\/subscribe messages. This
    --     event source type doesn\'t support MQTT wildcards (@+@ and @#@) in
    --     the event source topic.
    --
    -- -   @IOT_CORE@ – Subscribe to Amazon Web Services IoT Core MQTT
    --     messages. This event source type supports MQTT wildcards (@+@ and
    --     @#@) in the event source topic.
    LambdaEventSource -> LambdaEventSourceType
type' :: LambdaEventSourceType
  }
  deriving (LambdaEventSource -> LambdaEventSource -> Bool
(LambdaEventSource -> LambdaEventSource -> Bool)
-> (LambdaEventSource -> LambdaEventSource -> Bool)
-> Eq LambdaEventSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LambdaEventSource -> LambdaEventSource -> Bool
$c/= :: LambdaEventSource -> LambdaEventSource -> Bool
== :: LambdaEventSource -> LambdaEventSource -> Bool
$c== :: LambdaEventSource -> LambdaEventSource -> Bool
Prelude.Eq, ReadPrec [LambdaEventSource]
ReadPrec LambdaEventSource
Int -> ReadS LambdaEventSource
ReadS [LambdaEventSource]
(Int -> ReadS LambdaEventSource)
-> ReadS [LambdaEventSource]
-> ReadPrec LambdaEventSource
-> ReadPrec [LambdaEventSource]
-> Read LambdaEventSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LambdaEventSource]
$creadListPrec :: ReadPrec [LambdaEventSource]
readPrec :: ReadPrec LambdaEventSource
$creadPrec :: ReadPrec LambdaEventSource
readList :: ReadS [LambdaEventSource]
$creadList :: ReadS [LambdaEventSource]
readsPrec :: Int -> ReadS LambdaEventSource
$creadsPrec :: Int -> ReadS LambdaEventSource
Prelude.Read, Int -> LambdaEventSource -> ShowS
[LambdaEventSource] -> ShowS
LambdaEventSource -> String
(Int -> LambdaEventSource -> ShowS)
-> (LambdaEventSource -> String)
-> ([LambdaEventSource] -> ShowS)
-> Show LambdaEventSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LambdaEventSource] -> ShowS
$cshowList :: [LambdaEventSource] -> ShowS
show :: LambdaEventSource -> String
$cshow :: LambdaEventSource -> String
showsPrec :: Int -> LambdaEventSource -> ShowS
$cshowsPrec :: Int -> LambdaEventSource -> ShowS
Prelude.Show, (forall x. LambdaEventSource -> Rep LambdaEventSource x)
-> (forall x. Rep LambdaEventSource x -> LambdaEventSource)
-> Generic LambdaEventSource
forall x. Rep LambdaEventSource x -> LambdaEventSource
forall x. LambdaEventSource -> Rep LambdaEventSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LambdaEventSource x -> LambdaEventSource
$cfrom :: forall x. LambdaEventSource -> Rep LambdaEventSource x
Prelude.Generic)

-- |
-- Create a value of 'LambdaEventSource' 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:
--
-- 'topic', 'lambdaEventSource_topic' - The topic to which to subscribe to receive event messages.
--
-- 'type'', 'lambdaEventSource_type' - The type of event source. Choose from the following options:
--
-- -   @PUB_SUB@ – Subscribe to local publish\/subscribe messages. This
--     event source type doesn\'t support MQTT wildcards (@+@ and @#@) in
--     the event source topic.
--
-- -   @IOT_CORE@ – Subscribe to Amazon Web Services IoT Core MQTT
--     messages. This event source type supports MQTT wildcards (@+@ and
--     @#@) in the event source topic.
newLambdaEventSource ::
  -- | 'topic'
  Prelude.Text ->
  -- | 'type''
  LambdaEventSourceType ->
  LambdaEventSource
newLambdaEventSource :: Text -> LambdaEventSourceType -> LambdaEventSource
newLambdaEventSource Text
pTopic_ LambdaEventSourceType
pType_ =
  LambdaEventSource' :: Text -> LambdaEventSourceType -> LambdaEventSource
LambdaEventSource' {$sel:topic:LambdaEventSource' :: Text
topic = Text
pTopic_, $sel:type':LambdaEventSource' :: LambdaEventSourceType
type' = LambdaEventSourceType
pType_}

-- | The topic to which to subscribe to receive event messages.
lambdaEventSource_topic :: Lens.Lens' LambdaEventSource Prelude.Text
lambdaEventSource_topic :: (Text -> f Text) -> LambdaEventSource -> f LambdaEventSource
lambdaEventSource_topic = (LambdaEventSource -> Text)
-> (LambdaEventSource -> Text -> LambdaEventSource)
-> Lens LambdaEventSource LambdaEventSource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaEventSource' {Text
topic :: Text
$sel:topic:LambdaEventSource' :: LambdaEventSource -> Text
topic} -> Text
topic) (\s :: LambdaEventSource
s@LambdaEventSource' {} Text
a -> LambdaEventSource
s {$sel:topic:LambdaEventSource' :: Text
topic = Text
a} :: LambdaEventSource)

-- | The type of event source. Choose from the following options:
--
-- -   @PUB_SUB@ – Subscribe to local publish\/subscribe messages. This
--     event source type doesn\'t support MQTT wildcards (@+@ and @#@) in
--     the event source topic.
--
-- -   @IOT_CORE@ – Subscribe to Amazon Web Services IoT Core MQTT
--     messages. This event source type supports MQTT wildcards (@+@ and
--     @#@) in the event source topic.
lambdaEventSource_type :: Lens.Lens' LambdaEventSource LambdaEventSourceType
lambdaEventSource_type :: (LambdaEventSourceType -> f LambdaEventSourceType)
-> LambdaEventSource -> f LambdaEventSource
lambdaEventSource_type = (LambdaEventSource -> LambdaEventSourceType)
-> (LambdaEventSource
    -> LambdaEventSourceType -> LambdaEventSource)
-> Lens
     LambdaEventSource
     LambdaEventSource
     LambdaEventSourceType
     LambdaEventSourceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaEventSource' {LambdaEventSourceType
type' :: LambdaEventSourceType
$sel:type':LambdaEventSource' :: LambdaEventSource -> LambdaEventSourceType
type'} -> LambdaEventSourceType
type') (\s :: LambdaEventSource
s@LambdaEventSource' {} LambdaEventSourceType
a -> LambdaEventSource
s {$sel:type':LambdaEventSource' :: LambdaEventSourceType
type' = LambdaEventSourceType
a} :: LambdaEventSource)

instance Prelude.Hashable LambdaEventSource

instance Prelude.NFData LambdaEventSource

instance Core.ToJSON LambdaEventSource where
  toJSON :: LambdaEventSource -> Value
toJSON LambdaEventSource' {Text
LambdaEventSourceType
type' :: LambdaEventSourceType
topic :: Text
$sel:type':LambdaEventSource' :: LambdaEventSource -> LambdaEventSourceType
$sel:topic:LambdaEventSource' :: LambdaEventSource -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"topic" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
topic),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> LambdaEventSourceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= LambdaEventSourceType
type')
          ]
      )