{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.UpdateFunctionDefinition
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates a Lambda function definition.
module Amazonka.Greengrass.UpdateFunctionDefinition
  ( -- * Creating a Request
    UpdateFunctionDefinition (..),
    newUpdateFunctionDefinition,

    -- * Request Lenses
    updateFunctionDefinition_name,
    updateFunctionDefinition_functionDefinitionId,

    -- * Destructuring the Response
    UpdateFunctionDefinitionResponse (..),
    newUpdateFunctionDefinitionResponse,

    -- * Response Lenses
    updateFunctionDefinitionResponse_httpStatus,
  )
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
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newUpdateFunctionDefinition' smart constructor.
data UpdateFunctionDefinition = UpdateFunctionDefinition'
  { -- | The name of the definition.
    UpdateFunctionDefinition -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The ID of the Lambda function definition.
    UpdateFunctionDefinition -> Text
functionDefinitionId :: Prelude.Text
  }
  deriving (UpdateFunctionDefinition -> UpdateFunctionDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateFunctionDefinition -> UpdateFunctionDefinition -> Bool
$c/= :: UpdateFunctionDefinition -> UpdateFunctionDefinition -> Bool
== :: UpdateFunctionDefinition -> UpdateFunctionDefinition -> Bool
$c== :: UpdateFunctionDefinition -> UpdateFunctionDefinition -> Bool
Prelude.Eq, ReadPrec [UpdateFunctionDefinition]
ReadPrec UpdateFunctionDefinition
Int -> ReadS UpdateFunctionDefinition
ReadS [UpdateFunctionDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateFunctionDefinition]
$creadListPrec :: ReadPrec [UpdateFunctionDefinition]
readPrec :: ReadPrec UpdateFunctionDefinition
$creadPrec :: ReadPrec UpdateFunctionDefinition
readList :: ReadS [UpdateFunctionDefinition]
$creadList :: ReadS [UpdateFunctionDefinition]
readsPrec :: Int -> ReadS UpdateFunctionDefinition
$creadsPrec :: Int -> ReadS UpdateFunctionDefinition
Prelude.Read, Int -> UpdateFunctionDefinition -> ShowS
[UpdateFunctionDefinition] -> ShowS
UpdateFunctionDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateFunctionDefinition] -> ShowS
$cshowList :: [UpdateFunctionDefinition] -> ShowS
show :: UpdateFunctionDefinition -> String
$cshow :: UpdateFunctionDefinition -> String
showsPrec :: Int -> UpdateFunctionDefinition -> ShowS
$cshowsPrec :: Int -> UpdateFunctionDefinition -> ShowS
Prelude.Show, forall x.
Rep UpdateFunctionDefinition x -> UpdateFunctionDefinition
forall x.
UpdateFunctionDefinition -> Rep UpdateFunctionDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateFunctionDefinition x -> UpdateFunctionDefinition
$cfrom :: forall x.
UpdateFunctionDefinition -> Rep UpdateFunctionDefinition x
Prelude.Generic)

-- |
-- Create a value of 'UpdateFunctionDefinition' 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:
--
-- 'name', 'updateFunctionDefinition_name' - The name of the definition.
--
-- 'functionDefinitionId', 'updateFunctionDefinition_functionDefinitionId' - The ID of the Lambda function definition.
newUpdateFunctionDefinition ::
  -- | 'functionDefinitionId'
  Prelude.Text ->
  UpdateFunctionDefinition
newUpdateFunctionDefinition :: Text -> UpdateFunctionDefinition
newUpdateFunctionDefinition Text
pFunctionDefinitionId_ =
  UpdateFunctionDefinition'
    { $sel:name:UpdateFunctionDefinition' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:functionDefinitionId:UpdateFunctionDefinition' :: Text
functionDefinitionId = Text
pFunctionDefinitionId_
    }

-- | The name of the definition.
updateFunctionDefinition_name :: Lens.Lens' UpdateFunctionDefinition (Prelude.Maybe Prelude.Text)
updateFunctionDefinition_name :: Lens' UpdateFunctionDefinition (Maybe Text)
updateFunctionDefinition_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateFunctionDefinition' {Maybe Text
name :: Maybe Text
$sel:name:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Maybe Text
name} -> Maybe Text
name) (\s :: UpdateFunctionDefinition
s@UpdateFunctionDefinition' {} Maybe Text
a -> UpdateFunctionDefinition
s {$sel:name:UpdateFunctionDefinition' :: Maybe Text
name = Maybe Text
a} :: UpdateFunctionDefinition)

-- | The ID of the Lambda function definition.
updateFunctionDefinition_functionDefinitionId :: Lens.Lens' UpdateFunctionDefinition Prelude.Text
updateFunctionDefinition_functionDefinitionId :: Lens' UpdateFunctionDefinition Text
updateFunctionDefinition_functionDefinitionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateFunctionDefinition' {Text
functionDefinitionId :: Text
$sel:functionDefinitionId:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Text
functionDefinitionId} -> Text
functionDefinitionId) (\s :: UpdateFunctionDefinition
s@UpdateFunctionDefinition' {} Text
a -> UpdateFunctionDefinition
s {$sel:functionDefinitionId:UpdateFunctionDefinition' :: Text
functionDefinitionId = Text
a} :: UpdateFunctionDefinition)

instance Core.AWSRequest UpdateFunctionDefinition where
  type
    AWSResponse UpdateFunctionDefinition =
      UpdateFunctionDefinitionResponse
  request :: (Service -> Service)
-> UpdateFunctionDefinition -> Request UpdateFunctionDefinition
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateFunctionDefinition
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateFunctionDefinition)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdateFunctionDefinitionResponse
UpdateFunctionDefinitionResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UpdateFunctionDefinition where
  hashWithSalt :: Int -> UpdateFunctionDefinition -> Int
