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

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

-- | A list of CloudFront functions that are associated with a cache behavior
-- in a CloudFront distribution. CloudFront functions must be published to
-- the @LIVE@ stage to associate them with a cache behavior.
--
-- /See:/ 'newFunctionAssociations' smart constructor.
data FunctionAssociations = FunctionAssociations'
  { -- | The CloudFront functions that are associated with a cache behavior in a
    -- CloudFront distribution. CloudFront functions must be published to the
    -- @LIVE@ stage to associate them with a cache behavior.
    FunctionAssociations -> Maybe [FunctionAssociation]
items :: Prelude.Maybe [FunctionAssociation],
    -- | The number of CloudFront functions in the list.
    FunctionAssociations -> Int
quantity :: Prelude.Int
  }
  deriving (FunctionAssociations -> FunctionAssociations -> Bool
(FunctionAssociations -> FunctionAssociations -> Bool)
-> (FunctionAssociations -> FunctionAssociations -> Bool)
-> Eq FunctionAssociations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionAssociations -> FunctionAssociations -> Bool
$c/= :: FunctionAssociations -> FunctionAssociations -> Bool
== :: FunctionAssociations -> FunctionAssociations -> Bool
$c== :: FunctionAssociations -> FunctionAssociations -> Bool
Prelude.Eq, ReadPrec [FunctionAssociations]
ReadPrec FunctionAssociations
Int -> ReadS FunctionAssociations
ReadS [FunctionAssociations]
(Int -> ReadS FunctionAssociations)
-> ReadS [FunctionAssociations]
-> ReadPrec FunctionAssociations
-> ReadPrec [FunctionAssociations]
-> Read FunctionAssociations
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FunctionAssociations]
$creadListPrec :: ReadPrec [FunctionAssociations]
readPrec :: ReadPrec FunctionAssociations
$creadPrec :: ReadPrec FunctionAssociations
readList :: ReadS [FunctionAssociations]
$creadList :: ReadS [FunctionAssociations]
readsPrec :: Int -> ReadS FunctionAssociations
$creadsPrec :: Int -> ReadS FunctionAssociations
Prelude.Read, Int -> FunctionAssociations -> ShowS
[FunctionAssociations] -> ShowS
FunctionAssociations -> String
(Int -> FunctionAssociations -> ShowS)
-> (FunctionAssociations -> String)
-> ([FunctionAssociations] -> ShowS)
-> Show FunctionAssociations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionAssociations] -> ShowS
$cshowList :: [FunctionAssociations] -> ShowS
show :: FunctionAssociations -> String
$cshow :: FunctionAssociations -> String
showsPrec :: Int -> FunctionAssociations -> ShowS
$cshowsPrec :: Int -> FunctionAssociations -> ShowS
Prelude.Show, (forall x. FunctionAssociations -> Rep FunctionAssociations x)
-> (forall x. Rep FunctionAssociations x -> FunctionAssociations)
-> Generic FunctionAssociations
forall x. Rep FunctionAssociations x -> FunctionAssociations
forall x. FunctionAssociations -> Rep FunctionAssociations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FunctionAssociations x -> FunctionAssociations
$cfrom :: forall x. FunctionAssociations -> Rep FunctionAssociations x
Prelude.Generic)

-- |
-- Create a value of 'FunctionAssociations' 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', 'functionAssociations_items' - The CloudFront functions that are associated with a cache behavior in a
-- CloudFront distribution. CloudFront functions must be published to the
-- @LIVE@ stage to associate them with a cache behavior.
--
-- 'quantity', 'functionAssociations_quantity' - The number of CloudFront functions in the list.
newFunctionAssociations ::
  -- | 'quantity'
  Prelude.Int ->
  FunctionAssociations
newFunctionAssociations :: Int -> FunctionAssociations
newFunctionAssociations Int
pQuantity_ =
  FunctionAssociations' :: Maybe [FunctionAssociation] -> Int -> FunctionAssociations
FunctionAssociations'
    { $sel:items:FunctionAssociations' :: Maybe [FunctionAssociation]
items = Maybe [FunctionAssociation]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:FunctionAssociations' :: Int
quantity = Int
pQuantity_
    }

