{-# 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-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 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.Lens as Lens
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
(AssociateLink -> AssociateLink -> Bool)
-> (AssociateLink -> AssociateLink -> Bool) -> Eq AssociateLink
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]
(Int -> ReadS AssociateLink)
-> ReadS [AssociateLink]
-> ReadPrec AssociateLink
-> ReadPrec [AssociateLink]
-> Read 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
(Int -> AssociateLink -> ShowS)
-> (AssociateLink -> String)
-> ([AssociateLink] -> ShowS)
-> Show AssociateLink
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. AssociateLink -> Rep AssociateLink x)
-> (forall x. Rep AssociateLink x -> AssociateLink)
-> Generic AssociateLink
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' :: Text -> Text -> Text -> AssociateLink
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 :: (Text -> f Text) -> AssociateLink -> f AssociateLink
associateLink_globalNetworkId = (AssociateLink -> Text)
-> (AssociateLink -> Text -> AssociateLink)
-> Lens AssociateLink AssociateLink Text Text
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 :: (Text -> f Text) -> AssociateLink -> f AssociateLink
associateLink_deviceId = (AssociateLink -> Text)
-> (AssociateLink -> Text -> AssociateLink)
-> Lens AssociateLink AssociateLink Text Text
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 :: (Text -> f Text) -> AssociateLink -> f AssociateLink
associateLink_linkId = (AssociateLink -> Text)
-> (AssociateLink -> Text -> AssociateLink)
-> Lens AssociateLink AssociateLink Text Text
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 :: AssociateLink -> Request AssociateLink
request = Service -> AssociateLink -> Request AssociateLink
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateLink
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateLink)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AssociateLink))
-> Logger
-> Service
-> Proxy AssociateLink
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateLink)))
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 ->
          Maybe LinkAssociation -> Int -> AssociateLinkResponse
AssociateLinkResponse'
            (Maybe LinkAssociation -> Int -> AssociateLinkResponse)
-> Either String (Maybe LinkAssociation)
-> Either String (Int -> AssociateLinkResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe LinkAssociation)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"LinkAssociation")
            Either String (Int -> AssociateLinkResponse)
-> Either String Int -> Either String AssociateLinkResponse
forall (f :: * -> *) a b. Applicative f => 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 AssociateLink

instance Prelude.NFData AssociateLink

instance Core.ToHeaders AssociateLink where
  toHeaders :: AssociateLink -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AssociateLink -> 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 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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DeviceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
deviceId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"LinkId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
linkId)
          ]
      )

instance Core.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
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/global-networks/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
globalNetworkId,
        ByteString
"/link-associations"
      ]

instance Core.ToQuery AssociateLink where
  toQuery :: AssociateLink -> QueryString
toQuery = QueryString -> AssociateLink -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(AssociateLinkResponse -> AssociateLinkResponse -> Bool)
-> (AssociateLinkResponse -> AssociateLinkResponse -> Bool)
-> Eq AssociateLinkResponse
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]
(Int -> ReadS AssociateLinkResponse)
-> ReadS [AssociateLinkResponse]
-> ReadPrec AssociateLinkResponse
-> ReadPrec [AssociateLinkResponse]
-> Read 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
(Int -> AssociateLinkResponse -> ShowS)
-> (AssociateLinkResponse -> String)
-> ([AssociateLinkResponse] -> ShowS)
-> Show AssociateLinkResponse
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. AssociateLinkResponse -> Rep AssociateLinkResponse x)
-> (forall x. Rep AssociateLinkResponse x -> AssociateLinkResponse)
-> Generic AssociateLinkResponse
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' :: Maybe LinkAssociation -> Int -> AssociateLinkResponse
AssociateLinkResponse'
    { $sel:linkAssociation:AssociateLinkResponse' :: Maybe LinkAssociation
linkAssociation =
        Maybe 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 :: (Maybe LinkAssociation -> f (Maybe LinkAssociation))
-> AssociateLinkResponse -> f AssociateLinkResponse
associateLinkResponse_linkAssociation = (AssociateLinkResponse -> Maybe LinkAssociation)
-> (AssociateLinkResponse
    -> Maybe LinkAssociation -> AssociateLinkResponse)
-> Lens
     AssociateLinkResponse
     AssociateLinkResponse
     (Maybe LinkAssociation)
     (Maybe 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 :: (Int -> f Int) -> AssociateLinkResponse -> f AssociateLinkResponse
associateLinkResponse_httpStatus = (AssociateLinkResponse -> Int)
-> (AssociateLinkResponse -> Int -> AssociateLinkResponse)
-> Lens AssociateLinkResponse AssociateLinkResponse Int Int
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