{-# 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.AllocatePublicVirtualInterface
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Provisions a public virtual interface to be owned by the specified
-- Amazon Web Services account.
--
-- The owner of a connection calls this function to provision a public
-- virtual interface to be owned by the specified Amazon Web Services
-- account.
--
-- Virtual interfaces created using this function must be confirmed by the
-- owner using ConfirmPublicVirtualInterface. Until this step has been
-- completed, the virtual interface is in the @confirming@ state and is not
-- available to handle traffic.
--
-- When creating an IPv6 public virtual interface, omit the Amazon address
-- and customer address. IPv6 addresses are automatically assigned from the
-- Amazon pool of IPv6 addresses; you cannot specify custom IPv6 addresses.
module Amazonka.DirectConnect.AllocatePublicVirtualInterface
  ( -- * Creating a Request
    AllocatePublicVirtualInterface (..),
    newAllocatePublicVirtualInterface,

    -- * Request Lenses
    allocatePublicVirtualInterface_connectionId,
    allocatePublicVirtualInterface_ownerAccount,
    allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation,

    -- * Destructuring the Response
    VirtualInterface (..),
    newVirtualInterface,

    -- * Response Lenses
    virtualInterface_addressFamily,
    virtualInterface_amazonAddress,
    virtualInterface_amazonSideAsn,
    virtualInterface_asn,
    virtualInterface_authKey,
    virtualInterface_awsDeviceV2,
    virtualInterface_awsLogicalDeviceId,
    virtualInterface_bgpPeers,
    virtualInterface_connectionId,
    virtualInterface_customerAddress,
    virtualInterface_customerRouterConfig,
    virtualInterface_directConnectGatewayId,
    virtualInterface_jumboFrameCapable,
    virtualInterface_location,
    virtualInterface_mtu,
    virtualInterface_ownerAccount,
    virtualInterface_region,
    virtualInterface_routeFilterPrefixes,
    virtualInterface_siteLinkEnabled,
    virtualInterface_tags,
    virtualInterface_virtualGatewayId,
    virtualInterface_virtualInterfaceId,
    virtualInterface_virtualInterfaceName,
    virtualInterface_virtualInterfaceState,
    virtualInterface_virtualInterfaceType,
    virtualInterface_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:/ 'newAllocatePublicVirtualInterface' smart constructor.
data AllocatePublicVirtualInterface = AllocatePublicVirtualInterface'
  { -- | The ID of the connection on which the public virtual interface is
    -- provisioned.
    AllocatePublicVirtualInterface -> Text
connectionId :: Prelude.Text,
    -- | The ID of the Amazon Web Services account that owns the public virtual
    -- interface.
    AllocatePublicVirtualInterface -> Text
ownerAccount :: Prelude.Text,
    -- | Information about the public virtual interface.
    AllocatePublicVirtualInterface
-> NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' :: NewPublicVirtualInterfaceAllocation
  }
  deriving (AllocatePublicVirtualInterface
-> AllocatePublicVirtualInterface -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AllocatePublicVirtualInterface
-> AllocatePublicVirtualInterface -> Bool
$c/= :: AllocatePublicVirtualInterface
-> AllocatePublicVirtualInterface -> Bool
== :: AllocatePublicVirtualInterface
-> AllocatePublicVirtualInterface -> Bool
$c== :: AllocatePublicVirtualInterface
-> AllocatePublicVirtualInterface -> Bool
Prelude.Eq, ReadPrec [AllocatePublicVirtualInterface]
ReadPrec AllocatePublicVirtualInterface
Int -> ReadS AllocatePublicVirtualInterface
ReadS [AllocatePublicVirtualInterface]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AllocatePublicVirtualInterface]
$creadListPrec :: ReadPrec [AllocatePublicVirtualInterface]
readPrec :: ReadPrec AllocatePublicVirtualInterface
$creadPrec :: ReadPrec AllocatePublicVirtualInterface
readList :: ReadS [AllocatePublicVirtualInterface]
$creadList :: ReadS [AllocatePublicVirtualInterface]
readsPrec :: Int -> ReadS AllocatePublicVirtualInterface
$creadsPrec :: Int -> ReadS AllocatePublicVirtualInterface
Prelude.Read, Int -> AllocatePublicVirtualInterface -> ShowS
[AllocatePublicVirtualInterface] -> ShowS
AllocatePublicVirtualInterface -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AllocatePublicVirtualInterface] -> ShowS
$cshowList :: [AllocatePublicVirtualInterface] -> ShowS
show :: AllocatePublicVirtualInterface -> String
$cshow :: AllocatePublicVirtualInterface -> String
showsPrec :: Int -> AllocatePublicVirtualInterface -> ShowS
$cshowsPrec :: Int -> AllocatePublicVirtualInterface -> ShowS
Prelude.Show, forall x.
Rep AllocatePublicVirtualInterface x
-> AllocatePublicVirtualInterface
forall x.
AllocatePublicVirtualInterface
-> Rep AllocatePublicVirtualInterface x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AllocatePublicVirtualInterface x
-> AllocatePublicVirtualInterface
$cfrom :: forall x.
AllocatePublicVirtualInterface
-> Rep AllocatePublicVirtualInterface x
Prelude.Generic)

-- |
-- Create a value of 'AllocatePublicVirtualInterface' 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', 'allocatePublicVirtualInterface_connectionId' - The ID of the connection on which the public virtual interface is
-- provisioned.
--
-- 'ownerAccount', 'allocatePublicVirtualInterface_ownerAccount' - The ID of the Amazon Web Services account that owns the public virtual
-- interface.
--
-- 'newPublicVirtualInterfaceAllocation'', 'allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation' - Information about the public virtual interface.
newAllocatePublicVirtualInterface ::
  -- | 'connectionId'
  Prelude.Text ->
  -- | 'ownerAccount'
  Prelude.Text ->
  -- | 'newPublicVirtualInterfaceAllocation''
  NewPublicVirtualInterfaceAllocation ->
  AllocatePublicVirtualInterface
