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

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

-- | Structure that contains @payloadVersion@ and @targetArn@.
--
-- /See:/ 'newProvisioningHook' smart constructor.
data ProvisioningHook = ProvisioningHook'
  { -- | The payload that was sent to the target function.
    --
    -- /Note:/ Only Lambda functions are currently supported.
    ProvisioningHook -> Maybe Text
payloadVersion :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the target function.
    --
    -- /Note:/ Only Lambda functions are currently supported.
    ProvisioningHook -> Text
targetArn :: Prelude.Text
  }
  deriving (ProvisioningHook -> ProvisioningHook -> Bool
(ProvisioningHook -> ProvisioningHook -> Bool)
-> (ProvisioningHook -> ProvisioningHook -> Bool)
-> Eq ProvisioningHook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProvisioningHook -> ProvisioningHook -> Bool
$c/= :: ProvisioningHook -> ProvisioningHook -> Bool
== :: ProvisioningHook -> ProvisioningHook -> Bool
$c== :: ProvisioningHook -> ProvisioningHook -> Bool
Prelude.Eq, ReadPrec [ProvisioningHook]
ReadPrec ProvisioningHook
Int -> ReadS ProvisioningHook
ReadS [ProvisioningHook]
(Int -> ReadS ProvisioningHook)
-> ReadS [ProvisioningHook]
-> ReadPrec ProvisioningHook
-> ReadPrec [ProvisioningHook]
-> Read ProvisioningHook
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProvisioningHook]
$creadListPrec :: ReadPrec [ProvisioningHook]
readPrec :: ReadPrec ProvisioningHook
$creadPrec :: ReadPrec ProvisioningHook
readList :: ReadS [ProvisioningHook]
$creadList :: ReadS [ProvisioningHook]
readsPrec :: Int -> ReadS ProvisioningHook
$creadsPrec :: Int -> ReadS ProvisioningHook
Prelude.Read, Int -> ProvisioningHook -> ShowS
[ProvisioningHook] -> ShowS
ProvisioningHook -> String
(Int -> ProvisioningHook -> ShowS)
-> (ProvisioningHook -> String)
-> ([ProvisioningHook] -> ShowS)
-> Show ProvisioningHook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProvisioningHook] -> ShowS
$cshowList :: [ProvisioningHook] -> ShowS
show :: ProvisioningHook -> String
$cshow :: ProvisioningHook -> String
showsPrec :: Int -> ProvisioningHook -> ShowS
$cshowsPrec :: Int -> ProvisioningHook -> ShowS
Prelude.Show, (forall x. ProvisioningHook -> Rep ProvisioningHook x)
-> (forall x. Rep ProvisioningHook x -> ProvisioningHook)
-> Generic ProvisioningHook
forall x. Rep ProvisioningHook x -> ProvisioningHook
forall x. ProvisioningHook -> Rep ProvisioningHook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProvisioningHook x -> ProvisioningHook
$cfrom :: forall x. ProvisioningHook -> Rep ProvisioningHook x
Prelude.Generic)

-- |
-- Create a value of 'ProvisioningHook' 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:
--
-- 'payloadVersion', 'provisioningHook_payloadVersion' - The payload that was sent to the target function.
--
-- /Note:/ Only Lambda functions are currently supported.
--
-- 'targetArn', 'provisioningHook_targetArn' - The ARN of the target function.
--
-- /Note:/ Only Lambda functions are currently supported.
newProvisioningHook ::
  -- | 'targetArn'
  Prelude.Text ->
  ProvisioningHook
newProvisioningHook :: Text -> ProvisioningHook
newProvisioningHook Text
pTargetArn_ =
  ProvisioningHook' :: Maybe Text -> Text -> ProvisioningHook
ProvisioningHook'
    { $sel:payloadVersion:ProvisioningHook' :: Maybe Text
payloadVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:targetArn:ProvisioningHook' :: Text
targetArn = Text
pTargetArn_
    }

-- | The payload that was sent to the target function.
--
-- /Note:/ Only Lambda functions are currently supported.
provisioningHook_payloadVersion :: Lens.Lens' ProvisioningHook (Prelude.Maybe Prelude.Text)
provisioningHook_payloadVersion :: (Maybe Text -> f (Maybe Text))
-> ProvisioningHook -> f ProvisioningHook
provisioningHook_payloadVersion = (ProvisioningHook -> Maybe Text)
-> (ProvisioningHook -> Maybe Text -> ProvisioningHook)
-> Lens ProvisioningHook ProvisioningHook (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProvisioningHook' {Maybe Text
payloadVersion :: Maybe Text
$sel:payloadVersion:ProvisioningHook' :: ProvisioningHook -> Maybe Text
payloadVersion} -> Maybe Text
payloadVersion) (\s :: ProvisioningHook
s@ProvisioningHook' {} Maybe Text
a -> ProvisioningHook
s {$sel:payloadVersion:ProvisioningHook' :: Maybe Text
payloadVersion = Maybe Text
a} :: ProvisioningHook)

-- | The ARN of the target function.
--
-- /Note:/ Only Lambda functions are currently supported.
provisioningHook_targetArn :: Lens.Lens' ProvisioningHook Prelude.Text
provisioningHook_targetArn :: (Text -> f Text) -> ProvisioningHook -> f ProvisioningHook
provisioningHook_targetArn = (ProvisioningHook -> Text)
-> (ProvisioningHook -> Text -> ProvisioningHook)
-> Lens ProvisioningHook ProvisioningHook Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProvisioningHook' {Text
targetArn :: Text
$sel:targetArn:ProvisioningHook' :: ProvisioningHook -> Text
targetArn} -> Text
targetArn) (\s :: ProvisioningHook
s@ProvisioningHook' {} Text
a -> ProvisioningHook
s {$sel:targetArn:ProvisioningHook' :: Text
targetArn = Text
a} :: ProvisioningHook)

instance Core.FromJSON ProvisioningHook where
  parseJSON :: Value -> Parser ProvisioningHook
parseJSON =
    String
-> (Object -> Parser ProvisioningHook)
-> Value
-> Parser ProvisioningHook
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ProvisioningHook"
      ( \Object
x ->
          Maybe Text -> Text -> ProvisioningHook
ProvisioningHook'
            (Maybe Text -> Text -> ProvisioningHook)
-> Parser (Maybe Text) -> Parser (Text -> ProvisioningHook)
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
"payloadVersion")
            Parser (Text -> ProvisioningHook)
-> Parser Text -> Parser ProvisioningHook
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
"targetArn")
      )

instance Prelude.Hashable ProvisioningHook

instance Prelude.NFData ProvisioningHook

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