{-# 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-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)
--
-- 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 Amazonka.Greengrass.Types
import qualified Amazonka.Lens as Lens
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
(UpdateFunctionDefinition -> UpdateFunctionDefinition -> Bool)
-> (UpdateFunctionDefinition -> UpdateFunctionDefinition -> Bool)
-> Eq UpdateFunctionDefinition
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]
(Int -> ReadS UpdateFunctionDefinition)
-> ReadS [UpdateFunctionDefinition]
-> ReadPrec UpdateFunctionDefinition
-> ReadPrec [UpdateFunctionDefinition]
-> Read 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
(Int -> UpdateFunctionDefinition -> ShowS)
-> (UpdateFunctionDefinition -> String)
-> ([UpdateFunctionDefinition] -> ShowS)
-> Show UpdateFunctionDefinition
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.
 UpdateFunctionDefinition -> Rep UpdateFunctionDefinition x)
-> (forall x.
    Rep UpdateFunctionDefinition x -> UpdateFunctionDefinition)
-> Generic UpdateFunctionDefinition
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' :: Maybe Text -> Text -> UpdateFunctionDefinition
UpdateFunctionDefinition'
    { $sel:name:UpdateFunctionDefinition' :: Maybe Text
name = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> UpdateFunctionDefinition -> f UpdateFunctionDefinition
updateFunctionDefinition_name = (UpdateFunctionDefinition -> Maybe Text)
-> (UpdateFunctionDefinition
    -> Maybe Text -> UpdateFunctionDefinition)
-> Lens
     UpdateFunctionDefinition
     UpdateFunctionDefinition
     (Maybe Text)
     (Maybe Text)
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 :: (Text -> f Text)
-> UpdateFunctionDefinition -> f UpdateFunctionDefinition
updateFunctionDefinition_functionDefinitionId = (UpdateFunctionDefinition -> Text)
-> (UpdateFunctionDefinition -> Text -> UpdateFunctionDefinition)
-> Lens UpdateFunctionDefinition UpdateFunctionDefinition Text Text
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 :: UpdateFunctionDefinition -> Request UpdateFunctionDefinition
request = Service
-> UpdateFunctionDefinition -> Request UpdateFunctionDefinition
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateFunctionDefinition
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateFunctionDefinition)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateFunctionDefinition))
-> Logger
-> Service
-> Proxy UpdateFunctionDefinition
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateFunctionDefinition)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdateFunctionDefinitionResponse
UpdateFunctionDefinitionResponse'
            (Int -> UpdateFunctionDefinitionResponse)
-> Either String Int
-> Either String UpdateFunctionDefinitionResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UpdateFunctionDefinition

instance Prelude.NFData UpdateFunctionDefinition

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

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Name" 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
name]
      )

instance Core.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
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/greengrass/definition/functions/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
functionDefinitionId
      ]

instance Core.ToQuery UpdateFunctionDefinition where
  toQuery :: UpdateFunctionDefinition -> QueryString
toQuery = QueryString -> UpdateFunctionDefinition -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(UpdateFunctionDefinitionResponse
 -> UpdateFunctionDefinitionResponse -> Bool)
-> (UpdateFunctionDefinitionResponse
    -> UpdateFunctionDefinitionResponse -> Bool)
-> Eq UpdateFunctionDefinitionResponse
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]
(Int -> ReadS UpdateFunctionDefinitionResponse)
-> ReadS [UpdateFunctionDefinitionResponse]
-> ReadPrec UpdateFunctionDefinitionResponse
-> ReadPrec [UpdateFunctionDefinitionResponse]
-> Read 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
(Int -> UpdateFunctionDefinitionResponse -> ShowS)
-> (UpdateFunctionDefinitionResponse -> String)
-> ([UpdateFunctionDefinitionResponse] -> ShowS)
-> Show UpdateFunctionDefinitionResponse
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.
 UpdateFunctionDefinitionResponse
 -> Rep UpdateFunctionDefinitionResponse x)
-> (forall x.
    Rep UpdateFunctionDefinitionResponse x
    -> UpdateFunctionDefinitionResponse)
-> Generic UpdateFunctionDefinitionResponse
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' :: Int -> UpdateFunctionDefinitionResponse
UpdateFunctionDefinitionResponse'
    { $sel:httpStatus:UpdateFunctionDefinitionResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
updateFunctionDefinitionResponse_httpStatus :: Lens.Lens' UpdateFunctionDefinitionResponse Prelude.Int
updateFunctionDefinitionResponse_httpStatus :: (Int -> f Int)
-> UpdateFunctionDefinitionResponse
-> f UpdateFunctionDefinitionResponse
updateFunctionDefinitionResponse_httpStatus = (UpdateFunctionDefinitionResponse -> Int)
-> (UpdateFunctionDefinitionResponse
    -> Int -> UpdateFunctionDefinitionResponse)
-> Lens
     UpdateFunctionDefinitionResponse
     UpdateFunctionDefinitionResponse
     Int
     Int
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