-- | The CloudFront functions that are associated with a cache behavior in a
-- CloudFront distribution. CloudFront functions must be published to the
-- @LIVE@ stage to associate them with a cache behavior.
functionAssociations_items :: Lens.Lens' FunctionAssociations (Prelude.Maybe [FunctionAssociation])
functionAssociations_items :: (Maybe [FunctionAssociation] -> f (Maybe [FunctionAssociation]))
-> FunctionAssociations -> f FunctionAssociations
functionAssociations_items = (FunctionAssociations -> Maybe [FunctionAssociation])
-> (FunctionAssociations
    -> Maybe [FunctionAssociation] -> FunctionAssociations)
-> Lens
     FunctionAssociations
     FunctionAssociations
     (Maybe [FunctionAssociation])
     (Maybe [FunctionAssociation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionAssociations' {Maybe [FunctionAssociation]
items :: Maybe [FunctionAssociation]
$sel:items:FunctionAssociations' :: FunctionAssociations -> Maybe [FunctionAssociation]
items} -> Maybe [FunctionAssociation]
items) (\s :: FunctionAssociations
s@FunctionAssociations' {} Maybe [FunctionAssociation]
a -> FunctionAssociations
s {$sel:items:FunctionAssociations' :: Maybe [FunctionAssociation]
items = Maybe [FunctionAssociation]
a} :: FunctionAssociations) ((Maybe [FunctionAssociation] -> f (Maybe [FunctionAssociation]))
 -> FunctionAssociations -> f FunctionAssociations)
-> ((Maybe [FunctionAssociation]
     -> f (Maybe [FunctionAssociation]))
    -> Maybe [FunctionAssociation] -> f (Maybe [FunctionAssociation]))
-> (Maybe [FunctionAssociation] -> f (Maybe [FunctionAssociation]))
-> FunctionAssociations
-> f FunctionAssociations
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [FunctionAssociation]
  [FunctionAssociation]
  [FunctionAssociation]
  [FunctionAssociation]
-> Iso
     (Maybe [FunctionAssociation])
     (Maybe [FunctionAssociation])
     (Maybe [FunctionAssociation])
     (Maybe [FunctionAssociation])
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
  [FunctionAssociation]
  [FunctionAssociation]
  [FunctionAssociation]
  [FunctionAssociation]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of CloudFront functions in the list.
functionAssociations_quantity :: Lens.Lens' FunctionAssociations Prelude.Int
functionAssociations_quantity :: (Int -> f Int) -> FunctionAssociations -> f FunctionAssociations
functionAssociations_quantity = (FunctionAssociations -> Int)
-> (FunctionAssociations -> Int -> FunctionAssociations)
-> Lens FunctionAssociations FunctionAssociations Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionAssociations' {Int
quantity :: Int
$sel:quantity:FunctionAssociations' :: FunctionAssociations -> Int
quantity} -> Int
quantity) (\s :: FunctionAssociations
s@FunctionAssociations' {} Int
a -> FunctionAssociations
s {$sel:quantity:FunctionAssociations' :: Int
quantity = Int
a} :: FunctionAssociations)

instance Core.FromXML FunctionAssociations where
  parseXML :: [Node] -> Either String FunctionAssociations
parseXML [Node]
x =
    Maybe [FunctionAssociation] -> Int -> FunctionAssociations
FunctionAssociations'
      (Maybe [FunctionAssociation] -> Int -> FunctionAssociations)
-> Either String (Maybe [FunctionAssociation])
-> Either String (Int -> FunctionAssociations)
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 [FunctionAssociation]))
-> Either String (Maybe [FunctionAssociation])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [FunctionAssociation])
-> [Node] -> Either String (Maybe [FunctionAssociation])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [FunctionAssociation]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"FunctionAssociation")
                  )
      Either String (Int -> FunctionAssociations)
-> Either String Int -> Either String FunctionAssociations
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 FunctionAssociations

instance Prelude.NFData FunctionAssociations

instance Core.ToXML FunctionAssociations where
  toXML :: FunctionAssociations -> XML
toXML FunctionAssociations' {Int
Maybe [FunctionAssociation]
quantity :: Int
items :: Maybe [FunctionAssociation]
$sel:quantity:FunctionAssociations' :: FunctionAssociations -> Int
$sel:items:FunctionAssociations' :: FunctionAssociations -> Maybe [FunctionAssociation]
..} =
    [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 -> [FunctionAssociation] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"FunctionAssociation"
                ([FunctionAssociation] -> XML)
-> Maybe [FunctionAssociation] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [FunctionAssociation]
items
            ),
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity
      ]