newAllocatePublicVirtualInterface :: Text
-> Text
-> NewPublicVirtualInterfaceAllocation
-> AllocatePublicVirtualInterface
newAllocatePublicVirtualInterface
  Text
pConnectionId_
  Text
pOwnerAccount_
  NewPublicVirtualInterfaceAllocation
pNewPublicVirtualInterfaceAllocation_ =
    AllocatePublicVirtualInterface'
      { $sel:connectionId:AllocatePublicVirtualInterface' :: Text
connectionId =
          Text
pConnectionId_,
        $sel:ownerAccount:AllocatePublicVirtualInterface' :: Text
ownerAccount = Text
pOwnerAccount_,
        $sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' =
          NewPublicVirtualInterfaceAllocation
pNewPublicVirtualInterfaceAllocation_
      }

-- | The ID of the connection on which the public virtual interface is
-- provisioned.
allocatePublicVirtualInterface_connectionId :: Lens.Lens' AllocatePublicVirtualInterface Prelude.Text
allocatePublicVirtualInterface_connectionId :: Lens' AllocatePublicVirtualInterface Text
allocatePublicVirtualInterface_connectionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocatePublicVirtualInterface' {Text
connectionId :: Text
$sel:connectionId:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> Text
connectionId} -> Text
connectionId) (\s :: AllocatePublicVirtualInterface
s@AllocatePublicVirtualInterface' {} Text
a -> AllocatePublicVirtualInterface
s {$sel:connectionId:AllocatePublicVirtualInterface' :: Text
connectionId = Text
a} :: AllocatePublicVirtualInterface)

-- | The ID of the Amazon Web Services account that owns the public virtual
-- interface.
allocatePublicVirtualInterface_ownerAccount :: Lens.Lens' AllocatePublicVirtualInterface Prelude.Text
allocatePublicVirtualInterface_ownerAccount :: Lens' AllocatePublicVirtualInterface Text
allocatePublicVirtualInterface_ownerAccount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocatePublicVirtualInterface' {Text
ownerAccount :: Text
$sel:ownerAccount:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> Text
ownerAccount} -> Text
ownerAccount) (\s :: AllocatePublicVirtualInterface
s@AllocatePublicVirtualInterface' {} Text
a -> AllocatePublicVirtualInterface
s {$sel:ownerAccount:AllocatePublicVirtualInterface' :: Text
ownerAccount = Text
a} :: AllocatePublicVirtualInterface)

-- | Information about the public virtual interface.
allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation :: Lens.Lens' AllocatePublicVirtualInterface NewPublicVirtualInterfaceAllocation
allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation :: Lens'
  AllocatePublicVirtualInterface NewPublicVirtualInterfaceAllocation
allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocatePublicVirtualInterface' {NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' :: NewPublicVirtualInterfaceAllocation
$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface
-> NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation'} -> NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation') (\s :: AllocatePublicVirtualInterface
s@AllocatePublicVirtualInterface' {} NewPublicVirtualInterfaceAllocation
a -> AllocatePublicVirtualInterface
s {$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' = NewPublicVirtualInterfaceAllocation
a} :: AllocatePublicVirtualInterface)

instance
  Core.AWSRequest
    AllocatePublicVirtualInterface
  where
  type
    AWSResponse AllocatePublicVirtualInterface =
      VirtualInterface
  request :: (Service -> Service)
-> AllocatePublicVirtualInterface
-> Request AllocatePublicVirtualInterface
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 AllocatePublicVirtualInterface
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse AllocatePublicVirtualInterface)))
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
    AllocatePublicVirtualInterface
  where
  hashWithSalt :: Int -> AllocatePublicVirtualInterface -> Int
hashWithSalt
    Int
_salt
    AllocatePublicVirtualInterface' {Text
NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' :: NewPublicVirtualInterfaceAllocation
ownerAccount :: Text
connectionId :: Text
$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface
-> NewPublicVirtualInterfaceAllocation
$sel:ownerAccount:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> Text
$sel:connectionId:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> Text
..} =
      Int
_salt
        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` NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation'

instance
  Prelude.NFData
    AllocatePublicVirtualInterface
  where
  rnf :: AllocatePublicVirtualInterface -> ()
rnf AllocatePublicVirtualInterface' {Text
NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' :: NewPublicVirtualInterfaceAllocation
ownerAccount :: Text
connectionId :: Text
$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface
-> NewPublicVirtualInterfaceAllocation
$sel:ownerAccount:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> Text
$sel:connectionId:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> 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
ownerAccount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation'

instance
  Data.ToHeaders
    AllocatePublicVirtualInterface
  where
  toHeaders :: AllocatePublicVirtualInterface -> 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.AllocatePublicVirtualInterface" ::
                          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 AllocatePublicVirtualInterface where
  toJSON :: AllocatePublicVirtualInterface -> Value
toJSON AllocatePublicVirtualInterface' {Text
NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' :: NewPublicVirtualInterfaceAllocation
ownerAccount :: Text
connectionId :: Text
$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface
-> NewPublicVirtualInterfaceAllocation
$sel:ownerAccount:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> Text
$sel:connectionId:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> 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
"ownerAccount" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
ownerAccount),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"newPublicVirtualInterfaceAllocation"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation'
              )
          ]
      )

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

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