{-# 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-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)
--
-- 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_lagId,
    connection_macSecCapable,
    connection_portEncryptionStatus,
    connection_vlan,
    connection_location,
    connection_awsDevice,
    connection_hasLogicalRedundancy,
    connection_connectionId,
    connection_awsLogicalDeviceId,
    connection_loaIssueTime,
    connection_partnerName,
    connection_connectionName,
    connection_encryptionMode,
    connection_bandwidth,
    connection_jumboFrameCapable,
    connection_ownerAccount,
    connection_region,
    connection_macSecKeys,
    connection_providerName,
    connection_awsDeviceV2,
    connection_connectionState,
    connection_tags,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DirectConnect.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:/ '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
(DisassociateConnectionFromLag
 -> DisassociateConnectionFromLag -> Bool)
-> (DisassociateConnectionFromLag
    -> DisassociateConnectionFromLag -> Bool)
-> Eq DisassociateConnectionFromLag
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]
(Int -> ReadS DisassociateConnectionFromLag)
-> ReadS [DisassociateConnectionFromLag]
-> ReadPrec DisassociateConnectionFromLag
-> ReadPrec [DisassociateConnectionFromLag]
-> Read 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
(Int -> DisassociateConnectionFromLag -> ShowS)
-> (DisassociateConnectionFromLag -> String)
-> ([DisassociateConnectionFromLag] -> ShowS)
-> Show DisassociateConnectionFromLag
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.
 DisassociateConnectionFromLag
 -> Rep DisassociateConnectionFromLag x)
-> (forall x.
    Rep DisassociateConnectionFromLag x
    -> DisassociateConnectionFromLag)
-> Generic DisassociateConnectionFromLag
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' :: Text -> Text -> DisassociateConnectionFromLag
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 :: (Text -> f Text)
-> DisassociateConnectionFromLag -> f DisassociateConnectionFromLag
disassociateConnectionFromLag_connectionId = (DisassociateConnectionFromLag -> Text)
-> (DisassociateConnectionFromLag
    -> Text -> DisassociateConnectionFromLag)
-> Lens
     DisassociateConnectionFromLag
     DisassociateConnectionFromLag
     Text
     Text
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 :: (Text -> f Text)
-> DisassociateConnectionFromLag -> f DisassociateConnectionFromLag
disassociateConnectionFromLag_lagId = (DisassociateConnectionFromLag -> Text)
-> (DisassociateConnectionFromLag
    -> Text -> DisassociateConnectionFromLag)
-> Lens
     DisassociateConnectionFromLag
     DisassociateConnectionFromLag
     Text
     Text
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 :: DisassociateConnectionFromLag
-> Request DisassociateConnectionFromLag
request = Service
-> DisassociateConnectionFromLag
-> Request DisassociateConnectionFromLag
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DisassociateConnectionFromLag
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DisassociateConnectionFromLag)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DisassociateConnectionFromLag))
-> Logger
-> Service
-> Proxy DisassociateConnectionFromLag
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DisassociateConnectionFromLag)))
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 -> Object -> Either String Connection
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance
  Prelude.Hashable
    DisassociateConnectionFromLag

instance Prelude.NFData DisassociateConnectionFromLag

instance Core.ToHeaders DisassociateConnectionFromLag where
  toHeaders :: DisassociateConnectionFromLag -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DisassociateConnectionFromLag -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"OvertureService.DisassociateConnectionFromLag" ::
                          Prelude.ByteString
                      ),
            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 DisassociateConnectionFromLag where
  toJSON :: DisassociateConnectionFromLag -> Value
toJSON DisassociateConnectionFromLag' {Text
lagId :: Text
connectionId :: Text
$sel:lagId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> Text
$sel:connectionId:DisassociateConnectionFromLag' :: DisassociateConnectionFromLag -> 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
"connectionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
connectionId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"lagId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
lagId)
          ]
      )

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

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