{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Greengrass.Types.Function where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Greengrass.Types.FunctionConfiguration
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
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]
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
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. 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'
    { $sel:functionArn:Function' :: Maybe Text
functionArn = forall a. Maybe a
Prelude.Nothing,
      $sel:functionConfiguration:Function' :: Maybe FunctionConfiguration
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 :: Lens' Function (Maybe Text)
function_functionArn = 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 :: Lens' Function (Maybe FunctionConfiguration)
function_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 :: Lens' Function Text
function_id = 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 Data.FromJSON Function where
  parseJSON :: Value -> Parser Function
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Function"
      ( \Object
x ->
          Maybe Text -> Maybe FunctionConfiguration -> Text -> Function
Function'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"FunctionArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"FunctionConfiguration")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Id")
      )

instance Prelude.Hashable Function where
  hashWithSalt :: Int -> Function -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
functionArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FunctionConfiguration
functionConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

instance Prelude.NFData Function where
  rnf :: Function -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
functionArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe FunctionConfiguration
functionConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"FunctionArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
functionArn,
            (Key
"FunctionConfiguration" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FunctionConfiguration
functionConfiguration,
            forall a. a -> Maybe a
Prelude.Just (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id)
          ]
      )