{-# 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.AllocateHostedConnection
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a hosted connection on the specified interconnect or a link
-- aggregation group (LAG) of interconnects.
--
-- Allocates a VLAN number and a specified amount of capacity (bandwidth)
-- for use by a hosted connection on the specified interconnect or LAG of
-- interconnects. Amazon Web Services polices the hosted connection for the
-- specified capacity and the Direct Connect Partner must also police the
-- hosted connection for the specified capacity.
--
-- Intended for use by Direct Connect Partners only.
module Amazonka.DirectConnect.AllocateHostedConnection
  ( -- * Creating a Request
    AllocateHostedConnection (..),
    newAllocateHostedConnection,

    -- * Request Lenses
    allocateHostedConnection_tags,
    allocateHostedConnection_connectionId,
    allocateHostedConnection_ownerAccount,
    allocateHostedConnection_bandwidth,
    allocateHostedConnection_connectionName,
    allocateHostedConnection_vlan,

    -- * 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:/ 'newAllocateHostedConnection' smart constructor.
data AllocateHostedConnection = AllocateHostedConnection'
  { -- | The tags associated with the connection.
    AllocateHostedConnection -> Maybe (NonEmpty Tag)
tags :: Prelude.Maybe (Prelude.NonEmpty Tag),
    -- | The ID of the interconnect or LAG.
    AllocateHostedConnection -> Text
connectionId :: Prelude.Text,
    -- | The ID of the Amazon Web Services account ID of the customer for the
    -- connection.
    AllocateHostedConnection -> Text
ownerAccount :: Prelude.Text,
    -- | The bandwidth of the connection. The possible values are 50Mbps,
    -- 100Mbps, 200Mbps, 300Mbps, 400Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, and
    -- 10Gbps. Note that only those Direct Connect Partners who have met
    -- specific requirements are allowed to create a 1Gbps, 2Gbps, 5Gbps or
    -- 10Gbps hosted connection.
    AllocateHostedConnection -> Text
bandwidth :: Prelude.Text,
    -- | The name of the hosted connection.
    AllocateHostedConnection -> Text
connectionName :: Prelude.Text,
    -- | The dedicated VLAN provisioned to the hosted connection.
    AllocateHostedConnection -> Int
vlan :: Prelude.Int
  }
  deriving (AllocateHostedConnection -> AllocateHostedConnection -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
$c/= :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
== :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
$c== :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
Prelude.Eq, ReadPrec [AllocateHostedConnection]
ReadPrec AllocateHostedConnection
Int -> ReadS AllocateHostedConnection
ReadS [AllocateHostedConnection]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AllocateHostedConnection]
$creadListPrec :: ReadPrec [AllocateHostedConnection]
readPrec :: ReadPrec AllocateHostedConnection
$creadPrec :: ReadPrec AllocateHostedConnection
readList :: ReadS [AllocateHostedConnection]
$creadList :: ReadS [AllocateHostedConnection]
readsPrec :: Int -> ReadS AllocateHostedConnection
$creadsPrec :: Int -> ReadS AllocateHostedConnection
Prelude.Read, Int -> AllocateHostedConnection -> ShowS
[AllocateHostedConnection] -> ShowS
AllocateHostedConnection -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AllocateHostedConnection] -> ShowS
$cshowList :: [AllocateHostedConnection] -> ShowS
show :: AllocateHostedConnection -> String
$cshow :: AllocateHostedConnection -> String
showsPrec :: Int -> AllocateHostedConnection -> ShowS
$cshowsPrec :: Int -> AllocateHostedConnection -> ShowS
Prelude.Show, forall x.
Rep AllocateHostedConnection x -> AllocateHostedConnection
forall x.
AllocateHostedConnection -> Rep AllocateHostedConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AllocateHostedConnection x -> AllocateHostedConnection
$cfrom :: forall x.
AllocateHostedConnection -> Rep AllocateHostedConnection x
Prelude.Generic)

