{-# 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.CreateBGPPeer
-- 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)
--
-- Creates a BGP peer on the specified virtual interface.
--
-- You must create a BGP peer for the corresponding address family
-- (IPv4\/IPv6) in order to access Amazon Web Services resources that also
-- use that address family.
--
-- If logical redundancy is not supported by the connection, interconnect,
-- or LAG, the BGP peer cannot be in the same address family as an existing
-- BGP peer on the virtual interface.
--
-- When creating a IPv6 BGP peer, 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.
--
-- For a public virtual interface, the Autonomous System Number (ASN) must
-- be private or already on the allow list for the virtual interface.
module Amazonka.DirectConnect.CreateBGPPeer
  ( -- * Creating a Request
    CreateBGPPeer (..),
    newCreateBGPPeer,

    -- * Request Lenses
    createBGPPeer_newBGPPeer,
    createBGPPeer_virtualInterfaceId,

    -- * Destructuring the Response
    CreateBGPPeerResponse (..),
    newCreateBGPPeerResponse,

    -- * Response Lenses
    createBGPPeerResponse_virtualInterface,
    createBGPPeerResponse_httpStatus,
  )
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:/ 'newCreateBGPPeer' smart constructor.
data CreateBGPPeer = CreateBGPPeer'
  { -- | Information about the BGP peer.
    CreateBGPPeer -> Maybe NewBGPPeer
newBGPPeer' :: Prelude.Maybe NewBGPPeer,
    -- | The ID of the virtual interface.
    CreateBGPPeer -> Maybe Text
virtualInterfaceId :: Prelude.Maybe Prelude.Text
  }
  deriving (CreateBGPPeer -> CreateBGPPeer -> Bool
(CreateBGPPeer -> CreateBGPPeer -> Bool)
-> (CreateBGPPeer -> CreateBGPPeer -> Bool) -> Eq CreateBGPPeer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBGPPeer -> CreateBGPPeer -> Bool
$c/= :: CreateBGPPeer -> CreateBGPPeer -> Bool
== :: CreateBGPPeer -> CreateBGPPeer -> Bool
$c== :: CreateBGPPeer -> CreateBGPPeer -> Bool
Prelude.Eq, ReadPrec [CreateBGPPeer]
ReadPrec CreateBGPPeer
Int -> ReadS CreateBGPPeer
ReadS [CreateBGPPeer]
(Int -> ReadS CreateBGPPeer)
-> ReadS [CreateBGPPeer]
-> ReadPrec CreateBGPPeer
-> ReadPrec [CreateBGPPeer]
-> Read CreateBGPPeer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBGPPeer]
$creadListPrec :: ReadPrec [CreateBGPPeer]
readPrec :: ReadPrec CreateBGPPeer
$creadPrec :: ReadPrec CreateBGPPeer
readList :: ReadS [CreateBGPPeer]
$creadList :: ReadS [CreateBGPPeer]
readsPrec :: Int -> ReadS CreateBGPPeer
$creadsPrec :: Int -> ReadS CreateBGPPeer
Prelude.Read, Int -> CreateBGPPeer -> ShowS
[CreateBGPPeer] -> ShowS
CreateBGPPeer -> String
(Int -> CreateBGPPeer -> ShowS)
-> (CreateBGPPeer -> String)
-> ([CreateBGPPeer] -> ShowS)
-> Show CreateBGPPeer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBGPPeer] -> ShowS
$cshowList :: [CreateBGPPeer] -> ShowS
show :: CreateBGPPeer -> String
$cshow :: CreateBGPPeer -> String
showsPrec :: Int -> CreateBGPPeer -> ShowS
$cshowsPrec :: Int -> CreateBGPPeer -> ShowS
Prelude.Show, (forall x. CreateBGPPeer -> Rep CreateBGPPeer x)
-> (forall x. Rep CreateBGPPeer x -> CreateBGPPeer)
-> Generic CreateBGPPeer
forall x. Rep CreateBGPPeer x -> CreateBGPPeer
forall x. CreateBGPPeer -> Rep CreateBGPPeer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateBGPPeer x -> CreateBGPPeer
$cfrom :: forall x. CreateBGPPeer -> Rep CreateBGPPeer x
Prelude.Generic)

