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

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

-- | Contains configuration information about a CloudFront function.
--
-- /See:/ 'newFunctionConfig' smart constructor.
data FunctionConfig = FunctionConfig'
  { -- | A comment to describe the function.
    FunctionConfig -> Text
comment :: Prelude.Text,
    -- | The function’s runtime environment. The only valid value is
    -- @cloudfront-js-1.0@.
    FunctionConfig -> FunctionRuntime
runtime :: FunctionRuntime
  }
  deriving (FunctionConfig -> FunctionConfig -> Bool
(FunctionConfig -> FunctionConfig -> Bool)
-> (FunctionConfig -> FunctionConfig -> Bool) -> Eq FunctionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionConfig -> FunctionConfig -> Bool
$c/= :: FunctionConfig -> FunctionConfig -> Bool
== :: FunctionConfig -> FunctionConfig -> Bool
$c== :: FunctionConfig -> FunctionConfig -> Bool
Prelude.Eq, ReadPrec [FunctionConfig]
ReadPrec FunctionConfig
Int -> ReadS FunctionConfig
ReadS [FunctionConfig]
(Int -> ReadS FunctionConfig)
-> ReadS [FunctionConfig]
-> ReadPrec FunctionConfig
-> ReadPrec [FunctionConfig]
-> Read FunctionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FunctionConfig]
$creadListPrec :: ReadPrec [FunctionConfig]
readPrec :: ReadPrec FunctionConfig
$creadPrec :: ReadPrec FunctionConfig
readList :: ReadS [FunctionConfig]
$creadList :: ReadS [FunctionConfig]
readsPrec :: Int -> ReadS FunctionConfig
$creadsPrec :: Int -> ReadS FunctionConfig
Prelude.Read, Int -> FunctionConfig -> ShowS
[FunctionConfig] -> ShowS
FunctionConfig -> String
(Int -> FunctionConfig -> ShowS)
-> (FunctionConfig -> String)
-> ([FunctionConfig] -> ShowS)
-> Show FunctionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionConfig] -> ShowS
$cshowList :: [FunctionConfig] -> ShowS
show :: FunctionConfig -> String
$cshow :: FunctionConfig -> String
showsPrec :: Int -> FunctionConfig -> ShowS
$cshowsPrec :: Int -> FunctionConfig -> ShowS
Prelude.Show, (forall x. FunctionConfig -> Rep FunctionConfig x)
-> (forall x. Rep FunctionConfig x -> FunctionConfig)
-> Generic FunctionConfig
forall x. Rep FunctionConfig x -> FunctionConfig
forall x. FunctionConfig -> Rep FunctionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FunctionConfig x -> FunctionConfig
$cfrom :: forall x. FunctionConfig -> Rep FunctionConfig x
Prelude.Generic)

-- |
-- Create a value of 'FunctionConfig' 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:
--
-- 'comment', 'functionConfig_comment' - A comment to describe the function.
--
-- 'runtime', 'functionConfig_runtime' - The function’s runtime environment. The only valid value is
-- @cloudfront-js-1.0@.
newFunctionConfig ::
  -- | 'comment'
  Prelude.Text ->
  -- | 'runtime'
  FunctionRuntime ->
  FunctionConfig
newFunctionConfig :: Text -> FunctionRuntime -> FunctionConfig
newFunctionConfig Text
pComment_ FunctionRuntime
pRuntime_ =
  FunctionConfig' :: Text -> FunctionRuntime -> FunctionConfig
FunctionConfig'
    { $sel:comment:FunctionConfig' :: Text
comment = Text
pComment_,
      $sel:runtime:FunctionConfig' :: FunctionRuntime
runtime = FunctionRuntime
pRuntime_
    }

-- | A comment to describe the function.
functionConfig_comment :: Lens.Lens' FunctionConfig Prelude.Text
functionConfig_comment :: (Text -> f Text) -> FunctionConfig -> f FunctionConfig
functionConfig_comment = (FunctionConfig -> Text)
-> (FunctionConfig -> Text -> FunctionConfig)
-> Lens FunctionConfig FunctionConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionConfig' {Text
comment :: Text
$sel:comment:FunctionConfig' :: FunctionConfig -> Text
comment} -> Text
comment) (\s :: FunctionConfig
s@FunctionConfig' {} Text
a -> FunctionConfig
s {$sel:comment:FunctionConfig' :: Text
comment = Text
a} :: FunctionConfig)

-- | The function’s runtime environment. The only valid value is
-- @cloudfront-js-1.0@.
functionConfig_runtime :: Lens.Lens' FunctionConfig FunctionRuntime
functionConfig_runtime :: (FunctionRuntime -> f FunctionRuntime)
-> FunctionConfig -> f FunctionConfig
functionConfig_runtime = (FunctionConfig -> FunctionRuntime)
-> (FunctionConfig -> FunctionRuntime -> FunctionConfig)
-> Lens
     FunctionConfig FunctionConfig FunctionRuntime FunctionRuntime
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FunctionConfig' {FunctionRuntime
runtime :: FunctionRuntime
$sel:runtime:FunctionConfig' :: FunctionConfig -> FunctionRuntime
runtime} -> FunctionRuntime
runtime) (\s :: FunctionConfig
s@FunctionConfig' {} FunctionRuntime
a -> FunctionConfig
s {$sel:runtime:FunctionConfig' :: FunctionRuntime
runtime = FunctionRuntime
a} :: FunctionConfig)

instance Core.FromXML FunctionConfig where
  parseXML :: [Node] -> Either String FunctionConfig
parseXML [Node]
x =
    Text -> FunctionRuntime -> FunctionConfig
FunctionConfig'
      (Text -> FunctionRuntime -> FunctionConfig)
-> Either String Text
-> Either String (FunctionRuntime -> FunctionConfig)
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
"Comment")
      Either String (FunctionRuntime -> FunctionConfig)
-> Either String FunctionRuntime -> Either String FunctionConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String FunctionRuntime
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Runtime")

instance Prelude.Hashable FunctionConfig

instance Prelude.NFData FunctionConfig

instance Core.ToXML FunctionConfig where
  toXML :: FunctionConfig -> XML
toXML FunctionConfig' {Text
FunctionRuntime
runtime :: FunctionRuntime
comment :: Text
$sel:runtime:FunctionConfig' :: FunctionConfig -> FunctionRuntime
$sel:comment:FunctionConfig' :: FunctionConfig -> Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Comment" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
comment,
        Name
"Runtime" Name -> FunctionRuntime -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= FunctionRuntime
runtime
      ]