{-# 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.NetworkManager.AssociateLink
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Associates a link to a device. A device can be associated to multiple
-- links and a link can be associated to multiple devices. The device and
-- link must be in the same global network and the same site.
module Amazonka.NetworkManager.AssociateLink
  ( -- * Creating a Request
    AssociateLink (..),
    newAssociateLink,

    -- * Request Lenses
    associateLink_globalNetworkId,
    associateLink_deviceId,
    associateLink_linkId,

    -- * Destructuring the Response
    AssociateLinkResponse (..),
    newAssociateLinkResponse,

    -- * Response Lenses
    associateLinkResponse_linkAssociation,
    associateLinkResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.NetworkManager.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociateLink' smart constructor.
data AssociateLink = AssociateLink'
  { -- | The ID of the global network.
    AssociateLink -> Text
globalNetworkId :: Prelude.Text,
    -- | The ID of the device.
    AssociateLink -> Text
deviceId :: Prelude.Text,
    -- | The ID of the link.
    AssociateLink -> Text
linkId :: Prelude.Text
  }
  deriving (AssociateLink -> AssociateLink -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateLink -> AssociateLink -> Bool
$c/= :: AssociateLink -> AssociateLink -> Bool
== :: AssociateLink -> AssociateLink -> Bool
$c== :: AssociateLink -> AssociateLink -> Bool
Prelude.Eq, ReadPrec [AssociateLink]
ReadPrec AssociateLink
Int -> ReadS AssociateLink
ReadS [AssociateLink]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateLink]
$creadListPrec :: ReadPrec [AssociateLink]
readPrec :: ReadPrec AssociateLink
$creadPrec :: ReadPrec AssociateLink
readList :: ReadS [AssociateLink]
$creadList :: ReadS [AssociateLink]
readsPrec :: Int -> ReadS AssociateLink
$creadsPrec :: Int -> ReadS AssociateLink
Prelude.Read, Int -> AssociateLink -> ShowS
[AssociateLink] -> ShowS
AssociateLink -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateLink] -> ShowS
$cshowList :: [AssociateLink] -> ShowS
show :: AssociateLink -> String
$cshow :: AssociateLink -> String
showsPrec :: Int -> AssociateLink -> ShowS
$cshowsPrec :: Int -> AssociateLink -> ShowS
Prelude.Show, forall x. Rep AssociateLink x -> AssociateLink
forall x. AssociateLink -> Rep AssociateLink x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateLink x -> AssociateLink
$cfrom :: forall x. AssociateLink -> Rep AssociateLink x
Prelude.Generic)

-- |
-- Create a value of 'AssociateLink' 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:
--
-- 'globalNetworkId', 'associateLink_globalNetworkId' - The ID of the global network.
--
-- 'deviceId', 'associateLink_deviceId' - The ID of the device.
--
-- 'linkId', 'associateLink_linkId' - The ID of the link.
newAssociateLink ::
  -- | 'globalNetworkId'
  Prelude.Text ->
  -- | 'deviceId'
  Prelude.Text ->
  -- | 'linkId'
  Prelude.Text ->
  AssociateLink
newAssociateLink :: Text -> Text -> Text -> AssociateLink
newAssociateLink
  Text
pGlobalNetworkId_
  Text
pDeviceId_
  Text
pLinkId_ =
    AssociateLink'
      { $sel:globalNetworkId:AssociateLink' :: Text
globalNetworkId = Text
pGlobalNetworkId_,
        $sel:deviceId:AssociateLink' :: Text
deviceId = Text
pDeviceId_,
        $sel:linkId:AssociateLink' :: Text
linkId = Text
pLinkId_
      }

-- | The ID of the global network.
associateLink_globalNetworkId :: Lens.Lens' AssociateLink Prelude.Text
associateLink_globalNetworkId :: Lens' AssociateLink Text
associateLink_globalNetworkId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateLink' {Text
globalNetworkId :: Text
$sel:globalNetworkId:AssociateLink' :: AssociateLink -> Text
globalNetworkId} -> Text
globalNetworkId) (\s :: AssociateLink
s@AssociateLink' {} Text
a -> AssociateLink
s {$sel:globalNetworkId:AssociateLink' :: Text
globalNetworkId = Text
a} :: AssociateLink)

-- | The ID of the device.
associateLink_deviceId :: Lens.Lens' AssociateLink Prelude.Text
associateLink_deviceId :: Lens' AssociateLink Text
associateLink_deviceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateLink' {Text
deviceId :: Text
$sel:deviceId:AssociateLink' :: AssociateLink -> Text
deviceId} -> Text
deviceId) (\s :: AssociateLink
s@AssociateLink' {} Text
a -> AssociateLink
s {$sel:deviceId:AssociateLink' :: Text
deviceId = Text
a} :: AssociateLink)

