{-# 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.Greengrass.Types.Function
-- 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.Greengrass.Types.Function where

import qualified Amazonka.Core as Core
import Amazonka.Greengrass.Types.FunctionConfiguration
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a Lambda function.
--
-- /See:/ 'newFunction' smart constructor.
data Function = Function'
  { -- | The ARN of the Lambda function.
    Function -> Maybe Text
functionArn :: Prelude.Maybe Prelude.Text,
    -- | The configuration of the Lambda function.
    Function -> Maybe FunctionConfiguration
functionConfiguration :: Prelude.Maybe FunctionConfiguration,
    -- | A descriptive or arbitrary ID for the function. This value must be
    -- unique within the function definition version. Max length is 128
    -- characters with pattern \'\'[a-zA-Z0-9:_-]+\'\'.
    Function -> Text
id :: Prelude.Text
  }
  deriving (Function -> Function -> Bool
(Function -> Function -> Bool)
-> (Function -> Function -> Bool) -> Eq Function
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Function -> Function -> Bool
$c/= :: Function -> Function -> Bool
== :: Function -> Function -> Bool
$c== :: Function -> Function -> Bool
Prelude.Eq, ReadPrec [Function]
ReadPrec Function
Int -> ReadS Function
ReadS [Function]
(Int -> ReadS Function)
-> ReadS [Function]
-> ReadPrec Function
-> ReadPrec [Function]
-> Read Function
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Function]
$creadListPrec :: ReadPrec [Function]
readPrec :: ReadPrec Function
$creadPrec :: ReadPrec Function
readList :: ReadS [Function]
$creadList :: ReadS [Function]
readsPrec :: Int -> ReadS Function
$creadsPrec :: Int -> ReadS Function
Prelude.Read, Int -> Function -> ShowS
[Function] -> ShowS
Function -> String
(Int -> Function -> ShowS)
-> (Function -> String) -> ([Function] -> ShowS) -> Show Function
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Function] -> ShowS
$cshowList :: [Function] -> ShowS
show :: Function -> String
$cshow :: Function -> String
showsPrec :: Int -> Function -> ShowS
$cshowsPrec :: Int -> Function -> ShowS
Prelude.Show, (forall x. Function -> Rep Function x)
-> (forall x. Rep Function x -> Function) -> Generic Function
forall x. Rep Function x -> Function
forall x. Function -> Rep Function x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Function x -> Function
$cfrom :: forall x. Function -> Rep Function x
Prelude.Generic)

-- |
-- Create a value of 'Function' 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', 'function_functionArn' - The ARN of the Lambda function.
--
-- 'functionConfiguration', 'function_functionConfiguration' - The configuration of the Lambda function.
--
-- 'id', 'function_id' - A descriptive or arbitrary ID for the function. This value must be
-- unique within the function definition version. Max length is 128
-- characters with pattern \'\'[a-zA-Z0-9:_-]+\'\'.
newFunction ::
  -- | 'id'
  Prelude.Text ->
  Function
newFunction :: Text -> Function
newFunction Text
pId_ =
  Function' :: Maybe Text -> Maybe FunctionConfiguration -> Text -> Function
Function'
    { $sel:functionArn:Function' :: Maybe Text
functionArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionConfiguration:Function' :: Maybe FunctionConfiguration
functionConfiguration = Maybe FunctionConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Function' :: Text
id = Text
pId_
    }

-- | The ARN of the Lambda function.
function_functionArn :: Lens.Lens' Function (Prelude.Maybe Prelude.Text)
function_functionArn :: (Maybe Text -> f (Maybe Text)) -> Function -> f Function
function_functionArn = (Function -> Maybe Text)
-> (Function -> Maybe Text -> Function)
-> Lens Function Function (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Function' {Maybe Text
functionArn :: Maybe Text
$sel:functionArn:Function' :: Function -> Maybe Text
functionArn} -> Maybe Text
functionArn) (\s :: Function
s@Function' {} Maybe Text
a -> Function
s {$sel:functionArn:Function' :: Maybe Text
functionArn = Maybe Text
a} :: Function)

-- | The configuration of the Lambda function.
function_functionConfiguration :: Lens.Lens' Function (Prelude.Maybe FunctionConfiguration)
function_functionConfiguration :: (Maybe FunctionConfiguration -> f (Maybe FunctionConfiguration))
-> Function -> f Function
function_functionConfiguration = (Function -> Maybe FunctionConfiguration)
-> (Function -> Maybe FunctionConfiguration -> Function)
-> Lens
     Function
     Function
     (Maybe FunctionConfiguration)
     (Maybe FunctionConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Function' {Maybe FunctionConfiguration
functionConfiguration :: Maybe FunctionConfiguration
$sel:functionConfiguration:Function' :: Function -> Maybe FunctionConfiguration
functionConfiguration} -> Maybe FunctionConfiguration
functionConfiguration) (\s :: Function
s@Function' {} Maybe FunctionConfiguration
a -> Function
s {$sel:functionConfiguration:Function' :: Maybe FunctionConfiguration
functionConfiguration = Maybe FunctionConfiguration
a} :: Function)

-- | A descriptive or arbitrary ID for the function. This value must be
-- unique within the function definition version. Max length is 128
-- characters with pattern \'\'[a-zA-Z0-9:_-]+\'\'.
function_id :: Lens.Lens' Function Prelude.Text
function_id :: (Text -> f Text) -> Function -> f Function
function_id = (Function -> Text)
-> (Function -> Text -> Function)
-> Lens Function Function Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Function' {Text
id :: Text
$sel:id:Function' :: Function -> Text
id} -> Text
id) (\s :: Function
s@Function' {} Text
a -> Function
s {$sel:id:Function' :: Text
id = Text
a} :: Function)

instance Core.FromJSON Function where
  parseJSON :: Value -> Parser Function
parseJSON =
    String -> (Object -> Parser Function) -> Value -> Parser Function
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Function"
      ( \Object
x ->
          Maybe Text -> Maybe FunctionConfiguration -> Text -> Function
Function'
            (Maybe Text -> Maybe FunctionConfiguration -> Text -> Function)
-> Parser (Maybe Text)
-> Parser (Maybe FunctionConfiguration -> Text -> Function)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"FunctionArn")
            Parser (Maybe FunctionConfiguration -> Text -> Function)
-> Parser (Maybe FunctionConfiguration)
-> Parser (Text -> Function)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe FunctionConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"FunctionConfiguration")
            Parser (Text -> Function) -> Parser Text -> Parser Function
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Id")
      )

instance Prelude.Hashable Function

instance Prelude.NFData Function

instance Core.ToJSON Function where
  toJSON :: Function -> Value
toJSON Function' {Maybe Text
Maybe FunctionConfiguration
Text
id :: Text
functionConfiguration :: Maybe FunctionConfiguration
functionArn :: Maybe Text
$sel:id:Function' :: Function -> Text
$sel:functionConfiguration:Function' :: Function -> Maybe FunctionConfiguration
$sel:functionArn:Function' :: Function -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"FunctionArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
functionArn,
            (Text
"FunctionConfiguration" Text -> FunctionConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (FunctionConfiguration -> Pair)
-> Maybe FunctionConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FunctionConfiguration
functionConfiguration,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id)
          ]
      )