hashWithSalt Int
_salt UpdateFunctionDefinition' {Maybe Text
Text
functionDefinitionId :: Text
name :: Maybe Text
$sel:functionDefinitionId:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Text
$sel:name:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
functionDefinitionId

instance Prelude.NFData UpdateFunctionDefinition where
  rnf :: UpdateFunctionDefinition -> ()
rnf UpdateFunctionDefinition' {Maybe Text
Text
functionDefinitionId :: Text
name :: Maybe Text
$sel:functionDefinitionId:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Text
$sel:name:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
functionDefinitionId

instance Data.ToHeaders UpdateFunctionDefinition where
  toHeaders :: UpdateFunctionDefinition -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON UpdateFunctionDefinition where
  toJSON :: UpdateFunctionDefinition -> Value
toJSON UpdateFunctionDefinition' {Maybe Text
Text
functionDefinitionId :: Text
name :: Maybe Text
$sel:functionDefinitionId:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Text
$sel:name:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"Name" 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
name]
      )

instance Data.ToPath UpdateFunctionDefinition where
  toPath :: UpdateFunctionDefinition -> ByteString
toPath UpdateFunctionDefinition' {Maybe Text
Text
functionDefinitionId :: Text
name :: Maybe Text
$sel:functionDefinitionId:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Text
$sel:name:UpdateFunctionDefinition' :: UpdateFunctionDefinition -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/greengrass/definition/functions/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
functionDefinitionId
      ]

instance Data.ToQuery UpdateFunctionDefinition where
  toQuery :: UpdateFunctionDefinition -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newUpdateFunctionDefinitionResponse' smart constructor.
data UpdateFunctionDefinitionResponse = UpdateFunctionDefinitionResponse'
  { -- | The response's http status code.
    UpdateFunctionDefinitionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateFunctionDefinitionResponse
-> UpdateFunctionDefinitionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateFunctionDefinitionResponse
-> UpdateFunctionDefinitionResponse -> Bool
$c/= :: UpdateFunctionDefinitionResponse
-> UpdateFunctionDefinitionResponse -> Bool
== :: UpdateFunctionDefinitionResponse
-> UpdateFunctionDefinitionResponse -> Bool
$c== :: UpdateFunctionDefinitionResponse
-> UpdateFunctionDefinitionResponse -> Bool
Prelude.Eq, ReadPrec [UpdateFunctionDefinitionResponse]
ReadPrec UpdateFunctionDefinitionResponse
Int -> ReadS UpdateFunctionDefinitionResponse
ReadS [UpdateFunctionDefinitionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateFunctionDefinitionResponse]
$creadListPrec :: ReadPrec [UpdateFunctionDefinitionResponse]
readPrec :: ReadPrec UpdateFunctionDefinitionResponse
$creadPrec :: ReadPrec UpdateFunctionDefinitionResponse
readList :: ReadS [UpdateFunctionDefinitionResponse]
$creadList :: ReadS [UpdateFunctionDefinitionResponse]
readsPrec :: Int -> ReadS UpdateFunctionDefinitionResponse
$creadsPrec :: Int -> ReadS UpdateFunctionDefinitionResponse
Prelude.Read, Int -> UpdateFunctionDefinitionResponse -> ShowS
[UpdateFunctionDefinitionResponse] -> ShowS
UpdateFunctionDefinitionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateFunctionDefinitionResponse] -> ShowS
$cshowList :: [UpdateFunctionDefinitionResponse] -> ShowS
show :: UpdateFunctionDefinitionResponse -> String
$cshow :: UpdateFunctionDefinitionResponse -> String
showsPrec :: Int -> UpdateFunctionDefinitionResponse -> ShowS
$cshowsPrec :: Int -> UpdateFunctionDefinitionResponse -> ShowS
Prelude.Show, forall x.
Rep UpdateFunctionDefinitionResponse x
-> UpdateFunctionDefinitionResponse
forall x.
UpdateFunctionDefinitionResponse
-> Rep UpdateFunctionDefinitionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateFunctionDefinitionResponse x
-> UpdateFunctionDefinitionResponse
$cfrom :: forall x.
UpdateFunctionDefinitionResponse
-> Rep UpdateFunctionDefinitionResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateFunctionDefinitionResponse' 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:
--
-- 'httpStatus', 'updateFunctionDefinitionResponse_httpStatus' - The response's http status code.
newUpdateFunctionDefinitionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateFunctionDefinitionResponse
newUpdateFunctionDefinitionResponse :: Int -> UpdateFunctionDefinitionResponse
newUpdateFunctionDefinitionResponse Int
pHttpStatus_ =
  UpdateFunctionDefinitionResponse'
    { $sel:httpStatus:UpdateFunctionDefinitionResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
updateFunctionDefinitionResponse_httpStatus :: Lens.Lens' UpdateFunctionDefinitionResponse Prelude.Int
updateFunctionDefinitionResponse_httpStatus :: Lens' UpdateFunctionDefinitionResponse Int
updateFunctionDefinitionResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateFunctionDefinitionResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateFunctionDefinitionResponse' :: UpdateFunctionDefinitionResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: UpdateFunctionDefinitionResponse
s@UpdateFunctionDefinitionResponse' {} Int
a -> UpdateFunctionDefinitionResponse
s {$sel:httpStatus:UpdateFunctionDefinitionResponse' :: Int
httpStatus = Int
a} :: UpdateFunctionDefinitionResponse)

instance
  Prelude.NFData
    UpdateFunctionDefinitionResponse
  where
  rnf :: UpdateFunctionDefinitionResponse -> ()
rnf UpdateFunctionDefinitionResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateFunctionDefinitionResponse' :: UpdateFunctionDefinitionResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus