{-# 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.AssociateAssets
-- 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)
--
-- Associates a child asset with the given parent asset through a hierarchy
-- defined in the parent asset\'s model. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/add-associated-assets.html Associating assets>
-- in the /IoT SiteWise User Guide/.
module Amazonka.IoTSiteWise.AssociateAssets
  ( -- * Creating a Request
    AssociateAssets (..),
    newAssociateAssets,

    -- * Request Lenses
    associateAssets_clientToken,
    associateAssets_assetId,
    associateAssets_hierarchyId,
    associateAssets_childAssetId,

    -- * Destructuring the Response
    AssociateAssetsResponse (..),
    newAssociateAssetsResponse,
  )
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:/ 'newAssociateAssets' smart constructor.
data AssociateAssets = AssociateAssets'
  { -- | 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.
    AssociateAssets -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The ID of the parent asset.
    AssociateAssets -> Text
assetId :: Prelude.Text,
    -- | The ID of a hierarchy in the parent asset\'s model. Hierarchies allow
    -- different groupings of assets to be formed that all come from the same
    -- asset model. For more information, see
    -- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-hierarchies.html Asset hierarchies>
    -- in the /IoT SiteWise User Guide/.
    AssociateAssets -> Text
hierarchyId :: Prelude.Text,
    -- | The ID of the child asset to be associated.
    AssociateAssets -> Text
childAssetId :: Prelude.Text
  }
  deriving (AssociateAssets -> AssociateAssets -> Bool
(AssociateAssets -> AssociateAssets -> Bool)
-> (AssociateAssets -> AssociateAssets -> Bool)
-> Eq AssociateAssets
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateAssets -> AssociateAssets -> Bool
$c/= :: AssociateAssets -> AssociateAssets -> Bool
== :: AssociateAssets -> AssociateAssets -> Bool
$c== :: AssociateAssets -> AssociateAssets -> Bool
Prelude.Eq, ReadPrec [AssociateAssets]
ReadPrec AssociateAssets
Int -> ReadS AssociateAssets
ReadS [AssociateAssets]
(Int -> ReadS AssociateAssets)
-> ReadS [AssociateAssets]
-> ReadPrec AssociateAssets
-> ReadPrec [AssociateAssets]
-> Read AssociateAssets
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateAssets]
$creadListPrec :: ReadPrec [AssociateAssets]
readPrec :: ReadPrec AssociateAssets
$creadPrec :: ReadPrec AssociateAssets
readList :: ReadS [AssociateAssets]
$creadList :: ReadS [AssociateAssets]
readsPrec :: Int -> ReadS AssociateAssets
$creadsPrec :: Int -> ReadS AssociateAssets
Prelude.Read, Int -> AssociateAssets -> ShowS
[AssociateAssets] -> ShowS
AssociateAssets -> String
(Int -> AssociateAssets -> ShowS)
-> (AssociateAssets -> String)
-> ([AssociateAssets] -> ShowS)
-> Show AssociateAssets
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateAssets] -> ShowS
$cshowList :: [AssociateAssets] -> ShowS
show :: AssociateAssets -> String
$cshow :: AssociateAssets -> String
showsPrec :: Int -> AssociateAssets -> ShowS
$cshowsPrec :: Int -> AssociateAssets -> ShowS
Prelude.Show, (forall x. AssociateAssets -> Rep AssociateAssets x)
-> (forall x. Rep AssociateAssets x -> AssociateAssets)
-> Generic AssociateAssets
forall x. Rep AssociateAssets x -> AssociateAssets
forall x. AssociateAssets -> Rep AssociateAssets x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateAssets x -> AssociateAssets
$cfrom :: forall x. AssociateAssets -> Rep AssociateAssets x
Prelude.Generic)

-- |
-- Create a value of 'AssociateAssets' 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', 'associateAssets_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', 'associateAssets_assetId' - The ID of the parent asset.
--
-- 'hierarchyId', 'associateAssets_hierarchyId' - The ID of a hierarchy in the parent asset\'s model. Hierarchies allow
-- different groupings of assets to be formed that all come from the same
-- asset model. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-hierarchies.html Asset hierarchies>
-- in the /IoT SiteWise User Guide/.
--
-- 'childAssetId', 'associateAssets_childAssetId' - The ID of the child asset to be associated.
newAssociateAssets ::
  -- | 'assetId'
  Prelude.Text ->
  -- | 'hierarchyId'
  Prelude.Text ->
  -- | 'childAssetId'
  Prelude.Text ->
  AssociateAssets
newAssociateAssets :: Text -> Text -> Text -> AssociateAssets
newAssociateAssets
  Text
pAssetId_
  Text
pHierarchyId_
  Text
pChildAssetId_ =
    AssociateAssets' :: Maybe Text -> Text -> Text -> Text -> AssociateAssets
AssociateAssets'
      { $sel:clientToken:AssociateAssets' :: Maybe Text
clientToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:assetId:AssociateAssets' :: Text
assetId = Text
pAssetId_,
        $sel:hierarchyId:AssociateAssets' :: Text
hierarchyId = Text
pHierarchyId_,
        $sel:childAssetId:AssociateAssets' :: Text
childAssetId = Text
pChildAssetId_
      }

