{-# 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.DirectConnect.DisassociateConnectionFromLag
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Disassociates a connection from a link aggregation group (LAG). The
-- connection is interrupted and re-established as a standalone connection
-- (the connection is not deleted; to delete the connection, use the
-- DeleteConnection request). If the LAG has associated virtual interfaces
-- or hosted connections, they remain associated with the LAG. A
-- disassociated connection owned by an Direct Connect Partner is
-- automatically converted to an interconnect.
--
-- If disassociating the connection would cause the LAG to fall below its
-- setting for minimum number of operational connections, the request
-- fails, except when it\'s the last member of the LAG. If all connections
-- are disassociated, the LAG continues to exist as an empty LAG with no
-- physical connections.
module Amazonka.DirectConnect.DisassociateConnectionFromLag
  ( -- * Creating a Request
    DisassociateConnectionFromLag (..),
    newDisassociateConnectionFromLag,

    -- * Request Lenses
    disassociateConnectionFromLag_connectionId,
    disassociateConnectionFromLag_lagId,

    -- * Destructuring the Response
    Connection (..),
    newConnection,

    -- * Response Lenses
    connection_awsDevice,
    connection_awsDeviceV2,
    connection_awsLogicalDeviceId,
    connection_bandwidth,
    connection_connectionId,
    connection_connectionName,
    connection_connectionState,
    connection_encryptionMode,
    connection_hasLogicalRedundancy,
    connection_jumboFrameCapable,
    connection_lagId,
    connection_loaIssueTime,
    connection_location,
    connection_macSecCapable,
    connection_macSecKeys,
    connection_ownerAccount,
    connection_partnerName,
    connection_portEncryptionStatus,
    connection_providerName,
    connection_region,
    connection_tags,
    connection_vlan,
  )
where

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

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

-- |
-- Create a value of 'DisassociateConnectionFromLag' 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:
--
-- 'connectionId', 'disassociateConnectionFromLag_connectionId' - The ID of the connection.
--
-- 'lagId', 'disassociateConnectionFromLag_lagId' - The ID of the LAG.
newDisassociateConnectionFromLag ::
  -- | 'connectionId'
  Prelude.Text ->
  -- | 'lagId'
  Prelude.Text ->
  DisassociateConnectionFromLag
newDisassociateConnectionFromLag :: Text -> Text -> DisassociateConnectionFromLag
newDisassociateConnectionFromLag
  Text
pConnectionId_
  Text
pLagId_ =
    DisassociateConnectionFromLag'
      { $sel:connectionId:DisassociateConnectionFromLag' :: Text
connectionId =
          Text
pConnectionId_,
        $sel:lagId:DisassociateConnectionFromLag' :: Text
lagId = Text
pLagId_
      }

-- | The ID of the connection.
disassociateConnectionFromLag_connectionId :: Lens.Lens' DisassociateConnectionFromLag Prelude.Text
disassociateConnectionFromLag_connectionId :: Lens' DisassociateConnectionFromLag Text
disassociateConnectionFromLag_connectionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisassociateConnectionFromLag' {Text
connectionId :: Text
$sel:connectionId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
connectionId} -> Text
connectionId) (\s :: DisassociateConnectionFromLag
s@DisassociateConnectionFromLag' {} Text
a -> DisassociateConnectionFromLag
s {$sel:connectionId:DisassociateConnectionFromLag' :: Text
connectionId = Text
a} :: DisassociateConnectionFromLag)

-- | The ID of the LAG.
disassociateConnectionFromLag_lagId :: Lens.Lens' DisassociateConnectionFromLag Prelude.Text
disassociateConnectionFromLag_lagId :: Lens' DisassociateConnectionFromLag Text
disassociateConnectionFromLag_lagId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisassociateConnectionFromLag' {Text
lagId :: Text
$sel:lagId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
lagId} -> Text
lagId) (\s :: DisassociateConnectionFromLag
s@DisassociateConnectionFromLag' {} Text
a -> DisassociateConnectionFromLag
s {$sel:lagId:DisassociateConnectionFromLag' :: Text
lagId = Text
a} :: DisassociateConnectionFromLag)

instance
  Core.AWSRequest
    DisassociateConnectionFromLag
  where
  type
    AWSResponse DisassociateConnectionFromLag =
      Connection
  request :: (Service -> Service)
-> DisassociateConnectionFromLag
-> Request DisassociateConnectionFromLag
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 DisassociateConnectionFromLag
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DisassociateConnectionFromLag)))
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 -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance
  Prelude.Hashable
    DisassociateConnectionFromLag
  where
  hashWithSalt :: Int -> DisassociateConnectionFromLag -> Int
hashWithSalt Int
_salt DisassociateConnectionFromLag' {Text
lagId :: Text
connectionId :: Text
$sel:lagId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
$sel:connectionId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
connectionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
lagId

instance Prelude.NFData DisassociateConnectionFromLag where
  rnf :: DisassociateConnectionFromLag -> ()
rnf DisassociateConnectionFromLag' {Text
lagId :: Text
connectionId :: Text
$sel:lagId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
$sel:connectionId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
connectionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
lagId

instance Data.ToHeaders DisassociateConnectionFromLag where
  toHeaders :: DisassociateConnectionFromLag -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"OvertureService.DisassociateConnectionFromLag" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON DisassociateConnectionFromLag where
  toJSON :: DisassociateConnectionFromLag -> Value
toJSON DisassociateConnectionFromLag' {Text
lagId :: Text
connectionId :: Text
$sel:lagId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
$sel:connectionId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"connectionId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
connectionId),
            forall a. a -> Maybe a
Prelude.Just (Key
"lagId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
lagId)
          ]
      )

instance Data.ToPath DisassociateConnectionFromLag where
  toPath :: DisassociateConnectionFromLag -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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