-- | The ID of the link.
associateLink_linkId :: Lens.Lens' AssociateLink Prelude.Text
associateLink_linkId :: Lens' AssociateLink Text
associateLink_linkId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateLink' {Text
linkId :: Text
$sel:linkId:AssociateLink' :: AssociateLink -> Text
linkId} -> Text
linkId) (\s :: AssociateLink
s@AssociateLink' {} Text
a -> AssociateLink
s {$sel:linkId:AssociateLink' :: Text
linkId = Text
a} :: AssociateLink)

instance Core.AWSRequest AssociateLink where
  type
    AWSResponse AssociateLink =
      AssociateLinkResponse
  request :: (Service -> Service) -> AssociateLink -> Request AssociateLink
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateLink
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateLink)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe LinkAssociation -> Int -> AssociateLinkResponse
AssociateLinkResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"LinkAssociation")
            forall (f :: * -> *) a b. Applicative f => 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 AssociateLink where
  hashWithSalt :: Int -> AssociateLink -> Int
hashWithSalt Int
_salt AssociateLink' {Text
linkId :: Text
deviceId :: Text
globalNetworkId :: Text
$sel:linkId:AssociateLink' :: AssociateLink -> Text
$sel:deviceId:AssociateLink' :: AssociateLink -> Text
$sel:globalNetworkId:AssociateLink' :: AssociateLink -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
globalNetworkId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
deviceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
linkId

instance Prelude.NFData AssociateLink where
  rnf :: AssociateLink -> ()
rnf AssociateLink' {Text
linkId :: Text
deviceId :: Text
globalNetworkId :: Text
$sel:linkId:AssociateLink' :: AssociateLink -> Text
$sel:deviceId:AssociateLink' :: AssociateLink -> Text
$sel:globalNetworkId:AssociateLink' :: AssociateLink -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
globalNetworkId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
deviceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
linkId

instance Data.ToHeaders AssociateLink where
  toHeaders :: AssociateLink -> 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 AssociateLink where
  toJSON :: AssociateLink -> Value
toJSON AssociateLink' {Text
linkId :: Text
deviceId :: Text
globalNetworkId :: Text
$sel:linkId:AssociateLink' :: AssociateLink -> Text
$sel:deviceId:AssociateLink' :: AssociateLink -> Text
$sel:globalNetworkId:AssociateLink' :: AssociateLink -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"DeviceId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
deviceId),
            forall a. a -> Maybe a
Prelude.Just (Key
"LinkId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
linkId)
          ]
      )

instance Data.ToPath AssociateLink where
  toPath :: AssociateLink -> ByteString
toPath AssociateLink' {Text
linkId :: Text
deviceId :: Text
globalNetworkId :: Text
$sel:linkId:AssociateLink' :: AssociateLink -> Text
$sel:deviceId:AssociateLink' :: AssociateLink -> Text
$sel:globalNetworkId:AssociateLink' :: AssociateLink -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/global-networks/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
globalNetworkId,
        ByteString
"/link-associations"
      ]

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

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

-- |
-- Create a value of 'AssociateLinkResponse' 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:
--
-- 'linkAssociation', 'associateLinkResponse_linkAssociation' - The link association.
--
-- 'httpStatus', 'associateLinkResponse_httpStatus' - The response's http status code.
newAssociateLinkResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateLinkResponse
newAssociateLinkResponse :: Int -> AssociateLinkResponse
newAssociateLinkResponse Int
pHttpStatus_ =
  AssociateLinkResponse'
    { $sel:linkAssociation:AssociateLinkResponse' :: Maybe LinkAssociation
linkAssociation =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociateLinkResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The link association.
associateLinkResponse_linkAssociation :: Lens.Lens' AssociateLinkResponse (Prelude.Maybe LinkAssociation)
associateLinkResponse_linkAssociation :: Lens' AssociateLinkResponse (Maybe LinkAssociation)
associateLinkResponse_linkAssociation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateLinkResponse' {Maybe LinkAssociation
linkAssociation :: Maybe LinkAssociation
$sel:linkAssociation:AssociateLinkResponse' :: AssociateLinkResponse -> Maybe LinkAssociation
linkAssociation} -> Maybe LinkAssociation
linkAssociation) (\s :: AssociateLinkResponse
s@AssociateLinkResponse' {} Maybe LinkAssociation
a -> AssociateLinkResponse
s {$sel:linkAssociation:AssociateLinkResponse' :: Maybe LinkAssociation
linkAssociation = Maybe LinkAssociation
a} :: AssociateLinkResponse)

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

instance Prelude.NFData AssociateLinkResponse where
  rnf :: AssociateLinkResponse -> ()
rnf AssociateLinkResponse' {Int
Maybe LinkAssociation
httpStatus :: Int
linkAssociation :: Maybe LinkAssociation
$sel:httpStatus:AssociateLinkResponse' :: AssociateLinkResponse -> Int
$sel:linkAssociation:AssociateLinkResponse' :: AssociateLinkResponse -> Maybe LinkAssociation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe LinkAssociation
linkAssociation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus