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

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

-- | A CloudFront function that is associated with a cache behavior in a
-- CloudFront distribution.
--
-- /See:/ 'newFunctionAssociation' smart constructor.
data FunctionAssociation = FunctionAssociation'
  { -- | The Amazon Resource Name (ARN) of the function.
    FunctionAssociation -> Text
functionARN :: Prelude.Text,
    -- | The event type of the function, either @viewer-request@ or
    -- @viewer-response@. You cannot use origin-facing event types
    -- (@origin-request@ and @origin-response@) with a CloudFront function.
    FunctionAssociation -> EventType
eventType :: EventType
  }
  deriving (FunctionAssociation -> FunctionAssociation -> Bool
(FunctionAssociation -> FunctionAssociation -> Bool)
-> (FunctionAssociation -> FunctionAssociation -> Bool)
-> Eq FunctionAssociation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionAssociation -> FunctionAssociation -> Bool
$c/= :: FunctionAssociation -> FunctionAssociation -> Bool
== :: FunctionAssociation -> FunctionAssociation -> Bool
$c== :: FunctionAssociation -> FunctionAssociation -> Bool
Prelude.Eq, ReadPrec [FunctionAssociation]
ReadPrec FunctionAssociation
Int -> ReadS FunctionAssociation
ReadS [FunctionAssociation]
(Int -> ReadS FunctionAssociation)
-> ReadS [FunctionAssociation]
-> ReadPrec FunctionAssociation
-> ReadPrec [FunctionAssociation]
-> Read FunctionAssociation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FunctionAssociation]
$creadListPrec :: ReadPrec [FunctionAssociation]
readPrec :: ReadPrec FunctionAssociation
$creadPrec :: ReadPrec FunctionAssociation
readList :: ReadS [FunctionAssociation]
$creadList :: ReadS [FunctionAssociation]
readsPrec :: Int -> ReadS FunctionAssociation
$creadsPrec :: Int -> ReadS FunctionAssociation
Prelude.Read, Int -> FunctionAssociation -> ShowS
[FunctionAssociation] -> ShowS
FunctionAssociation -> String
(Int -> FunctionAssociation -> ShowS)
-> (FunctionAssociation -> String)
-> ([FunctionAssociation] -> ShowS)
-> Show FunctionAssociation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionAssociation] -> ShowS
$cshowList :: [FunctionAssociation] -> ShowS
show :: FunctionAssociation -> String
$cshow :: FunctionAssociation -> String
showsPrec :: Int -> FunctionAssociation -> ShowS
$cshowsPrec :: Int -> FunctionAssociation -> ShowS
Prelude.Show, (forall x. FunctionAssociation -> Rep FunctionAssociation x)
-> (forall x. Rep FunctionAssociation x -> FunctionAssociation)
-> Generic FunctionAssociation
forall x. Rep FunctionAssociation x -> FunctionAssociation
forall x. FunctionAssociation -> Rep FunctionAssociation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FunctionAssociation x -> FunctionAssociation
$cfrom :: forall x. FunctionAssociation -> Rep FunctionAssociation x
Prelude.Generic)

-- |
-- Create a value of 'FunctionAssociation' 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:
--
-- 'functionARN', 'functionAssociation_functionARN' - The Amazon Resource Name (ARN) of the function.
--
-- 'eventType', 'functionAssociation_eventType' - The event type of the function, either @viewer-request@ or
-- @viewer-response@. You cannot use origin-facing event types
-- (@origin-request@ and @origin-response@) with a CloudFront function.
newFunctionAssociation ::
  -- | 'functionARN'
  Prelude.Text ->
  -- | 'eventType'
  EventType ->
  FunctionAssociation
newFunctionAssociation :: Text -> EventType -> FunctionAssociation
newFunctionAssociation Text
pFunctionARN_ EventType
pEventType_ =
  FunctionAssociation' :: Text -> EventType -> FunctionAssociation
FunctionAssociation'
    { $sel:functionARN:FunctionAssociation' :: Text
functionARN = Text
pFunctionARN_,
      $sel:eventType:FunctionAssociation' :: EventType
eventType = EventType
pEventType_
    }

-- | The Amazon Resource Name (ARN) of the function.
functionAssociation_functionARN :: Lens.Lens' FunctionAssociation Prelude.Text
functionAssociation_functionARN :: (Text -> f Text) -> FunctionAssociation -> f FunctionAssociation
functionAssociation_functionARN = (FunctionAssociation -> Text)
-> (FunctionAssociation -> Text -> FunctionAssociation)
-> Lens FunctionAssociation FunctionAssociation Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionAssociation' {Text
functionARN :: Text
$sel:functionARN:FunctionAssociation' :: FunctionAssociation -> Text
functionARN} -> Text
functionARN) (\s :: FunctionAssociation
s@FunctionAssociation' {} Text
a -> FunctionAssociation
s {$sel:functionARN:FunctionAssociation' :: Text
functionARN = Text
a} :: FunctionAssociation)

-- | The event type of the function, either @viewer-request@ or
-- @viewer-response@. You cannot use origin-facing event types
-- (@origin-request@ and @origin-response@) with a CloudFront function.
functionAssociation_eventType :: Lens.Lens' FunctionAssociation EventType
functionAssociation_eventType :: (EventType -> f EventType)
-> FunctionAssociation -> f FunctionAssociation
functionAssociation_eventType = (FunctionAssociation -> EventType)
-> (FunctionAssociation -> EventType -> FunctionAssociation)
-> Lens FunctionAssociation FunctionAssociation EventType EventType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionAssociation' {EventType
eventType :: EventType
$sel:eventType:FunctionAssociation' :: FunctionAssociation -> EventType
eventType} -> EventType
eventType) (\s :: FunctionAssociation
s@FunctionAssociation' {} EventType
a -> FunctionAssociation
s {$sel:eventType:FunctionAssociation' :: EventType
eventType = EventType
a} :: FunctionAssociation)

instance Core.FromXML FunctionAssociation where
  parseXML :: [Node] -> Either String FunctionAssociation
parseXML [Node]
x =
    Text -> EventType -> FunctionAssociation
FunctionAssociation'
      (Text -> EventType -> FunctionAssociation)
-> Either String Text
-> Either String (EventType -> FunctionAssociation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"FunctionARN")
      Either String (EventType -> FunctionAssociation)
-> Either String EventType -> Either String FunctionAssociation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String EventType
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"EventType")

instance Prelude.Hashable FunctionAssociation

instance Prelude.NFData FunctionAssociation

instance Core.ToXML FunctionAssociation where
  toXML :: FunctionAssociation -> XML
toXML FunctionAssociation' {Text
EventType
eventType :: EventType
functionARN :: Text
$sel:eventType:FunctionAssociation' :: FunctionAssociation -> EventType
$sel:functionARN:FunctionAssociation' :: FunctionAssociation -> Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"FunctionARN" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
functionARN,
        Name
"EventType" Name -> EventType -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= EventType
eventType
      ]