{-# 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.CloudFront.Types.LambdaFunctionAssociations
-- 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.CloudFront.Types.LambdaFunctionAssociations where

import Amazonka.CloudFront.Types.LambdaFunctionAssociation
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex type that specifies a list of Lambda\@Edge functions
-- associations for a cache behavior.
--
-- If you want to invoke one or more Lambda\@Edge functions triggered by
-- requests that match the @PathPattern@ of the cache behavior, specify the
-- applicable values for @Quantity@ and @Items@. Note that there can be up
-- to 4 @LambdaFunctionAssociation@ items in this list (one for each
-- possible value of @EventType@) and each @EventType@ can be associated
-- with only one function.
--
-- If you don\'t want to invoke any Lambda\@Edge functions for the requests
-- that match @PathPattern@, specify @0@ for @Quantity@ and omit @Items@.
--
-- /See:/ 'newLambdaFunctionAssociations' smart constructor.
data LambdaFunctionAssociations = LambdaFunctionAssociations'
  { -- | __Optional__: A complex type that contains @LambdaFunctionAssociation@
    -- items for this cache behavior. If @Quantity@ is @0@, you can omit
    -- @Items@.
    LambdaFunctionAssociations -> Maybe [LambdaFunctionAssociation]
items :: Prelude.Maybe [LambdaFunctionAssociation],
    -- | The number of Lambda\@Edge function associations for this cache
    -- behavior.
    LambdaFunctionAssociations -> Int
quantity :: Prelude.Int
  }
  deriving (LambdaFunctionAssociations -> LambdaFunctionAssociations -> Bool
(LambdaFunctionAssociations -> LambdaFunctionAssociations -> Bool)
-> (LambdaFunctionAssociations
    -> LambdaFunctionAssociations -> Bool)
-> Eq LambdaFunctionAssociations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LambdaFunctionAssociations -> LambdaFunctionAssociations -> Bool
$c/= :: LambdaFunctionAssociations -> LambdaFunctionAssociations -> Bool
== :: LambdaFunctionAssociations -> LambdaFunctionAssociations -> Bool
$c== :: LambdaFunctionAssociations -> LambdaFunctionAssociations -> Bool
Prelude.Eq, ReadPrec [LambdaFunctionAssociations]
ReadPrec LambdaFunctionAssociations
Int -> ReadS LambdaFunctionAssociations
ReadS [LambdaFunctionAssociations]
(Int -> ReadS LambdaFunctionAssociations)
-> ReadS [LambdaFunctionAssociations]
-> ReadPrec LambdaFunctionAssociations
-> ReadPrec [LambdaFunctionAssociations]
-> Read LambdaFunctionAssociations
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LambdaFunctionAssociations]
$creadListPrec :: ReadPrec [LambdaFunctionAssociations]
readPrec :: ReadPrec LambdaFunctionAssociations
$creadPrec :: ReadPrec LambdaFunctionAssociations
readList :: ReadS [LambdaFunctionAssociations]
$creadList :: ReadS [LambdaFunctionAssociations]
readsPrec :: Int -> ReadS LambdaFunctionAssociations
$creadsPrec :: Int -> ReadS LambdaFunctionAssociations
Prelude.Read, Int -> LambdaFunctionAssociations -> ShowS
[LambdaFunctionAssociations] -> ShowS
LambdaFunctionAssociations -> String
(Int -> LambdaFunctionAssociations -> ShowS)
-> (LambdaFunctionAssociations -> String)
-> ([LambdaFunctionAssociations] -> ShowS)
-> Show LambdaFunctionAssociations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LambdaFunctionAssociations] -> ShowS
$cshowList :: [LambdaFunctionAssociations] -> ShowS
show :: LambdaFunctionAssociations -> String
$cshow :: LambdaFunctionAssociations -> String
showsPrec :: Int -> LambdaFunctionAssociations -> ShowS
$cshowsPrec :: Int -> LambdaFunctionAssociations -> ShowS
Prelude.Show, (forall x.
 LambdaFunctionAssociations -> Rep LambdaFunctionAssociations x)