-- | 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.
associateAssets_clientToken :: Lens.Lens' AssociateAssets (Prelude.Maybe Prelude.Text)
associateAssets_clientToken :: (Maybe Text -> f (Maybe Text))
-> AssociateAssets -> f AssociateAssets
associateAssets_clientToken = (AssociateAssets -> Maybe Text)
-> (AssociateAssets -> Maybe Text -> AssociateAssets)
-> Lens AssociateAssets AssociateAssets (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAssets' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:AssociateAssets' :: AssociateAssets -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: AssociateAssets
s@AssociateAssets' {} Maybe Text
a -> AssociateAssets
s {$sel:clientToken:AssociateAssets' :: Maybe Text
clientToken = Maybe Text
a} :: AssociateAssets)

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

-- | The ID of a hierarchy in the parent asset\'s model. Hierarchies allow
-- different groupings of assets to be formed that all come from the same
-- asset model. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-hierarchies.html Asset hierarchies>
-- in the /IoT SiteWise User Guide/.
associateAssets_hierarchyId :: Lens.Lens' AssociateAssets Prelude.Text
associateAssets_hierarchyId :: (Text -> f Text) -> AssociateAssets -> f AssociateAssets
associateAssets_hierarchyId = (AssociateAssets -> Text)
-> (AssociateAssets -> Text -> AssociateAssets)
-> Lens AssociateAssets AssociateAssets Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAssets' {Text
hierarchyId :: Text
$sel:hierarchyId:AssociateAssets' :: AssociateAssets -> Text
hierarchyId} -> Text
hierarchyId) (\s :: AssociateAssets
s@AssociateAssets' {} Text
a -> AssociateAssets
s {$sel:hierarchyId:AssociateAssets' :: Text
hierarchyId = Text
a} :: AssociateAssets)

-- | The ID of the child asset to be associated.
associateAssets_childAssetId :: Lens.Lens' AssociateAssets Prelude.Text
associateAssets_childAssetId :: (Text -> f Text) -> AssociateAssets -> f AssociateAssets
associateAssets_childAssetId = (AssociateAssets -> Text)
-> (AssociateAssets -> Text -> AssociateAssets)
-> Lens AssociateAssets AssociateAssets Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateAssets' {Text
childAssetId :: Text
$sel:childAssetId:AssociateAssets' :: AssociateAssets -> Text
childAssetId} -> Text
childAssetId) (\s :: AssociateAssets
s@AssociateAssets' {} Text
a -> AssociateAssets
s {$sel:childAssetId:AssociateAssets' :: Text
childAssetId = Text
a} :: AssociateAssets)

instance Core.AWSRequest AssociateAssets where
  type
    AWSResponse AssociateAssets =
      AssociateAssetsResponse
  request :: AssociateAssets -> Request AssociateAssets
request = Service -> AssociateAssets -> Request AssociateAssets
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateAssets
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateAssets)))
response =
    AWSResponse AssociateAssets
-> Logger
-> Service
-> Proxy AssociateAssets
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateAssets)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse AssociateAssets
AssociateAssetsResponse
AssociateAssetsResponse'

instance Prelude.Hashable AssociateAssets

instance Prelude.NFData AssociateAssets

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

instance Core.ToJSON AssociateAssets where
  toJSON :: AssociateAssets -> Value
toJSON AssociateAssets' {Maybe Text
Text
childAssetId :: Text
hierarchyId :: Text
assetId :: Text
clientToken :: Maybe Text
$sel:childAssetId:AssociateAssets' :: AssociateAssets -> Text
$sel:hierarchyId:AssociateAssets' :: AssociateAssets -> Text
$sel:assetId:AssociateAssets' :: AssociateAssets -> Text
$sel:clientToken:AssociateAssets' :: AssociateAssets -> 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
"hierarchyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
hierarchyId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"childAssetId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
childAssetId)
          ]
      )

instance Core.ToPath AssociateAssets where
  toPath :: AssociateAssets -> ByteString
toPath AssociateAssets' {Maybe Text
Text
childAssetId :: Text
hierarchyId :: Text
assetId :: Text
clientToken :: Maybe Text
$sel:childAssetId:AssociateAssets' :: AssociateAssets -> Text
$sel:hierarchyId:AssociateAssets' :: AssociateAssets -> Text
$sel:assetId:AssociateAssets' :: AssociateAssets -> Text
$sel:clientToken:AssociateAssets' :: AssociateAssets -> 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, ByteString
"/associate"]

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

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

-- |
-- Create a value of 'AssociateAssetsResponse' 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.
newAssociateAssetsResponse ::
  AssociateAssetsResponse
newAssociateAssetsResponse :: AssociateAssetsResponse
newAssociateAssetsResponse = AssociateAssetsResponse
AssociateAssetsResponse'

instance Prelude.NFData AssociateAssetsResponse