{-# 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.NetworkManager.RegisterTransitGateway
-- 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)
--
-- Registers a transit gateway in your global network. The transit gateway
-- can be in any AWS Region, but it must be owned by the same AWS account
-- that owns the global network. You cannot register a transit gateway in
-- more than one global network.
module Amazonka.NetworkManager.RegisterTransitGateway
  ( -- * Creating a Request
    RegisterTransitGateway (..),
    newRegisterTransitGateway,

    -- * Request Lenses
    registerTransitGateway_globalNetworkId,
    registerTransitGateway_transitGatewayArn,

    -- * Destructuring the Response
    RegisterTransitGatewayResponse (..),
    newRegisterTransitGatewayResponse,

    -- * Response Lenses
    registerTransitGatewayResponse_transitGatewayRegistration,
    registerTransitGatewayResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkManager.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRegisterTransitGateway' smart constructor.
data RegisterTransitGateway = RegisterTransitGateway'
  { -- | The ID of the global network.
    RegisterTransitGateway -> Text
globalNetworkId :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the transit gateway. For more
    -- information, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazonec2.html#amazonec2-resources-for-iam-policies Resources Defined by Amazon EC2>.
    RegisterTransitGateway -> Text
transitGatewayArn :: Prelude.Text
  }
  deriving (RegisterTransitGateway -> RegisterTransitGateway -> Bool
(RegisterTransitGateway -> RegisterTransitGateway -> Bool)
-> (RegisterTransitGateway -> RegisterTransitGateway -> Bool)
-> Eq RegisterTransitGateway
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterTransitGateway -> RegisterTransitGateway -> Bool
$c/= :: RegisterTransitGateway -> RegisterTransitGateway -> Bool
== :: RegisterTransitGateway -> RegisterTransitGateway -> Bool
$c== :: RegisterTransitGateway -> RegisterTransitGateway -> Bool
Prelude.Eq, ReadPrec [RegisterTransitGateway]
ReadPrec RegisterTransitGateway
Int -> ReadS RegisterTransitGateway
ReadS [RegisterTransitGateway]
(Int -> ReadS RegisterTransitGateway)
-> ReadS [RegisterTransitGateway]
-> ReadPrec RegisterTransitGateway
-> ReadPrec [RegisterTransitGateway]
-> Read RegisterTransitGateway
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterTransitGateway]
$creadListPrec :: ReadPrec [RegisterTransitGateway]
readPrec :: ReadPrec RegisterTransitGateway
$creadPrec :: ReadPrec RegisterTransitGateway
readList :: ReadS [RegisterTransitGateway]
$creadList :: ReadS [RegisterTransitGateway]
readsPrec :: Int -> ReadS RegisterTransitGateway
$creadsPrec :: Int -> ReadS RegisterTransitGateway
Prelude.Read, Int -> RegisterTransitGateway -> ShowS
[RegisterTransitGateway] -> ShowS
RegisterTransitGateway -> String
(Int -> RegisterTransitGateway -> ShowS)
-> (RegisterTransitGateway -> String)
-> ([RegisterTransitGateway] -> ShowS)
-> Show RegisterTransitGateway
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterTransitGateway] -> ShowS
$cshowList :: [RegisterTransitGateway] -> ShowS
show :: RegisterTransitGateway -> String
$cshow :: RegisterTransitGateway -> String
showsPrec :: Int -> RegisterTransitGateway -> ShowS
$cshowsPrec :: Int -> RegisterTransitGateway -> ShowS
Prelude.Show, (forall x. RegisterTransitGateway -> Rep RegisterTransitGateway x)
-> (forall x.
    Rep RegisterTransitGateway x -> RegisterTransitGateway)
-> Generic RegisterTransitGateway
forall x. Rep RegisterTransitGateway x -> RegisterTransitGateway
forall x. RegisterTransitGateway -> Rep RegisterTransitGateway x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterTransitGateway x -> RegisterTransitGateway
$cfrom :: forall x. RegisterTransitGateway -> Rep RegisterTransitGateway x
Prelude.Generic)

-- |
-- Create a value of 'RegisterTransitGateway' 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:
--
-- 'globalNetworkId', 'registerTransitGateway_globalNetworkId' - The ID of the global network.
--
-- 'transitGatewayArn', 'registerTransitGateway_transitGatewayArn' - The Amazon Resource Name (ARN) of the transit gateway. For more
-- information, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazonec2.html#amazonec2-resources-for-iam-policies Resources Defined by Amazon EC2>.
newRegisterTransitGateway ::
  -- | 'globalNetworkId'
  Prelude.Text ->
  -- | 'transitGatewayArn'
  Prelude.Text ->
  RegisterTransitGateway
newRegisterTransitGateway :: Text -> Text -> RegisterTransitGateway
newRegisterTransitGateway
  Text
pGlobalNetworkId_
  Text
pTransitGatewayArn_ =
    RegisterTransitGateway' :: Text -> Text -> RegisterTransitGateway
RegisterTransitGateway'
      { $sel:globalNetworkId:RegisterTransitGateway' :: Text
globalNetworkId =
          Text
pGlobalNetworkId_,
        $sel:transitGatewayArn:RegisterTransitGateway' :: Text
transitGatewayArn = Text
pTransitGatewayArn_
      }

-- | The ID of the global network.
registerTransitGateway_globalNetworkId :: Lens.Lens' RegisterTransitGateway Prelude.Text
registerTransitGateway_globalNetworkId :: (Text -> f Text)
-> RegisterTransitGateway -> f RegisterTransitGateway
registerTransitGateway_globalNetworkId = (RegisterTransitGateway -> Text)
-> (RegisterTransitGateway -> Text -> RegisterTransitGateway)
-> Lens RegisterTransitGateway RegisterTransitGateway Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterTransitGateway' {Text
globalNetworkId :: Text
$sel:globalNetworkId:RegisterTransitGateway' :: RegisterTransitGateway -> Text
globalNetworkId} -> Text
globalNetworkId) (\s :: RegisterTransitGateway
s@RegisterTransitGateway' {} Text
a -> RegisterTransitGateway
s {$sel:globalNetworkId:RegisterTransitGateway' :: Text
globalNetworkId = Text
a} :: RegisterTransitGateway)

-- | The Amazon Resource Name (ARN) of the transit gateway. For more
-- information, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazonec2.html#amazonec2-resources-for-iam-policies Resources Defined by Amazon EC2>.
registerTransitGateway_transitGatewayArn :: Lens.Lens' RegisterTransitGateway Prelude.Text
registerTransitGateway_transitGatewayArn :: (Text -> f Text)
-> RegisterTransitGateway -> f RegisterTransitGateway
registerTransitGateway_transitGatewayArn = (RegisterTransitGateway -> Text)
-> (RegisterTransitGateway -> Text -> RegisterTransitGateway)
-> Lens RegisterTransitGateway RegisterTransitGateway Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterTransitGateway' {Text
transitGatewayArn :: Text
$sel:transitGatewayArn:RegisterTransitGateway' :: RegisterTransitGateway -> Text
transitGatewayArn} -> Text
transitGatewayArn) (\s :: RegisterTransitGateway
s@RegisterTransitGateway' {} Text
a -> RegisterTransitGateway
s {$sel:transitGatewayArn:RegisterTransitGateway' :: Text
transitGatewayArn = Text
a} :: RegisterTransitGateway)

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

instance Prelude.NFData RegisterTransitGateway

instance Core.ToHeaders RegisterTransitGateway where
  toHeaders :: RegisterTransitGateway -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterTransitGateway -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 RegisterTransitGateway where
  toJSON :: RegisterTransitGateway -> Value
toJSON RegisterTransitGateway' {Text
transitGatewayArn :: Text
globalNetworkId :: Text
$sel:transitGatewayArn:RegisterTransitGateway' :: RegisterTransitGateway -> Text
$sel:globalNetworkId:RegisterTransitGateway' :: RegisterTransitGateway -> 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
"TransitGatewayArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
transitGatewayArn)
          ]
      )

instance Core.ToPath RegisterTransitGateway where
  toPath :: RegisterTransitGateway -> ByteString
toPath RegisterTransitGateway' {Text
transitGatewayArn :: Text
globalNetworkId :: Text
$sel:transitGatewayArn:RegisterTransitGateway' :: RegisterTransitGateway -> Text
$sel:globalNetworkId:RegisterTransitGateway' :: RegisterTransitGateway -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/global-networks/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
globalNetworkId,
        ByteString
"/transit-gateway-registrations"
      ]

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

-- | /See:/ 'newRegisterTransitGatewayResponse' smart constructor.
data RegisterTransitGatewayResponse = RegisterTransitGatewayResponse'
  { -- | Information about the transit gateway registration.
    RegisterTransitGatewayResponse -> Maybe TransitGatewayRegistration
transitGatewayRegistration :: Prelude.Maybe TransitGatewayRegistration,
    -- | The response's http status code.
    RegisterTransitGatewayResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterTransitGatewayResponse
-> RegisterTransitGatewayResponse -> Bool
(RegisterTransitGatewayResponse
 -> RegisterTransitGatewayResponse -> Bool)
-> (RegisterTransitGatewayResponse
    -> RegisterTransitGatewayResponse -> Bool)
-> Eq RegisterTransitGatewayResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterTransitGatewayResponse
-> RegisterTransitGatewayResponse -> Bool
$c/= :: RegisterTransitGatewayResponse
-> RegisterTransitGatewayResponse -> Bool
== :: RegisterTransitGatewayResponse
-> RegisterTransitGatewayResponse -> Bool
$c== :: RegisterTransitGatewayResponse
-> RegisterTransitGatewayResponse -> Bool
Prelude.Eq, ReadPrec [RegisterTransitGatewayResponse]
ReadPrec RegisterTransitGatewayResponse
Int -> ReadS RegisterTransitGatewayResponse
ReadS [RegisterTransitGatewayResponse]
(Int -> ReadS RegisterTransitGatewayResponse)
-> ReadS [RegisterTransitGatewayResponse]
-> ReadPrec RegisterTransitGatewayResponse
-> ReadPrec [RegisterTransitGatewayResponse]
-> Read RegisterTransitGatewayResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterTransitGatewayResponse]
$creadListPrec :: ReadPrec [RegisterTransitGatewayResponse]
readPrec :: ReadPrec RegisterTransitGatewayResponse
$creadPrec :: ReadPrec RegisterTransitGatewayResponse
readList :: ReadS [RegisterTransitGatewayResponse]
$creadList :: ReadS [RegisterTransitGatewayResponse]
readsPrec :: Int -> ReadS RegisterTransitGatewayResponse
$creadsPrec :: Int -> ReadS RegisterTransitGatewayResponse
Prelude.Read, Int -> RegisterTransitGatewayResponse -> ShowS
[RegisterTransitGatewayResponse] -> ShowS
RegisterTransitGatewayResponse -> String
(Int -> RegisterTransitGatewayResponse -> ShowS)
-> (RegisterTransitGatewayResponse -> String)
-> ([RegisterTransitGatewayResponse] -> ShowS)
-> Show RegisterTransitGatewayResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterTransitGatewayResponse] -> ShowS
$cshowList :: [RegisterTransitGatewayResponse] -> ShowS
show :: RegisterTransitGatewayResponse -> String
$cshow :: RegisterTransitGatewayResponse -> String
showsPrec :: Int -> RegisterTransitGatewayResponse -> ShowS
$cshowsPrec :: Int -> RegisterTransitGatewayResponse -> ShowS
Prelude.Show, (forall x.
 RegisterTransitGatewayResponse
 -> Rep RegisterTransitGatewayResponse x)
-> (forall x.
    Rep RegisterTransitGatewayResponse x
    -> RegisterTransitGatewayResponse)
-> Generic RegisterTransitGatewayResponse
forall x.
Rep RegisterTransitGatewayResponse x
-> RegisterTransitGatewayResponse
forall x.
RegisterTransitGatewayResponse
-> Rep RegisterTransitGatewayResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RegisterTransitGatewayResponse x
-> RegisterTransitGatewayResponse
$cfrom :: forall x.
RegisterTransitGatewayResponse
-> Rep RegisterTransitGatewayResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterTransitGatewayResponse' 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:
--
-- 'transitGatewayRegistration', 'registerTransitGatewayResponse_transitGatewayRegistration' - Information about the transit gateway registration.
--
-- 'httpStatus', 'registerTransitGatewayResponse_httpStatus' - The response's http status code.
newRegisterTransitGatewayResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterTransitGatewayResponse
newRegisterTransitGatewayResponse :: Int -> RegisterTransitGatewayResponse
newRegisterTransitGatewayResponse Int
pHttpStatus_ =
  RegisterTransitGatewayResponse' :: Maybe TransitGatewayRegistration
-> Int -> RegisterTransitGatewayResponse
RegisterTransitGatewayResponse'
    { $sel:transitGatewayRegistration:RegisterTransitGatewayResponse' :: Maybe TransitGatewayRegistration
transitGatewayRegistration =
        Maybe TransitGatewayRegistration
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RegisterTransitGatewayResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the transit gateway registration.
registerTransitGatewayResponse_transitGatewayRegistration :: Lens.Lens' RegisterTransitGatewayResponse (Prelude.Maybe TransitGatewayRegistration)
registerTransitGatewayResponse_transitGatewayRegistration :: (Maybe TransitGatewayRegistration
 -> f (Maybe TransitGatewayRegistration))
-> RegisterTransitGatewayResponse
-> f RegisterTransitGatewayResponse
registerTransitGatewayResponse_transitGatewayRegistration = (RegisterTransitGatewayResponse
 -> Maybe TransitGatewayRegistration)
-> (RegisterTransitGatewayResponse
    -> Maybe TransitGatewayRegistration
    -> RegisterTransitGatewayResponse)
-> Lens
     RegisterTransitGatewayResponse
     RegisterTransitGatewayResponse
     (Maybe TransitGatewayRegistration)
     (Maybe TransitGatewayRegistration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterTransitGatewayResponse' {Maybe TransitGatewayRegistration
transitGatewayRegistration :: Maybe TransitGatewayRegistration
$sel:transitGatewayRegistration:RegisterTransitGatewayResponse' :: RegisterTransitGatewayResponse -> Maybe TransitGatewayRegistration
transitGatewayRegistration} -> Maybe TransitGatewayRegistration
transitGatewayRegistration) (\s :: RegisterTransitGatewayResponse
s@RegisterTransitGatewayResponse' {} Maybe TransitGatewayRegistration
a -> RegisterTransitGatewayResponse
s {$sel:transitGatewayRegistration:RegisterTransitGatewayResponse' :: Maybe TransitGatewayRegistration
transitGatewayRegistration = Maybe TransitGatewayRegistration
a} :: RegisterTransitGatewayResponse)

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

instance
  Prelude.NFData
    RegisterTransitGatewayResponse