-- |
-- Create a value of 'CreateBGPPeer' 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:
--
-- 'newBGPPeer'', 'createBGPPeer_newBGPPeer' - Information about the BGP peer.
--
-- 'virtualInterfaceId', 'createBGPPeer_virtualInterfaceId' - The ID of the virtual interface.
newCreateBGPPeer ::
  CreateBGPPeer
newCreateBGPPeer :: CreateBGPPeer
newCreateBGPPeer =
  CreateBGPPeer' :: Maybe NewBGPPeer -> Maybe Text -> CreateBGPPeer
CreateBGPPeer'
    { $sel:newBGPPeer':CreateBGPPeer' :: Maybe NewBGPPeer
newBGPPeer' = Maybe NewBGPPeer
forall a. Maybe a
Prelude.Nothing,
      $sel:virtualInterfaceId:CreateBGPPeer' :: Maybe Text
virtualInterfaceId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Information about the BGP peer.
createBGPPeer_newBGPPeer :: Lens.Lens' CreateBGPPeer (Prelude.Maybe NewBGPPeer)
createBGPPeer_newBGPPeer :: (Maybe NewBGPPeer -> f (Maybe NewBGPPeer))
-> CreateBGPPeer -> f CreateBGPPeer
createBGPPeer_newBGPPeer = (CreateBGPPeer -> Maybe NewBGPPeer)
-> (CreateBGPPeer -> Maybe NewBGPPeer -> CreateBGPPeer)
-> Lens
     CreateBGPPeer CreateBGPPeer (Maybe NewBGPPeer) (Maybe NewBGPPeer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBGPPeer' {Maybe NewBGPPeer
newBGPPeer' :: Maybe NewBGPPeer
$sel:newBGPPeer':CreateBGPPeer' :: CreateBGPPeer -> Maybe NewBGPPeer
newBGPPeer'} -> Maybe NewBGPPeer
newBGPPeer') (\s :: CreateBGPPeer
s@CreateBGPPeer' {} Maybe NewBGPPeer
a -> CreateBGPPeer
s {$sel:newBGPPeer':CreateBGPPeer' :: Maybe NewBGPPeer
newBGPPeer' = Maybe NewBGPPeer
a} :: CreateBGPPeer)

-- | The ID of the virtual interface.
createBGPPeer_virtualInterfaceId :: Lens.Lens' CreateBGPPeer (Prelude.Maybe Prelude.Text)
createBGPPeer_virtualInterfaceId :: (Maybe Text -> f (Maybe Text)) -> CreateBGPPeer -> f CreateBGPPeer
createBGPPeer_virtualInterfaceId = (CreateBGPPeer -> Maybe Text)
-> (CreateBGPPeer -> Maybe Text -> CreateBGPPeer)
-> Lens CreateBGPPeer CreateBGPPeer (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBGPPeer' {Maybe Text
virtualInterfaceId :: Maybe Text
$sel:virtualInterfaceId:CreateBGPPeer' :: CreateBGPPeer -> Maybe Text
virtualInterfaceId} -> Maybe Text
virtualInterfaceId) (\s :: CreateBGPPeer
s@CreateBGPPeer' {} Maybe Text
a -> CreateBGPPeer
s {$sel:virtualInterfaceId:CreateBGPPeer' :: Maybe Text
virtualInterfaceId = Maybe Text
a} :: CreateBGPPeer)

instance Core.AWSRequest CreateBGPPeer where
  type
    AWSResponse CreateBGPPeer =
      CreateBGPPeerResponse
  request :: CreateBGPPeer -> Request CreateBGPPeer
request = Service -> CreateBGPPeer -> Request CreateBGPPeer
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateBGPPeer
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateBGPPeer)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateBGPPeer))
-> Logger
-> Service
-> Proxy CreateBGPPeer
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateBGPPeer)))
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 VirtualInterface -> Int -> CreateBGPPeerResponse
CreateBGPPeerResponse'
            (Maybe VirtualInterface -> Int -> CreateBGPPeerResponse)
-> Either String (Maybe VirtualInterface)
-> Either String (Int -> CreateBGPPeerResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe VirtualInterface)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"virtualInterface")
            Either String (Int -> CreateBGPPeerResponse)
-> Either String Int -> Either String CreateBGPPeerResponse
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 CreateBGPPeer

instance Prelude.NFData CreateBGPPeer

instance Core.ToHeaders CreateBGPPeer where
  toHeaders :: CreateBGPPeer -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateBGPPeer -> 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.CreateBGPPeer" ::
                          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 CreateBGPPeer where
  toJSON :: CreateBGPPeer -> Value
toJSON CreateBGPPeer' {Maybe Text
Maybe NewBGPPeer
virtualInterfaceId :: Maybe Text
newBGPPeer' :: Maybe NewBGPPeer
$sel:virtualInterfaceId:CreateBGPPeer' :: CreateBGPPeer -> Maybe Text
$sel:newBGPPeer':CreateBGPPeer' :: CreateBGPPeer -> Maybe NewBGPPeer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"newBGPPeer" Text -> NewBGPPeer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NewBGPPeer -> Pair) -> Maybe NewBGPPeer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe NewBGPPeer
newBGPPeer',
            (Text
"virtualInterfaceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
virtualInterfaceId
          ]
      )

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

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

-- | /See:/ 'newCreateBGPPeerResponse' smart constructor.
data CreateBGPPeerResponse = CreateBGPPeerResponse'
  { -- | The virtual interface.
    CreateBGPPeerResponse -> Maybe VirtualInterface
virtualInterface :: Prelude.Maybe VirtualInterface,
    -- | The response's http status code.
    CreateBGPPeerResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateBGPPeerResponse -> CreateBGPPeerResponse -> Bool
(CreateBGPPeerResponse -> CreateBGPPeerResponse -> Bool)
-> (CreateBGPPeerResponse -> CreateBGPPeerResponse -> Bool)
-> Eq CreateBGPPeerResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBGPPeerResponse -> CreateBGPPeerResponse -> Bool
$c/= :: CreateBGPPeerResponse -> CreateBGPPeerResponse -> Bool
== :: CreateBGPPeerResponse -> CreateBGPPeerResponse -> Bool
$c== :: CreateBGPPeerResponse -> CreateBGPPeerResponse -> Bool
Prelude.Eq, ReadPrec [CreateBGPPeerResponse]
ReadPrec CreateBGPPeerResponse
Int -> ReadS CreateBGPPeerResponse
ReadS [CreateBGPPeerResponse]
(Int -> ReadS CreateBGPPeerResponse)
-> ReadS [CreateBGPPeerResponse]
-> ReadPrec CreateBGPPeerResponse
-> ReadPrec [CreateBGPPeerResponse]
-> Read CreateBGPPeerResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBGPPeerResponse]
$creadListPrec :: ReadPrec [CreateBGPPeerResponse]
readPrec :: ReadPrec CreateBGPPeerResponse
$creadPrec :: ReadPrec CreateBGPPeerResponse
readList :: ReadS [CreateBGPPeerResponse]
$creadList :: ReadS [CreateBGPPeerResponse]
readsPrec :: Int -> ReadS CreateBGPPeerResponse
$creadsPrec :: Int -> ReadS CreateBGPPeerResponse
Prelude.Read, Int -> CreateBGPPeerResponse -> ShowS
[CreateBGPPeerResponse] -> ShowS
CreateBGPPeerResponse -> String
(Int -> CreateBGPPeerResponse -> ShowS)
-> (CreateBGPPeerResponse -> String)
-> ([CreateBGPPeerResponse] -> ShowS)
-> Show CreateBGPPeerResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBGPPeerResponse] -> ShowS
$cshowList :: [CreateBGPPeerResponse] -> ShowS
show :: CreateBGPPeerResponse -> String
$cshow :: CreateBGPPeerResponse -> String
showsPrec :: Int -> CreateBGPPeerResponse -> ShowS
$cshowsPrec :: Int -> CreateBGPPeerResponse -> ShowS
Prelude.Show, (forall x. CreateBGPPeerResponse -> Rep CreateBGPPeerResponse x)
-> (forall x. Rep CreateBGPPeerResponse x -> CreateBGPPeerResponse)
-> Generic CreateBGPPeerResponse
forall x. Rep CreateBGPPeerResponse x -> CreateBGPPeerResponse
forall x. CreateBGPPeerResponse -> Rep CreateBGPPeerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateBGPPeerResponse x -> CreateBGPPeerResponse
$cfrom :: forall x. CreateBGPPeerResponse -> Rep CreateBGPPeerResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateBGPPeerResponse' 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:
--
-- 'virtualInterface', 'createBGPPeerResponse_virtualInterface' - The virtual interface.
--
-- 'httpStatus', 'createBGPPeerResponse_httpStatus' - The response's http status code.
newCreateBGPPeerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateBGPPeerResponse
newCreateBGPPeerResponse :: Int -> CreateBGPPeerResponse
newCreateBGPPeerResponse Int
pHttpStatus_ =
  CreateBGPPeerResponse' :: Maybe VirtualInterface -> Int -> CreateBGPPeerResponse
