{-# 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.Pinpoint.Types.CampaignHook
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Pinpoint.Types.CampaignHook where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Pinpoint.Types.Mode
import qualified Amazonka.Prelude as Prelude

-- | Specifies settings for invoking an AWS Lambda function that customizes a
-- segment for a campaign.
--
-- /See:/ 'newCampaignHook' smart constructor.
data CampaignHook = CampaignHook'
  { -- | The name or Amazon Resource Name (ARN) of the AWS Lambda function that
    -- Amazon Pinpoint invokes to customize a segment for a campaign.
    CampaignHook -> Maybe Text
lambdaFunctionName :: Prelude.Maybe Prelude.Text,
    -- | The mode that Amazon Pinpoint uses to invoke the AWS Lambda function.
    -- Possible values are:
    --
    -- -   FILTER - Invoke the function to customize the segment that\'s used
    --     by a campaign.
    --
    -- -   DELIVERY - (Deprecated) Previously, invoked the function to send a
    --     campaign through a custom channel. This functionality is not
    --     supported anymore. To send a campaign through a custom channel, use
    --     the CustomDeliveryConfiguration and CampaignCustomMessage objects of
    --     the campaign.
    CampaignHook -> Maybe Mode
mode :: Prelude.Maybe Mode,
    -- | The web URL that Amazon Pinpoint calls to invoke the AWS Lambda function
    -- over HTTPS.
    CampaignHook -> Maybe Text
webUrl :: Prelude.Maybe Prelude.Text
  }
  deriving (CampaignHook -> CampaignHook -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CampaignHook -> CampaignHook -> Bool
$c/= :: CampaignHook -> CampaignHook -> Bool
== :: CampaignHook -> CampaignHook -> Bool
$c== :: CampaignHook -> CampaignHook -> Bool
Prelude.Eq, ReadPrec [CampaignHook]
ReadPrec CampaignHook
Int -> ReadS CampaignHook
ReadS [CampaignHook]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CampaignHook]
$creadListPrec :: ReadPrec [CampaignHook]
readPrec :: ReadPrec CampaignHook
$creadPrec :: ReadPrec CampaignHook
readList :: ReadS [CampaignHook]
$creadList :: ReadS [CampaignHook]
readsPrec :: Int -> ReadS CampaignHook
$creadsPrec :: Int -> ReadS CampaignHook
Prelude.Read, Int -> CampaignHook -> ShowS
[CampaignHook] -> ShowS
CampaignHook -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CampaignHook] -> ShowS
$cshowList :: [CampaignHook] -> ShowS
show :: CampaignHook -> String
$cshow :: CampaignHook -> String
showsPrec :: Int -> CampaignHook -> ShowS
$cshowsPrec :: Int -> CampaignHook -> ShowS
Prelude.Show, forall x. Rep CampaignHook x -> CampaignHook
forall x. CampaignHook -> Rep CampaignHook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CampaignHook x -> CampaignHook
$cfrom :: forall x. CampaignHook -> Rep CampaignHook x
Prelude.Generic)

-- |
-- Create a value of 'CampaignHook' 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:
--
-- 'lambdaFunctionName', 'campaignHook_lambdaFunctionName' - The name or Amazon Resource Name (ARN) of the AWS Lambda function that
-- Amazon Pinpoint invokes to customize a segment for a campaign.
--
-- 'mode', 'campaignHook_mode' - The mode that Amazon Pinpoint uses to invoke the AWS Lambda function.
-- Possible values are:
--
-- -   FILTER - Invoke the function to customize the segment that\'s used
--     by a campaign.
--
-- -   DELIVERY - (Deprecated) Previously, invoked the function to send a
--     campaign through a custom channel. This functionality is not
--     supported anymore. To send a campaign through a custom channel, use
--     the CustomDeliveryConfiguration and CampaignCustomMessage objects of
--     the campaign.
--
-- 'webUrl', 'campaignHook_webUrl' - The web URL that Amazon Pinpoint calls to invoke the AWS Lambda function
-- over HTTPS.
newCampaignHook ::
  CampaignHook
newCampaignHook :: CampaignHook
newCampaignHook =
  CampaignHook'
    { $sel:lambdaFunctionName:CampaignHook' :: Maybe Text
lambdaFunctionName = forall a. Maybe a
Prelude.Nothing,
      $sel:mode:CampaignHook' :: Maybe Mode
mode = forall a. Maybe a
Prelude.Nothing,
      $sel:webUrl:CampaignHook' :: Maybe Text
webUrl = forall a. Maybe a
Prelude.Nothing
    }

