{-# 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.IoTSiteWise.UpdateAsset
-- 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 an asset\'s name. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/update-assets-and-models.html Updating assets and models>
-- in the /IoT SiteWise User Guide/.
module Amazonka.IoTSiteWise.UpdateAsset
  ( -- * Creating a Request
    UpdateAsset (..),
    newUpdateAsset,

    -- * Request Lenses
    updateAsset_clientToken,
    updateAsset_assetId,
    updateAsset_assetName,

    -- * Destructuring the Response
    UpdateAssetResponse (..),
    newUpdateAssetResponse,

    -- * Response Lenses
    updateAssetResponse_httpStatus,
    updateAssetResponse_assetStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.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:/ 'newUpdateAsset' smart constructor.
data UpdateAsset = UpdateAsset'
  { -- | A unique case-sensitive identifier that you can provide to ensure the
    -- idempotency of the request. Don\'t reuse this client token if a new
    -- idempotent request is required.
    UpdateAsset -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The ID of the asset to update.
    UpdateAsset -> Text
assetId :: Prelude.Text,
    -- | A unique, friendly name for the asset.
    UpdateAsset -> Text
assetName :: Prelude.Text
  }
  deriving (UpdateAsset -> UpdateAsset -> Bool
(UpdateAsset -> UpdateAsset -> Bool)
-> (UpdateAsset -> UpdateAsset -> Bool) -> Eq UpdateAsset
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateAsset -> UpdateAsset -> Bool
$c/= :: UpdateAsset -> UpdateAsset -> Bool
== :: UpdateAsset -> UpdateAsset -> Bool
$c== :: UpdateAsset -> UpdateAsset -> Bool
Prelude.Eq, ReadPrec [UpdateAsset]
ReadPrec UpdateAsset
Int -> ReadS UpdateAsset
ReadS [UpdateAsset]
(Int -> ReadS UpdateAsset)
-> ReadS [UpdateAsset]
-> ReadPrec UpdateAsset
-> ReadPrec [UpdateAsset]
-> Read UpdateAsset
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateAsset]
$creadListPrec :: ReadPrec [UpdateAsset]
readPrec :: ReadPrec UpdateAsset
$creadPrec :: ReadPrec UpdateAsset
readList :: ReadS [UpdateAsset]
$creadList :: ReadS [UpdateAsset]
readsPrec :: Int -> ReadS UpdateAsset
$creadsPrec :: Int -> ReadS UpdateAsset
Prelude.Read, Int -> UpdateAsset -> ShowS
[UpdateAsset] -> ShowS
UpdateAsset -> String
(Int -> UpdateAsset -> ShowS)
-> (UpdateAsset -> String)
-> ([UpdateAsset] -> ShowS)
-> Show UpdateAsset
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateAsset] -> ShowS
$cshowList :: [UpdateAsset] -> ShowS
show :: UpdateAsset -> String
$cshow :: UpdateAsset -> String
showsPrec :: Int -> UpdateAsset -> ShowS
$cshowsPrec :: Int -> UpdateAsset -> ShowS
Prelude.Show, (forall x. UpdateAsset -> Rep UpdateAsset x)
-> (forall x. Rep UpdateAsset x -> UpdateAsset)
-> Generic UpdateAsset
forall x. Rep UpdateAsset x -> UpdateAsset
forall x. UpdateAsset -> Rep UpdateAsset x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateAsset x -> UpdateAsset
$cfrom :: forall x. UpdateAsset -> Rep UpdateAsset x
Prelude.Generic)

-- |
-- Create a value of 'UpdateAsset' 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:
--
-- 'clientToken', 'updateAsset_clientToken' - A unique case-sensitive identifier that you can provide to ensure the
-- idempotency of the request. Don\'t reuse this client token if a new
-- idempotent request is required.
--
-- 'assetId', 'updateAsset_assetId' - The ID of the asset to update.
--
-- 'assetName', 'updateAsset_assetName' - A unique, friendly name for the asset.
newUpdateAsset ::
  -- | 'assetId'
  Prelude.Text ->
  -- | 'assetName'
  Prelude.Text ->
  UpdateAsset
newUpdateAsset :: Text -> Text -> UpdateAsset
newUpdateAsset Text
pAssetId_ Text
pAssetName_ =
  UpdateAsset' :: Maybe Text -> Text -> Text -> UpdateAsset
UpdateAsset'
    { $sel:clientToken:UpdateAsset' :: Maybe Text
clientToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:assetId:UpdateAsset' :: Text
assetId = Text
pAssetId_,
      $sel:assetName:UpdateAsset' :: Text
assetName = Text
pAssetName_
    }

