{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' FunctionAssociation Text
functionAssociation_functionARN = 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 :: Lens' FunctionAssociation EventType
functionAssociation_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 Data.FromXML FunctionAssociation where
  parseXML :: [Node] -> Either String FunctionAssociation
parseXML [Node]
x =
    Text -> EventType -> FunctionAssociation
FunctionAssociation'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"FunctionARN")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"EventType")

instance Prelude.Hashable FunctionAssociation where
  hashWithSalt :: Int -> FunctionAssociation -> Int
hashWithSalt Int
_salt FunctionAssociation' {Text
EventType
eventType :: EventType
functionARN :: Text
$sel:eventType:FunctionAssociation' :: FunctionAssociation -> EventType
$sel:functionARN:FunctionAssociation' :: FunctionAssociation -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
functionARN
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EventType
eventType

instance Prelude.NFData FunctionAssociation where
  rnf :: FunctionAssociation -> ()
rnf FunctionAssociation' {Text
EventType
eventType :: EventType
functionARN :: Text
$sel:eventType:FunctionAssociation' :: FunctionAssociation -> EventType
$sel:functionARN:FunctionAssociation' :: FunctionAssociation -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
functionARN
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EventType
eventType

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