-- |
-- Create a value of 'AllocateHostedConnection' 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:
--
-- 'tags', 'allocateHostedConnection_tags' - The tags associated with the connection.
--
-- 'connectionId', 'allocateHostedConnection_connectionId' - The ID of the interconnect or LAG.
--
-- 'ownerAccount', 'allocateHostedConnection_ownerAccount' - The ID of the Amazon Web Services account ID of the customer for the
-- connection.
--
-- 'bandwidth', 'allocateHostedConnection_bandwidth' - The bandwidth of the connection. The possible values are 50Mbps,
-- 100Mbps, 200Mbps, 300Mbps, 400Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, and
-- 10Gbps. Note that only those Direct Connect Partners who have met
-- specific requirements are allowed to create a 1Gbps, 2Gbps, 5Gbps or
-- 10Gbps hosted connection.
--
-- 'connectionName', 'allocateHostedConnection_connectionName' - The name of the hosted connection.
--
-- 'vlan', 'allocateHostedConnection_vlan' - The dedicated VLAN provisioned to the hosted connection.
newAllocateHostedConnection ::
  -- | 'connectionId'
  Prelude.Text ->
  -- | 'ownerAccount'
  Prelude.Text ->
  -- | 'bandwidth'
  Prelude.Text ->
  -- | 'connectionName'
  Prelude.Text ->
  -- | 'vlan'
  Prelude.Int ->
  AllocateHostedConnection
newAllocateHostedConnection :: Text -> Text -> Text -> Text -> Int -> AllocateHostedConnection
newAllocateHostedConnection
  Text
pConnectionId_
  Text
pOwnerAccount_
  Text
pBandwidth_
  Text
pConnectionName_
  Int
pVlan_ =
    AllocateHostedConnection'
      { $sel:tags:AllocateHostedConnection' :: Maybe (NonEmpty Tag)
tags = forall a. Maybe a
Prelude.Nothing,
        $sel:connectionId:AllocateHostedConnection' :: Text
connectionId = Text
pConnectionId_,
        $sel:ownerAccount:AllocateHostedConnection' :: Text
ownerAccount = Text
pOwnerAccount_,
        $sel:bandwidth:AllocateHostedConnection' :: Text
bandwidth = Text
pBandwidth_,
        $sel:connectionName:AllocateHostedConnection' :: Text
connectionName = Text
pConnectionName_,
        $sel:vlan:AllocateHostedConnection' :: Int
vlan = Int
pVlan_
      }

-- | The tags associated with the connection.
allocateHostedConnection_tags :: Lens.Lens' AllocateHostedConnection (Prelude.Maybe (Prelude.NonEmpty Tag))
allocateHostedConnection_tags :: Lens' AllocateHostedConnection (Maybe (NonEmpty Tag))
allocateHostedConnection_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Maybe (NonEmpty Tag)
tags :: Maybe (NonEmpty Tag)
$sel:tags:AllocateHostedConnection' :: AllocateHostedConnection -> Maybe (NonEmpty Tag)
tags} -> Maybe (NonEmpty Tag)
tags) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Maybe (NonEmpty Tag)
a -> AllocateHostedConnection
s {$sel:tags:AllocateHostedConnection' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
a} :: AllocateHostedConnection) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the interconnect or LAG.
allocateHostedConnection_connectionId :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_connectionId :: Lens' AllocateHostedConnection Text
allocateHostedConnection_connectionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
connectionId :: Text
$sel:connectionId:AllocateHostedConnection' :: AllocateHostedConnection -> Text
connectionId} -> Text
connectionId) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:connectionId:AllocateHostedConnection' :: Text
connectionId = Text
a} :: AllocateHostedConnection)

-- | The ID of the Amazon Web Services account ID of the customer for the
-- connection.
allocateHostedConnection_ownerAccount :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_ownerAccount :: Lens' AllocateHostedConnection Text
allocateHostedConnection_ownerAccount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
ownerAccount :: Text
$sel:ownerAccount:AllocateHostedConnection' :: AllocateHostedConnection -> Text
ownerAccount} -> Text
ownerAccount) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:ownerAccount:AllocateHostedConnection' :: Text
ownerAccount = Text
a} :: AllocateHostedConnection)

-- | The bandwidth of the connection. The possible values are 50Mbps,
-- 100Mbps, 200Mbps, 300Mbps, 400Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, and
-- 10Gbps. Note that only those Direct Connect Partners who have met
-- specific requirements are allowed to create a 1Gbps, 2Gbps, 5Gbps or
-- 10Gbps hosted connection.
allocateHostedConnection_bandwidth :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_bandwidth :: Lens' AllocateHostedConnection Text
allocateHostedConnection_bandwidth = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
bandwidth :: Text
$sel:bandwidth:AllocateHostedConnection' :: AllocateHostedConnection -> Text
bandwidth} -> Text
bandwidth) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:bandwidth:AllocateHostedConnection' :: Text
bandwidth = Text
a} :: AllocateHostedConnection)

-- | The name of the hosted connection.
allocateHostedConnection_connectionName :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_connectionName :: Lens' AllocateHostedConnection Text
allocateHostedConnection_connectionName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
connectionName :: Text
$sel:connectionName:AllocateHostedConnection' :: AllocateHostedConnection -> Text
connectionName} -> Text
connectionName) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:connectionName:AllocateHostedConnection' :: Text
connectionName = Text
a} :: AllocateHostedConnection)

-- | The dedicated VLAN provisioned to the hosted connection.
allocateHostedConnection_vlan :: Lens.Lens' AllocateHostedConnection Prelude.Int
allocateHostedConnection_vlan :: Lens' AllocateHostedConnection Int
allocateHostedConnection_vlan = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Int
vlan :: Int
$sel:vlan:AllocateHostedConnection' :: AllocateHostedConnection -> Int
vlan} -> Int
vlan) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Int
a -> AllocateHostedConnection
s {$sel:vlan:AllocateHostedConnection' :: Int
vlan = Int
a} :: AllocateHostedConnection)

instance Core.AWSRequest AllocateHostedConnection where
  type
    AWSResponse AllocateHostedConnection =
      Connection
  request :: (Service -> Service)
-> AllocateHostedConnection -> Request AllocateHostedConnection
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 AllocateHostedConnection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AllocateHostedConnection)))
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 AllocateHostedConnection where
  hashWithSalt :: Int -> AllocateHostedConnection -> Int
hashWithSalt Int
_salt AllocateHostedConnection' {Int
Maybe (NonEmpty Tag)
Text
vlan :: Int
connectionName :: Text
bandwidth :: Text
ownerAccount :: Text
connectionId :: Text
tags :: Maybe (NonEmpty Tag)
$sel:vlan:AllocateHostedConnection' :: AllocateHostedConnection -> Int
$sel:connectionName:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:bandwidth:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:ownerAccount:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:connectionId:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:tags:AllocateHostedConnection' :: AllocateHostedConnection -> Maybe (NonEmpty Tag)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Tag)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
connectionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
ownerAccount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
bandwidth
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
connectionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
vlan

instance Prelude.NFData AllocateHostedConnection where
  rnf :: AllocateHostedConnection -> ()
rnf AllocateHostedConnection' {Int
Maybe (NonEmpty Tag)
Text
vlan :: Int
connectionName :: Text
bandwidth :: Text
ownerAccount :: Text
connectionId :: Text
tags :: Maybe (NonEmpty Tag)
$sel:vlan:AllocateHostedConnection' :: AllocateHostedConnection -> Int
$sel:connectionName:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:bandwidth:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:ownerAccount:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:connectionId:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:tags:AllocateHostedConnection' :: AllocateHostedConnection -> Maybe (NonEmpty Tag)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Tag)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
ownerAccount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
bandwidth
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
connectionName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
vlan

instance Data.ToHeaders AllocateHostedConnection where
  toHeaders :: AllocateHostedConnection -> 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.AllocateHostedConnection" ::
                          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 AllocateHostedConnection where
  toJSON :: AllocateHostedConnection -> Value
toJSON AllocateHostedConnection' {Int
Maybe (NonEmpty Tag)
Text
vlan :: Int
connectionName :: Text
bandwidth :: Text
ownerAccount :: Text
connectionId :: Text
tags :: Maybe (NonEmpty Tag)
$sel:vlan:AllocateHostedConnection' :: AllocateHostedConnection -> Int
$sel:connectionName:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:bandwidth:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:ownerAccount:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:connectionId:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:tags:AllocateHostedConnection' :: AllocateHostedConnection -> Maybe (NonEmpty Tag)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"tags" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Tag)
tags,
            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
"ownerAccount" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
ownerAccount),
            forall a. a -> Maybe a
Prelude.Just (Key
"bandwidth" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
bandwidth),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"connectionName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
connectionName),
            forall a. a -> Maybe a
Prelude.Just (Key
"vlan" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
vlan)
          ]
      )

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

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