{-# 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-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.Pinpoint.Types.CampaignHook where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(CampaignHook -> CampaignHook -> Bool)
-> (CampaignHook -> CampaignHook -> Bool) -> Eq CampaignHook
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]
(Int -> ReadS CampaignHook)
-> ReadS [CampaignHook]
-> ReadPrec CampaignHook
-> ReadPrec [CampaignHook]
-> Read 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
(Int -> CampaignHook -> ShowS)
-> (CampaignHook -> String)
-> ([CampaignHook] -> ShowS)
-> Show CampaignHook
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. CampaignHook -> Rep CampaignHook x)
-> (forall x. Rep CampaignHook x -> CampaignHook)
-> Generic CampaignHook
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' :: Maybe Text -> Maybe Mode -> Maybe Text -> CampaignHook
CampaignHook'
    { $sel:lambdaFunctionName:CampaignHook' :: Maybe Text
lambdaFunctionName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:mode:CampaignHook' :: Maybe Mode
mode = Maybe Mode
forall a. Maybe a
Prelude.Nothing,
      $sel:webUrl:CampaignHook' :: Maybe Text
webUrl = Maybe Text
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 :: (Maybe Text -> f (Maybe Text)) -> CampaignHook -> f CampaignHook
campaignHook_lambdaFunctionName = (CampaignHook -> Maybe Text)
-> (CampaignHook -> Maybe Text -> CampaignHook)
-> Lens CampaignHook CampaignHook (Maybe Text) (Maybe Text)
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 :: (Maybe Mode -> f (Maybe Mode)) -> CampaignHook -> f CampaignHook
campaignHook_mode = (CampaignHook -> Maybe Mode)
-> (CampaignHook -> Maybe Mode -> CampaignHook)
-> Lens CampaignHook CampaignHook (Maybe Mode) (Maybe 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 :: (Maybe Text -> f (Maybe Text)) -> CampaignHook -> f CampaignHook
campaignHook_webUrl = (CampaignHook -> Maybe Text)
-> (CampaignHook -> Maybe Text -> CampaignHook)
-> Lens CampaignHook CampaignHook (Maybe Text) (Maybe Text)
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 Core.FromJSON CampaignHook where
  parseJSON :: Value -> Parser CampaignHook
parseJSON =
    String
-> (Object -> Parser CampaignHook) -> Value -> Parser CampaignHook
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CampaignHook"
      ( \Object
x ->
          Maybe Text -> Maybe Mode -> Maybe Text -> CampaignHook
CampaignHook'
            (Maybe Text -> Maybe Mode -> Maybe Text -> CampaignHook)
-> Parser (Maybe Text)
-> Parser (Maybe Mode -> Maybe Text -> CampaignHook)
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
"LambdaFunctionName")
            Parser (Maybe Mode -> Maybe Text -> CampaignHook)
-> Parser (Maybe Mode) -> Parser (Maybe Text -> CampaignHook)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Mode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Mode")
            Parser (Maybe Text -> CampaignHook)
-> Parser (Maybe Text) -> Parser CampaignHook
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
"WebUrl")
      )

instance Prelude.Hashable CampaignHook

instance Prelude.NFData CampaignHook

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"LambdaFunctionName" 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
lambdaFunctionName,
            (Text
"Mode" Text -> Mode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Mode -> Pair) -> Maybe Mode -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Mode
mode,
            (Text
"WebUrl" 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
webUrl
          ]
      )