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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.EndpointTypesElement
import qualified Amazonka.Prelude as Prelude

-- | Specifies the delivery configuration settings for sending a campaign or
-- campaign treatment through a custom channel. This object is required if
-- you use the CampaignCustomMessage object to define the message to send
-- for the campaign or campaign treatment.
--
-- /See:/ 'newCustomDeliveryConfiguration' smart constructor.
data CustomDeliveryConfiguration = CustomDeliveryConfiguration'
  { -- | The types of endpoints to send the campaign or treatment to. Each valid
    -- value maps to a type of channel that you can associate with an endpoint
    -- by using the ChannelType property of an endpoint.
    CustomDeliveryConfiguration -> Maybe [EndpointTypesElement]
endpointTypes :: Prelude.Maybe [EndpointTypesElement],
    -- | The destination to send the campaign or treatment to. This value can be
    -- one of the following:
    --
    -- -   The name or Amazon Resource Name (ARN) of an AWS Lambda function to
    --     invoke to handle delivery of the campaign or treatment.
    --
    -- -   The URL for a web application or service that supports HTTPS and can
    --     receive the message. The URL has to be a full URL, including the
    --     HTTPS protocol.
    CustomDeliveryConfiguration -> Text
deliveryUri :: Prelude.Text
  }
  deriving (CustomDeliveryConfiguration -> CustomDeliveryConfiguration -> Bool
(CustomDeliveryConfiguration
 -> CustomDeliveryConfiguration -> Bool)
-> (CustomDeliveryConfiguration
    -> CustomDeliveryConfiguration -> Bool)
-> Eq CustomDeliveryConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomDeliveryConfiguration -> CustomDeliveryConfiguration -> Bool
$c/= :: CustomDeliveryConfiguration -> CustomDeliveryConfiguration -> Bool
== :: CustomDeliveryConfiguration -> CustomDeliveryConfiguration -> Bool
$c== :: CustomDeliveryConfiguration -> CustomDeliveryConfiguration -> Bool
Prelude.Eq, ReadPrec [CustomDeliveryConfiguration]
ReadPrec CustomDeliveryConfiguration
Int -> ReadS CustomDeliveryConfiguration
ReadS [CustomDeliveryConfiguration]
(Int -> ReadS CustomDeliveryConfiguration)
-> ReadS [CustomDeliveryConfiguration]
-> ReadPrec CustomDeliveryConfiguration
-> ReadPrec [CustomDeliveryConfiguration]
-> Read CustomDeliveryConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomDeliveryConfiguration]
$creadListPrec :: ReadPrec [CustomDeliveryConfiguration]
readPrec :: ReadPrec CustomDeliveryConfiguration
$creadPrec :: ReadPrec CustomDeliveryConfiguration
readList :: ReadS [CustomDeliveryConfiguration]
$creadList :: ReadS [CustomDeliveryConfiguration]
readsPrec :: Int -> ReadS CustomDeliveryConfiguration
$creadsPrec :: Int -> ReadS CustomDeliveryConfiguration
Prelude.Read, Int -> CustomDeliveryConfiguration -> ShowS
[CustomDeliveryConfiguration] -> ShowS
CustomDeliveryConfiguration -> String
(Int -> CustomDeliveryConfiguration -> ShowS)
-> (CustomDeliveryConfiguration -> String)
-> ([CustomDeliveryConfiguration] -> ShowS)
-> Show CustomDeliveryConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomDeliveryConfiguration] -> ShowS
$cshowList :: [CustomDeliveryConfiguration] -> ShowS
show :: CustomDeliveryConfiguration -> String
$cshow :: CustomDeliveryConfiguration -> String
showsPrec :: Int -> CustomDeliveryConfiguration -> ShowS
$cshowsPrec :: Int -> CustomDeliveryConfiguration -> ShowS
Prelude.Show, (forall x.
 CustomDeliveryConfiguration -> Rep CustomDeliveryConfiguration x)
-> (forall x.
    Rep CustomDeliveryConfiguration x -> CustomDeliveryConfiguration)
-> Generic CustomDeliveryConfiguration
forall x.
Rep CustomDeliveryConfiguration x -> CustomDeliveryConfiguration
forall x.
CustomDeliveryConfiguration -> Rep CustomDeliveryConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CustomDeliveryConfiguration x -> CustomDeliveryConfiguration
$cfrom :: forall x.
CustomDeliveryConfiguration -> Rep CustomDeliveryConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'CustomDeliveryConfiguration' 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:
--
-- 'endpointTypes', 'customDeliveryConfiguration_endpointTypes' - The types of endpoints to send the campaign or treatment to. Each valid
-- value maps to a type of channel that you can associate with an endpoint
-- by using the ChannelType property of an endpoint.
--
-- 'deliveryUri', 'customDeliveryConfiguration_deliveryUri' - The destination to send the campaign or treatment to. This value can be
-- one of the following:
--
-- -   The name or Amazon Resource Name (ARN) of an AWS Lambda function to
--     invoke to handle delivery of the campaign or treatment.
--
-- -   The URL for a web application or service that supports HTTPS and can
--     receive the message. The URL has to be a full URL, including the
--     HTTPS protocol.
newCustomDeliveryConfiguration ::
  -- | 'deliveryUri'
  Prelude.Text ->
  CustomDeliveryConfiguration
newCustomDeliveryConfiguration :: Text -> CustomDeliveryConfiguration
newCustomDeliveryConfiguration Text
pDeliveryUri_ =
  CustomDeliveryConfiguration' :: Maybe [EndpointTypesElement] -> Text -> CustomDeliveryConfiguration
