{-# 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.UpdateCoreDefinition
-- 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 core definition.
module Amazonka.Greengrass.UpdateCoreDefinition
  ( -- * Creating a Request
    UpdateCoreDefinition (..),
    newUpdateCoreDefinition,

    -- * Request Lenses
    updateCoreDefinition_name,
    updateCoreDefinition_coreDefinitionId,

    -- * Destructuring the Response
    UpdateCoreDefinitionResponse (..),
    newUpdateCoreDefinitionResponse,

    -- * Response Lenses
    updateCoreDefinitionResponse_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:/ 'newUpdateCoreDefinition' smart constructor.
data UpdateCoreDefinition = UpdateCoreDefinition'
  { -- | The name of the definition.
    UpdateCoreDefinition -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The ID of the core definition.
    UpdateCoreDefinition -> Text
coreDefinitionId :: Prelude.Text
  }
  deriving (UpdateCoreDefinition -> UpdateCoreDefinition -> Bool
(UpdateCoreDefinition -> UpdateCoreDefinition -> Bool)
-> (UpdateCoreDefinition -> UpdateCoreDefinition -> Bool)
-> Eq UpdateCoreDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateCoreDefinition -> UpdateCoreDefinition -> Bool
$c/= :: UpdateCoreDefinition -> UpdateCoreDefinition -> Bool
== :: UpdateCoreDefinition -> UpdateCoreDefinition -> Bool
$c== :: UpdateCoreDefinition -> UpdateCoreDefinition -> Bool
Prelude.Eq, ReadPrec [UpdateCoreDefinition]
ReadPrec UpdateCoreDefinition
Int -> ReadS UpdateCoreDefinition
ReadS [UpdateCoreDefinition]
(Int -> ReadS UpdateCoreDefinition)
-> ReadS [UpdateCoreDefinition]
-> ReadPrec UpdateCoreDefinition
-> ReadPrec [UpdateCoreDefinition]
-> Read UpdateCoreDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateCoreDefinition]
$creadListPrec :: ReadPrec [UpdateCoreDefinition]
readPrec :: ReadPrec UpdateCoreDefinition
$creadPrec :: ReadPrec UpdateCoreDefinition
readList :: ReadS [UpdateCoreDefinition]
$creadList :: ReadS [UpdateCoreDefinition]
readsPrec :: Int -> ReadS UpdateCoreDefinition
$creadsPrec :: Int -> ReadS UpdateCoreDefinition
Prelude.Read, Int -> UpdateCoreDefinition -> ShowS
[UpdateCoreDefinition] -> ShowS
UpdateCoreDefinition -> String
(Int -> UpdateCoreDefinition -> ShowS)
-> (UpdateCoreDefinition -> String)
-> ([UpdateCoreDefinition] -> ShowS)
-> Show UpdateCoreDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateCoreDefinition] -> ShowS
$cshowList :: [UpdateCoreDefinition] -> ShowS
show :: UpdateCoreDefinition -> String
$cshow :: UpdateCoreDefinition -> String
showsPrec :: Int -> UpdateCoreDefinition -> ShowS
$cshowsPrec :: Int -> UpdateCoreDefinition -> ShowS
Prelude.Show, (forall x. UpdateCoreDefinition -> Rep UpdateCoreDefinition x)
-> (forall x. Rep UpdateCoreDefinition x -> UpdateCoreDefinition)
-> Generic UpdateCoreDefinition
forall x. Rep UpdateCoreDefinition x -> UpdateCoreDefinition
forall x. UpdateCoreDefinition -> Rep UpdateCoreDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateCoreDefinition x -> UpdateCoreDefinition
$cfrom :: forall x. UpdateCoreDefinition -> Rep UpdateCoreDefinition x
Prelude.Generic)

-- |
-- Create a value of 'UpdateCoreDefinition' 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', 'updateCoreDefinition_name' - The name of the definition.
--
-- 'coreDefinitionId', 'updateCoreDefinition_coreDefinitionId' - The ID of the core definition.
newUpdateCoreDefinition ::
  -- | 'coreDefinitionId'
  Prelude.Text ->
  UpdateCoreDefinition
newUpdateCoreDefinition :: Text -> UpdateCoreDefinition
newUpdateCoreDefinition Text
pCoreDefinitionId_ =
  UpdateCoreDefinition' :: Maybe Text -> Text -> UpdateCoreDefinition
UpdateCoreDefinition'
    { $sel:name:UpdateCoreDefinition' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:coreDefinitionId:UpdateCoreDefinition' :: Text
coreDefinitionId = Text
pCoreDefinitionId_
    }

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

-- | The ID of the core definition.
updateCoreDefinition_coreDefinitionId :: Lens.Lens' UpdateCoreDefinition Prelude.Text
updateCoreDefinition_coreDefinitionId :: (Text -> f Text) -> UpdateCoreDefinition -> f UpdateCoreDefinition
updateCoreDefinition_coreDefinitionId = (UpdateCoreDefinition -> Text)
-> (UpdateCoreDefinition -> Text -> UpdateCoreDefinition)
-> Lens UpdateCoreDefinition UpdateCoreDefinition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCoreDefinition' {Text
coreDefinitionId :: Text
$sel:coreDefinitionId:UpdateCoreDefinition' :: UpdateCoreDefinition -> Text
coreDefinitionId} -> Text
coreDefinitionId) (\s :: UpdateCoreDefinition
s@UpdateCoreDefinition' {} Text
a -> UpdateCoreDefinition
s {$sel:coreDefinitionId:UpdateCoreDefinition' :: Text
coreDefinitionId = Text
a} :: UpdateCoreDefinition)

instance Core.AWSRequest UpdateCoreDefinition where
  type
    AWSResponse UpdateCoreDefinition =
      UpdateCoreDefinitionResponse
  request :: UpdateCoreDefinition -> Request UpdateCoreDefinition
request = Service -> UpdateCoreDefinition -> Request UpdateCoreDefinition
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateCoreDefinition
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateCoreDefinition)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateCoreDefinition))
-> Logger
-> Service
-> Proxy UpdateCoreDefinition
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateCoreDefinition)))
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 -> UpdateCoreDefinitionResponse
UpdateCoreDefinitionResponse'
            (Int -> UpdateCoreDefinitionResponse)
-> Either String Int -> Either String UpdateCoreDefinitionResponse
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 UpdateCoreDefinition

instance Prelude.NFData UpdateCoreDefinition

instance Core.ToHeaders UpdateCoreDefinition where
  toHeaders :: UpdateCoreDefinition -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateCoreDefinition -> 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 UpdateCoreDefinition where
  toJSON :: UpdateCoreDefinition -> Value
toJSON UpdateCoreDefinition' {Maybe Text
Text
coreDefinitionId :: Text
name :: Maybe Text
$sel:coreDefinitionId:UpdateCoreDefinition' :: UpdateCoreDefinition -> Text
$sel:name:UpdateCoreDefinition' :: UpdateCoreDefinition -> 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 UpdateCoreDefinition where
  toPath :: UpdateCoreDefinition -> ByteString
toPath UpdateCoreDefinition' {Maybe Text
Text
coreDefinitionId :: Text
name :: Maybe Text
$sel:coreDefinitionId:UpdateCoreDefinition' :: UpdateCoreDefinition -> Text
$sel:name:UpdateCoreDefinition' :: UpdateCoreDefinition -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/greengrass/definition/cores/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
coreDefinitionId
      ]

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

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

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

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

instance Prelude.NFData UpdateCoreDefinitionResponse