-- | The name or Amazon Resource Name (ARN) of the AWS Lambda function that
-- Amazon Pinpoint invokes to customize a segment for a campaign.
campaignHook_lambdaFunctionName :: Lens.Lens' CampaignHook (Prelude.Maybe Prelude.Text)
campaignHook_lambdaFunctionName :: Lens' CampaignHook (Maybe Text)
campaignHook_lambdaFunctionName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CampaignHook' {Maybe Text
lambdaFunctionName :: Maybe Text
$sel:lambdaFunctionName:CampaignHook' :: CampaignHook -> Maybe Text
lambdaFunctionName} -> Maybe Text
lambdaFunctionName) (\s :: CampaignHook
s@CampaignHook' {} Maybe Text
a -> CampaignHook
s {$sel:lambdaFunctionName:CampaignHook' :: Maybe Text
lambdaFunctionName = Maybe Text
a} :: CampaignHook)

-- | The mode that Amazon Pinpoint uses to invoke the AWS Lambda function.
-- Possible values are:
--
-- -   FILTER - Invoke the function to customize the segment that\'s used
--     by a campaign.
--
-- -   DELIVERY - (Deprecated) Previously, invoked the function to send a
--     campaign through a custom channel. This functionality is not
--     supported anymore. To send a campaign through a custom channel, use
--     the CustomDeliveryConfiguration and CampaignCustomMessage objects of
--     the campaign.
campaignHook_mode :: Lens.Lens' CampaignHook (Prelude.Maybe Mode)
campaignHook_mode :: Lens' CampaignHook (Maybe Mode)
campaignHook_mode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CampaignHook' {Maybe Mode
mode :: Maybe Mode
$sel:mode:CampaignHook' :: CampaignHook -> Maybe Mode
mode} -> Maybe Mode
mode) (\s :: CampaignHook
s@CampaignHook' {} Maybe Mode
a -> CampaignHook
s {$sel:mode:CampaignHook' :: Maybe Mode
mode = Maybe Mode
a} :: CampaignHook)

-- | The web URL that Amazon Pinpoint calls to invoke the AWS Lambda function
-- over HTTPS.
campaignHook_webUrl :: Lens.Lens' CampaignHook (Prelude.Maybe Prelude.Text)
campaignHook_webUrl :: Lens' CampaignHook (Maybe Text)
campaignHook_webUrl = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CampaignHook' {Maybe Text
webUrl :: Maybe Text
$sel:webUrl:CampaignHook' :: CampaignHook -> Maybe Text
webUrl} -> Maybe Text
webUrl) (\s :: CampaignHook
s@CampaignHook' {} Maybe Text
a -> CampaignHook
s {$sel:webUrl:CampaignHook' :: Maybe Text
webUrl = Maybe Text
a} :: CampaignHook)

instance Data.FromJSON CampaignHook where
  parseJSON :: Value -> Parser CampaignHook
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CampaignHook"
      ( \Object
x ->
          Maybe Text -> Maybe Mode -> Maybe Text -> CampaignHook
CampaignHook'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"LambdaFunctionName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Mode")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"WebUrl")
      )

instance Prelude.Hashable CampaignHook where
  hashWithSalt :: Int -> CampaignHook -> Int
hashWithSalt Int
_salt CampaignHook' {Maybe Text
Maybe Mode
webUrl :: Maybe Text
mode :: Maybe Mode
lambdaFunctionName :: Maybe Text
$sel:webUrl:CampaignHook' :: CampaignHook -> Maybe Text
$sel:mode:CampaignHook' :: CampaignHook -> Maybe Mode
$sel:lambdaFunctionName:CampaignHook' :: CampaignHook -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
lambdaFunctionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Mode
mode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
webUrl

instance Prelude.NFData CampaignHook where
  rnf :: CampaignHook -> ()
rnf CampaignHook' {Maybe Text
Maybe Mode
webUrl :: Maybe Text
mode :: Maybe Mode
lambdaFunctionName :: Maybe Text
$sel:webUrl:CampaignHook' :: CampaignHook -> Maybe Text
$sel:mode:CampaignHook' :: CampaignHook -> Maybe Mode
$sel:lambdaFunctionName:CampaignHook' :: CampaignHook -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
lambdaFunctionName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Mode
mode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
webUrl

instance Data.ToJSON CampaignHook where
  toJSON :: CampaignHook -> Value
toJSON CampaignHook' {Maybe Text
Maybe Mode
webUrl :: Maybe Text
mode :: Maybe Mode
lambdaFunctionName :: Maybe Text
$sel:webUrl:CampaignHook' :: CampaignHook -> Maybe Text
$sel:mode:CampaignHook' :: CampaignHook -> Maybe Mode
$sel:lambdaFunctionName:CampaignHook' :: CampaignHook -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"LambdaFunctionName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
lambdaFunctionName,
            (Key
"Mode" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Mode
mode,
            (Key
"WebUrl" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
webUrl
          ]
      )