-> (forall x.
    Rep LambdaFunctionAssociations x -> LambdaFunctionAssociations)
-> Generic LambdaFunctionAssociations
forall x.
Rep LambdaFunctionAssociations x -> LambdaFunctionAssociations
forall x.
LambdaFunctionAssociations -> Rep LambdaFunctionAssociations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep LambdaFunctionAssociations x -> LambdaFunctionAssociations
$cfrom :: forall x.
LambdaFunctionAssociations -> Rep LambdaFunctionAssociations x
Prelude.Generic)

-- |
-- Create a value of 'LambdaFunctionAssociations' 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:
--
-- 'items', 'lambdaFunctionAssociations_items' - __Optional__: A complex type that contains @LambdaFunctionAssociation@
-- items for this cache behavior. If @Quantity@ is @0@, you can omit
-- @Items@.
--
-- 'quantity', 'lambdaFunctionAssociations_quantity' - The number of Lambda\@Edge function associations for this cache
-- behavior.
newLambdaFunctionAssociations ::
  -- | 'quantity'
  Prelude.Int ->
  LambdaFunctionAssociations
newLambdaFunctionAssociations :: Int -> LambdaFunctionAssociations
newLambdaFunctionAssociations Int
pQuantity_ =
  LambdaFunctionAssociations' :: Maybe [LambdaFunctionAssociation]
-> Int -> LambdaFunctionAssociations
LambdaFunctionAssociations'
    { $sel:items:LambdaFunctionAssociations' :: Maybe [LambdaFunctionAssociation]
items =
        Maybe [LambdaFunctionAssociation]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:LambdaFunctionAssociations' :: Int
quantity = Int
pQuantity_
    }

-- | __Optional__: A complex type that contains @LambdaFunctionAssociation@
-- items for this cache behavior. If @Quantity@ is @0@, you can omit
-- @Items@.
lambdaFunctionAssociations_items :: Lens.Lens' LambdaFunctionAssociations (Prelude.Maybe [LambdaFunctionAssociation])
lambdaFunctionAssociations_items :: (Maybe [LambdaFunctionAssociation]
 -> f (Maybe [LambdaFunctionAssociation]))
-> LambdaFunctionAssociations -> f LambdaFunctionAssociations
lambdaFunctionAssociations_items = (LambdaFunctionAssociations -> Maybe [LambdaFunctionAssociation])
-> (LambdaFunctionAssociations
    -> Maybe [LambdaFunctionAssociation] -> LambdaFunctionAssociations)
-> Lens
     LambdaFunctionAssociations
     LambdaFunctionAssociations
     (Maybe [LambdaFunctionAssociation])
     (Maybe [LambdaFunctionAssociation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionAssociations' {Maybe [LambdaFunctionAssociation]
items :: Maybe [LambdaFunctionAssociation]
$sel:items:LambdaFunctionAssociations' :: LambdaFunctionAssociations -> Maybe [LambdaFunctionAssociation]
items} -> Maybe [LambdaFunctionAssociation]
items) (\s :: LambdaFunctionAssociations
s@LambdaFunctionAssociations' {} Maybe [LambdaFunctionAssociation]
a -> LambdaFunctionAssociations
s {$sel:items:LambdaFunctionAssociations' :: Maybe [LambdaFunctionAssociation]
items = Maybe [LambdaFunctionAssociation]
a} :: LambdaFunctionAssociations) ((Maybe [LambdaFunctionAssociation]
  -> f (Maybe [LambdaFunctionAssociation]))
 -> LambdaFunctionAssociations -> f LambdaFunctionAssociations)
-> ((Maybe [LambdaFunctionAssociation]
     -> f (Maybe [LambdaFunctionAssociation]))
    -> Maybe [LambdaFunctionAssociation]
    -> f (Maybe [LambdaFunctionAssociation]))