-- | A unique case-sensitive identifier that you can provide to ensure the
-- idempotency of the request. Don\'t reuse this client token if a new
-- idempotent request is required.
updateAsset_clientToken :: Lens.Lens' UpdateAsset (Prelude.Maybe Prelude.Text)
updateAsset_clientToken :: (Maybe Text -> f (Maybe Text)) -> UpdateAsset -> f UpdateAsset
updateAsset_clientToken = (UpdateAsset -> Maybe Text)
-> (UpdateAsset -> Maybe Text -> UpdateAsset)
-> Lens UpdateAsset UpdateAsset (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAsset' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:UpdateAsset' :: UpdateAsset -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: UpdateAsset
s@UpdateAsset' {} Maybe Text
a -> UpdateAsset
s {$sel:clientToken:UpdateAsset' :: Maybe Text
clientToken = Maybe Text
a} :: UpdateAsset)

-- | The ID of the asset to update.
updateAsset_assetId :: Lens.Lens' UpdateAsset Prelude.Text
updateAsset_assetId :: (Text -> f Text) -> UpdateAsset -> f UpdateAsset
updateAsset_assetId = (UpdateAsset -> Text)
-> (UpdateAsset -> Text -> UpdateAsset)
-> Lens UpdateAsset UpdateAsset Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAsset' {Text
assetId :: Text
$sel:assetId:UpdateAsset' :: UpdateAsset -> Text
assetId} -> Text
assetId) (\s :: UpdateAsset
s@UpdateAsset' {} Text
a -> UpdateAsset
s {$sel:assetId:UpdateAsset' :: Text
assetId = Text
a} :: UpdateAsset)

-- | A unique, friendly name for the asset.
updateAsset_assetName :: Lens.Lens' UpdateAsset Prelude.Text
updateAsset_assetName :: (Text -> f Text) -> UpdateAsset -> f UpdateAsset
updateAsset_assetName = (UpdateAsset -> Text)
-> (UpdateAsset -> Text -> UpdateAsset)
-> Lens UpdateAsset UpdateAsset Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAsset' {Text
assetName :: Text
$sel:assetName:UpdateAsset' :: UpdateAsset -> Text
assetName} -> Text
assetName) (\s :: UpdateAsset
s@UpdateAsset' {} Text
a -> UpdateAsset
s {$sel:assetName:UpdateAsset' :: Text
assetName = Text
a} :: UpdateAsset)

instance Core.AWSRequest UpdateAsset where
  type AWSResponse UpdateAsset = UpdateAssetResponse
  request :: UpdateAsset -> Request UpdateAsset
request = Service -> UpdateAsset -> Request UpdateAsset
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateAsset
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateAsset)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateAsset))
-> Logger
-> Service
-> Proxy UpdateAsset
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateAsset)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> AssetStatus -> UpdateAssetResponse
UpdateAssetResponse'
            (Int -> AssetStatus -> UpdateAssetResponse)
-> Either String Int
-> Either String (AssetStatus -> UpdateAssetResponse)
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))
            Either String (AssetStatus -> UpdateAssetResponse)
-> Either String AssetStatus -> Either String UpdateAssetResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String AssetStatus
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"assetStatus")
      )

instance Prelude.Hashable UpdateAsset

instance Prelude.NFData UpdateAsset

instance Core.ToHeaders UpdateAsset where
  toHeaders :: UpdateAsset -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateAsset -> 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 UpdateAsset where
  toJSON :: UpdateAsset -> Value
toJSON UpdateAsset' {Maybe Text
Text
assetName :: Text
assetId :: Text
clientToken :: Maybe Text
$sel:assetName:UpdateAsset' :: UpdateAsset -> Text
$sel:assetId:UpdateAsset' :: UpdateAsset -> Text
$sel:clientToken:UpdateAsset' :: UpdateAsset -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"clientToken" 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
clientToken,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"assetName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
assetName)
          ]
      )

instance Core.ToPath UpdateAsset where
  toPath :: UpdateAsset -> ByteString
toPath UpdateAsset' {Maybe Text
Text
assetName :: Text
assetId :: Text
clientToken :: Maybe Text
$sel:assetName:UpdateAsset' :: UpdateAsset -> Text
$sel:assetId:UpdateAsset' :: UpdateAsset -> Text
$sel:clientToken:UpdateAsset' :: UpdateAsset -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/assets/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
assetId]

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