CustomDeliveryConfiguration'
    { $sel:endpointTypes:CustomDeliveryConfiguration' :: Maybe [EndpointTypesElement]
endpointTypes =
        Maybe [EndpointTypesElement]
forall a. Maybe a
Prelude.Nothing,
      $sel:deliveryUri:CustomDeliveryConfiguration' :: Text
deliveryUri = Text
pDeliveryUri_
    }

-- | The types of endpoints to send the campaign or treatment to. Each valid
-- value maps to a type of channel that you can associate with an endpoint
-- by using the ChannelType property of an endpoint.
customDeliveryConfiguration_endpointTypes :: Lens.Lens' CustomDeliveryConfiguration (Prelude.Maybe [EndpointTypesElement])
customDeliveryConfiguration_endpointTypes :: (Maybe [EndpointTypesElement] -> f (Maybe [EndpointTypesElement]))
-> CustomDeliveryConfiguration -> f CustomDeliveryConfiguration
customDeliveryConfiguration_endpointTypes = (CustomDeliveryConfiguration -> Maybe [EndpointTypesElement])
-> (CustomDeliveryConfiguration
    -> Maybe [EndpointTypesElement] -> CustomDeliveryConfiguration)
-> Lens
     CustomDeliveryConfiguration
     CustomDeliveryConfiguration
     (Maybe [EndpointTypesElement])
     (Maybe [EndpointTypesElement])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomDeliveryConfiguration' {Maybe [EndpointTypesElement]
endpointTypes :: Maybe [EndpointTypesElement]
$sel:endpointTypes:CustomDeliveryConfiguration' :: CustomDeliveryConfiguration -> Maybe [EndpointTypesElement]
endpointTypes} -> Maybe [EndpointTypesElement]
endpointTypes) (\s :: CustomDeliveryConfiguration
s@CustomDeliveryConfiguration' {} Maybe [EndpointTypesElement]
a -> CustomDeliveryConfiguration
s {$sel:endpointTypes:CustomDeliveryConfiguration' :: Maybe [EndpointTypesElement]
endpointTypes = Maybe [EndpointTypesElement]
a} :: CustomDeliveryConfiguration) ((Maybe [EndpointTypesElement] -> f (Maybe [EndpointTypesElement]))
 -> CustomDeliveryConfiguration -> f CustomDeliveryConfiguration)
-> ((Maybe [EndpointTypesElement]
     -> f (Maybe [EndpointTypesElement]))
    -> Maybe [EndpointTypesElement]
    -> f (Maybe [EndpointTypesElement]))
-> (Maybe [EndpointTypesElement]
    -> f (Maybe [EndpointTypesElement]))
-> CustomDeliveryConfiguration
-> f CustomDeliveryConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [EndpointTypesElement]
  [EndpointTypesElement]
  [EndpointTypesElement]
  [EndpointTypesElement]
-> Iso
     (Maybe [EndpointTypesElement])
     (Maybe [EndpointTypesElement])
     (Maybe [EndpointTypesElement])
     (Maybe [EndpointTypesElement])
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
  [EndpointTypesElement]
  [EndpointTypesElement]
  [EndpointTypesElement]
  [EndpointTypesElement]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The destination to send the campaign or treatment to. This value can be
-- one of the following:
--
-- -   The name or Amazon Resource Name (ARN) of an AWS Lambda function to
--     invoke to handle delivery of the campaign or treatment.
--
-- -   The URL for a web application or service that supports HTTPS and can
--     receive the message. The URL has to be a full URL, including the
--     HTTPS protocol.
customDeliveryConfiguration_deliveryUri :: Lens.Lens' CustomDeliveryConfiguration Prelude.Text
customDeliveryConfiguration_deliveryUri :: (Text -> f Text)
-> CustomDeliveryConfiguration -> f CustomDeliveryConfiguration
customDeliveryConfiguration_deliveryUri = (CustomDeliveryConfiguration -> Text)
-> (CustomDeliveryConfiguration
    -> Text -> CustomDeliveryConfiguration)
-> Lens
     CustomDeliveryConfiguration CustomDeliveryConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomDeliveryConfiguration' {Text
deliveryUri :: Text
$sel:deliveryUri:CustomDeliveryConfiguration' :: CustomDeliveryConfiguration -> Text
deliveryUri} -> Text
deliveryUri) (\s :: CustomDeliveryConfiguration
s@CustomDeliveryConfiguration' {} Text
a -> CustomDeliveryConfiguration
s {$sel:deliveryUri:CustomDeliveryConfiguration' :: Text
deliveryUri = Text
a} :: CustomDeliveryConfiguration)

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

instance Prelude.Hashable CustomDeliveryConfiguration

instance Prelude.NFData CustomDeliveryConfiguration

instance Core.ToJSON CustomDeliveryConfiguration where
  toJSON :: CustomDeliveryConfiguration -> Value
toJSON CustomDeliveryConfiguration' {Maybe [EndpointTypesElement]
Text
deliveryUri :: Text
endpointTypes :: Maybe [EndpointTypesElement]
$sel:deliveryUri:CustomDeliveryConfiguration' :: CustomDeliveryConfiguration -> Text
$sel:endpointTypes:CustomDeliveryConfiguration' :: CustomDeliveryConfiguration -> Maybe [EndpointTypesElement]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EndpointTypes" Text -> [EndpointTypesElement] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([EndpointTypesElement] -> Pair)
-> Maybe [EndpointTypesElement] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [EndpointTypesElement]
endpointTypes,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DeliveryUri" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
deliveryUri)
          ]
      )