CreateBGPPeerResponse'
    { $sel:virtualInterface:CreateBGPPeerResponse' :: Maybe VirtualInterface
virtualInterface =
        Maybe VirtualInterface
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateBGPPeerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The virtual interface.
createBGPPeerResponse_virtualInterface :: Lens.Lens' CreateBGPPeerResponse (Prelude.Maybe VirtualInterface)
createBGPPeerResponse_virtualInterface :: (Maybe VirtualInterface -> f (Maybe VirtualInterface))
-> CreateBGPPeerResponse -> f CreateBGPPeerResponse
createBGPPeerResponse_virtualInterface = (CreateBGPPeerResponse -> Maybe VirtualInterface)
-> (CreateBGPPeerResponse
    -> Maybe VirtualInterface -> CreateBGPPeerResponse)
-> Lens
     CreateBGPPeerResponse
     CreateBGPPeerResponse
     (Maybe VirtualInterface)
     (Maybe VirtualInterface)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBGPPeerResponse' {Maybe VirtualInterface
virtualInterface :: Maybe VirtualInterface
$sel:virtualInterface:CreateBGPPeerResponse' :: CreateBGPPeerResponse -> Maybe VirtualInterface
virtualInterface} -> Maybe VirtualInterface
virtualInterface) (\s :: CreateBGPPeerResponse
s@CreateBGPPeerResponse' {} Maybe VirtualInterface
a -> CreateBGPPeerResponse
s {$sel:virtualInterface:CreateBGPPeerResponse' :: Maybe VirtualInterface
virtualInterface = Maybe VirtualInterface
a} :: CreateBGPPeerResponse)

-- | The response's http status code.
createBGPPeerResponse_httpStatus :: Lens.Lens' CreateBGPPeerResponse Prelude.Int
createBGPPeerResponse_httpStatus :: (Int -> f Int) -> CreateBGPPeerResponse -> f CreateBGPPeerResponse
createBGPPeerResponse_httpStatus = (CreateBGPPeerResponse -> Int)
-> (CreateBGPPeerResponse -> Int -> CreateBGPPeerResponse)
-> Lens CreateBGPPeerResponse CreateBGPPeerResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBGPPeerResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateBGPPeerResponse' :: CreateBGPPeerResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateBGPPeerResponse
s@CreateBGPPeerResponse' {} Int
a -> CreateBGPPeerResponse
s {$sel:httpStatus:CreateBGPPeerResponse' :: Int
httpStatus = Int
a} :: CreateBGPPeerResponse)

instance Prelude.NFData CreateBGPPeerResponse