-- | /See:/ 'newUpdateAssetResponse' smart constructor.
data UpdateAssetResponse = UpdateAssetResponse'
  { -- | The response's http status code.
    UpdateAssetResponse -> Int
httpStatus :: Prelude.Int,
    -- | The status of the asset, which contains a state (@UPDATING@ after
    -- successfully calling this operation) and any error message.
    UpdateAssetResponse -> AssetStatus
assetStatus :: AssetStatus
  }
  deriving (UpdateAssetResponse -> UpdateAssetResponse -> Bool
(UpdateAssetResponse -> UpdateAssetResponse -> Bool)
-> (UpdateAssetResponse -> UpdateAssetResponse -> Bool)
-> Eq UpdateAssetResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateAssetResponse -> UpdateAssetResponse -> Bool
$c/= :: UpdateAssetResponse -> UpdateAssetResponse -> Bool
== :: UpdateAssetResponse -> UpdateAssetResponse -> Bool
$c== :: UpdateAssetResponse -> UpdateAssetResponse -> Bool
Prelude.Eq, ReadPrec [UpdateAssetResponse]
ReadPrec UpdateAssetResponse
Int -> ReadS UpdateAssetResponse
ReadS [UpdateAssetResponse]
(Int -> ReadS UpdateAssetResponse)
-> ReadS [UpdateAssetResponse]
-> ReadPrec UpdateAssetResponse
-> ReadPrec [UpdateAssetResponse]
-> Read UpdateAssetResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateAssetResponse]
$creadListPrec :: ReadPrec [UpdateAssetResponse]
readPrec :: ReadPrec UpdateAssetResponse
$creadPrec :: ReadPrec UpdateAssetResponse
readList :: ReadS [UpdateAssetResponse]
$creadList :: ReadS [UpdateAssetResponse]
readsPrec :: Int -> ReadS UpdateAssetResponse
$creadsPrec :: Int -> ReadS UpdateAssetResponse
Prelude.Read, Int -> UpdateAssetResponse -> ShowS
[UpdateAssetResponse] -> ShowS
UpdateAssetResponse -> String
(Int -> UpdateAssetResponse -> ShowS)
-> (UpdateAssetResponse -> String)
-> ([UpdateAssetResponse] -> ShowS)
-> Show UpdateAssetResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateAssetResponse] -> ShowS
$cshowList :: [UpdateAssetResponse] -> ShowS
show :: UpdateAssetResponse -> String
$cshow :: UpdateAssetResponse -> String
showsPrec :: Int -> UpdateAssetResponse -> ShowS
$cshowsPrec :: Int -> UpdateAssetResponse -> ShowS
Prelude.Show, (forall x. UpdateAssetResponse -> Rep UpdateAssetResponse x)
-> (forall x. Rep UpdateAssetResponse x -> UpdateAssetResponse)
-> Generic UpdateAssetResponse
forall x. Rep UpdateAssetResponse x -> UpdateAssetResponse
forall x. UpdateAssetResponse -> Rep UpdateAssetResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateAssetResponse x -> UpdateAssetResponse
$cfrom :: forall x. UpdateAssetResponse -> Rep UpdateAssetResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateAssetResponse' 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', 'updateAssetResponse_httpStatus' - The response's http status code.
--
-- 'assetStatus', 'updateAssetResponse_assetStatus' - The status of the asset, which contains a state (@UPDATING@ after
-- successfully calling this operation) and any error message.
newUpdateAssetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'assetStatus'
  AssetStatus ->
  UpdateAssetResponse
newUpdateAssetResponse :: Int -> AssetStatus -> UpdateAssetResponse
newUpdateAssetResponse Int
pHttpStatus_ AssetStatus
pAssetStatus_ =
  UpdateAssetResponse' :: Int -> AssetStatus -> UpdateAssetResponse
UpdateAssetResponse'
    { $sel:httpStatus:UpdateAssetResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:assetStatus:UpdateAssetResponse' :: AssetStatus
assetStatus = AssetStatus
pAssetStatus_
    }

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

-- | The status of the asset, which contains a state (@UPDATING@ after
-- successfully calling this operation) and any error message.
updateAssetResponse_assetStatus :: Lens.Lens' UpdateAssetResponse AssetStatus
updateAssetResponse_assetStatus :: (AssetStatus -> f AssetStatus)
-> UpdateAssetResponse -> f UpdateAssetResponse
updateAssetResponse_assetStatus = (UpdateAssetResponse -> AssetStatus)
-> (UpdateAssetResponse -> AssetStatus -> UpdateAssetResponse)
-> Lens
     UpdateAssetResponse UpdateAssetResponse AssetStatus AssetStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAssetResponse' {AssetStatus
assetStatus :: AssetStatus
$sel:assetStatus:UpdateAssetResponse' :: UpdateAssetResponse -> AssetStatus
assetStatus} -> AssetStatus
assetStatus) (\s :: UpdateAssetResponse
s@UpdateAssetResponse' {} AssetStatus
a -> UpdateAssetResponse
s {$sel:assetStatus:UpdateAssetResponse' :: AssetStatus
assetStatus = AssetStatus
a} :: UpdateAssetResponse)

instance Prelude.NFData UpdateAssetResponse