-> (Maybe [LambdaFunctionAssociation]
    -> f (Maybe [LambdaFunctionAssociation]))
-> LambdaFunctionAssociations
-> f LambdaFunctionAssociations
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [LambdaFunctionAssociation]
  [LambdaFunctionAssociation]
  [LambdaFunctionAssociation]
  [LambdaFunctionAssociation]
-> Iso
     (Maybe [LambdaFunctionAssociation])
     (Maybe [LambdaFunctionAssociation])
     (Maybe [LambdaFunctionAssociation])
     (Maybe [LambdaFunctionAssociation])
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
  [LambdaFunctionAssociation]
  [LambdaFunctionAssociation]
  [LambdaFunctionAssociation]
  [LambdaFunctionAssociation]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of Lambda\@Edge function associations for this cache
-- behavior.
lambdaFunctionAssociations_quantity :: Lens.Lens' LambdaFunctionAssociations Prelude.Int
lambdaFunctionAssociations_quantity :: (Int -> f Int)
-> LambdaFunctionAssociations -> f LambdaFunctionAssociations
lambdaFunctionAssociations_quantity = (LambdaFunctionAssociations -> Int)
-> (LambdaFunctionAssociations
    -> Int -> LambdaFunctionAssociations)
-> Lens
     LambdaFunctionAssociations LambdaFunctionAssociations Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionAssociations' {Int
quantity :: Int
$sel:quantity:LambdaFunctionAssociations' :: LambdaFunctionAssociations -> Int
quantity} -> Int
quantity) (\s :: LambdaFunctionAssociations
s@LambdaFunctionAssociations' {} Int
a -> LambdaFunctionAssociations
s {$sel:quantity:LambdaFunctionAssociations' :: Int
quantity = Int
a} :: LambdaFunctionAssociations)

instance Core.FromXML LambdaFunctionAssociations where
  parseXML :: [Node] -> Either String LambdaFunctionAssociations
parseXML [Node]
x =
    Maybe [LambdaFunctionAssociation]
-> Int -> LambdaFunctionAssociations
LambdaFunctionAssociations'
      (Maybe [LambdaFunctionAssociation]
 -> Int -> LambdaFunctionAssociations)
-> Either String (Maybe [LambdaFunctionAssociation])
-> Either String (Int -> LambdaFunctionAssociations)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Items" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [LambdaFunctionAssociation]))
-> Either String (Maybe [LambdaFunctionAssociation])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [LambdaFunctionAssociation])
-> [Node] -> Either String (Maybe [LambdaFunctionAssociation])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may
                        (Text -> [Node] -> Either String [LambdaFunctionAssociation]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"LambdaFunctionAssociation")
                  )
      Either String (Int -> LambdaFunctionAssociations)
-> Either String Int -> Either String LambdaFunctionAssociations
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Int
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Quantity")

instance Prelude.Hashable LambdaFunctionAssociations

instance Prelude.NFData LambdaFunctionAssociations

instance Core.ToXML LambdaFunctionAssociations where
  toXML :: LambdaFunctionAssociations -> XML
toXML LambdaFunctionAssociations' {Int
Maybe [LambdaFunctionAssociation]
quantity :: Int
items :: Maybe [LambdaFunctionAssociation]
$sel:quantity:LambdaFunctionAssociations' :: LambdaFunctionAssociations -> Int
$sel:items:LambdaFunctionAssociations' :: LambdaFunctionAssociations -> Maybe [LambdaFunctionAssociation]
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe XML -> XML
forall a. ToXML a => a -> XML
Core.toXML
            ( Name -> [LambdaFunctionAssociation] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"LambdaFunctionAssociation"
                ([LambdaFunctionAssociation] -> XML)
-> Maybe [LambdaFunctionAssociation] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [LambdaFunctionAssociation]
items
            ),
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity
      ]