{-# 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.BackupGateway.AssociateGatewayToServer
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Associates a backup gateway with your server. After you complete the
-- association process, you can back up and restore your VMs through the
-- gateway.
module Amazonka.BackupGateway.AssociateGatewayToServer
  ( -- * Creating a Request
    AssociateGatewayToServer (..),
    newAssociateGatewayToServer,

    -- * Request Lenses
    associateGatewayToServer_gatewayArn,
    associateGatewayToServer_serverArn,

    -- * Destructuring the Response
    AssociateGatewayToServerResponse (..),
    newAssociateGatewayToServerResponse,

    -- * Response Lenses
    associateGatewayToServerResponse_gatewayArn,
    associateGatewayToServerResponse_httpStatus,
  )
where

import Amazonka.BackupGateway.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociateGatewayToServer' smart constructor.
data AssociateGatewayToServer = AssociateGatewayToServer'
  { -- | The Amazon Resource Name (ARN) of the gateway. Use the @ListGateways@
    -- operation to return a list of gateways for your account and Amazon Web
    -- Services Region.
    AssociateGatewayToServer -> Text
gatewayArn :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the server that hosts your virtual
    -- machines.
    AssociateGatewayToServer -> Text
serverArn :: Prelude.Text
  }
  deriving (AssociateGatewayToServer -> AssociateGatewayToServer -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateGatewayToServer -> AssociateGatewayToServer -> Bool
$c/= :: AssociateGatewayToServer -> AssociateGatewayToServer -> Bool
== :: AssociateGatewayToServer -> AssociateGatewayToServer -> Bool
$c== :: AssociateGatewayToServer -> AssociateGatewayToServer -> Bool
Prelude.Eq, ReadPrec [AssociateGatewayToServer]
ReadPrec AssociateGatewayToServer
Int -> ReadS AssociateGatewayToServer
ReadS [AssociateGatewayToServer]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateGatewayToServer]
$creadListPrec :: ReadPrec [AssociateGatewayToServer]
readPrec :: ReadPrec AssociateGatewayToServer
$creadPrec :: ReadPrec AssociateGatewayToServer
readList :: ReadS [AssociateGatewayToServer]
$creadList :: ReadS [AssociateGatewayToServer]
readsPrec :: Int -> ReadS AssociateGatewayToServer
$creadsPrec :: Int -> ReadS AssociateGatewayToServer
Prelude.Read, Int -> AssociateGatewayToServer -> ShowS
[AssociateGatewayToServer] -> ShowS
AssociateGatewayToServer -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateGatewayToServer] -> ShowS
$cshowList :: [AssociateGatewayToServer] -> ShowS
show :: AssociateGatewayToServer -> String
$cshow :: AssociateGatewayToServer -> String
showsPrec :: Int -> AssociateGatewayToServer -> ShowS
$cshowsPrec :: Int -> AssociateGatewayToServer -> ShowS
Prelude.Show, forall x.
Rep AssociateGatewayToServer x -> AssociateGatewayToServer
forall x.
AssociateGatewayToServer -> Rep AssociateGatewayToServer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateGatewayToServer x -> AssociateGatewayToServer
$cfrom :: forall x.
AssociateGatewayToServer -> Rep AssociateGatewayToServer x
Prelude.Generic)

-- |
-- Create a value of 'AssociateGatewayToServer' 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:
--
-- 'gatewayArn', 'associateGatewayToServer_gatewayArn' - The Amazon Resource Name (ARN) of the gateway. Use the @ListGateways@
-- operation to return a list of gateways for your account and Amazon Web
-- Services Region.
--
-- 'serverArn', 'associateGatewayToServer_serverArn' - The Amazon Resource Name (ARN) of the server that hosts your virtual
-- machines.
newAssociateGatewayToServer ::
  -- | 'gatewayArn'
  Prelude.Text ->
  -- | 'serverArn'
  Prelude.Text ->
  AssociateGatewayToServer
newAssociateGatewayToServer :: Text -> Text -> AssociateGatewayToServer
newAssociateGatewayToServer Text
pGatewayArn_ Text
pServerArn_ =
  AssociateGatewayToServer'
    { $sel:gatewayArn:AssociateGatewayToServer' :: Text
gatewayArn =
        Text
pGatewayArn_,
      $sel:serverArn:AssociateGatewayToServer' :: Text
serverArn = Text
pServerArn_
    }

-- | The Amazon Resource Name (ARN) of the gateway. Use the @ListGateways@
-- operation to return a list of gateways for your account and Amazon Web
-- Services Region.
associateGatewayToServer_gatewayArn :: Lens.Lens' AssociateGatewayToServer Prelude.Text
associateGatewayToServer_gatewayArn :: Lens' AssociateGatewayToServer Text
associateGatewayToServer_gatewayArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateGatewayToServer' {Text
gatewayArn :: Text
$sel:gatewayArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
gatewayArn} -> Text
gatewayArn) (\s :: AssociateGatewayToServer
s@AssociateGatewayToServer' {} Text
a -> AssociateGatewayToServer
s {$sel:gatewayArn:AssociateGatewayToServer' :: Text
gatewayArn = Text
a} :: AssociateGatewayToServer)

-- | The Amazon Resource Name (ARN) of the server that hosts your virtual
-- machines.
associateGatewayToServer_serverArn :: Lens.Lens' AssociateGatewayToServer Prelude.Text
associateGatewayToServer_serverArn :: Lens' AssociateGatewayToServer Text
associateGatewayToServer_serverArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateGatewayToServer' {Text
serverArn :: Text
$sel:serverArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
serverArn} -> Text
serverArn) (\s :: AssociateGatewayToServer
s@AssociateGatewayToServer' {} Text
a -> AssociateGatewayToServer
s {$sel:serverArn:AssociateGatewayToServer' :: Text
serverArn = Text
a} :: AssociateGatewayToServer)

instance Core.AWSRequest AssociateGatewayToServer where
  type
    AWSResponse AssociateGatewayToServer =
      AssociateGatewayToServerResponse
  request :: (Service -> Service)
-> AssociateGatewayToServer -> Request AssociateGatewayToServer
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 AssociateGatewayToServer
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateGatewayToServer)))
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 ->
          Maybe Text -> Int -> AssociateGatewayToServerResponse
AssociateGatewayToServerResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"GatewayArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AssociateGatewayToServer where
  hashWithSalt :: Int -> AssociateGatewayToServer -> Int
hashWithSalt Int
_salt AssociateGatewayToServer' {Text
serverArn :: Text
gatewayArn :: Text
$sel:serverArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
$sel:gatewayArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
gatewayArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
serverArn

instance Prelude.NFData AssociateGatewayToServer where
  rnf :: AssociateGatewayToServer -> ()
rnf AssociateGatewayToServer' {Text
serverArn :: Text
gatewayArn :: Text
$sel:serverArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
$sel:gatewayArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
gatewayArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
serverArn

instance Data.ToHeaders AssociateGatewayToServer where
  toHeaders :: AssociateGatewayToServer -> 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
"BackupOnPremises_v20210101.AssociateGatewayToServer" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON AssociateGatewayToServer where
  toJSON :: AssociateGatewayToServer -> Value
toJSON AssociateGatewayToServer' {Text
serverArn :: Text
gatewayArn :: Text
$sel:serverArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
$sel:gatewayArn:AssociateGatewayToServer' :: AssociateGatewayToServer -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"GatewayArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
gatewayArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"ServerArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
serverArn)
          ]
      )

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

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

-- | /See:/ 'newAssociateGatewayToServerResponse' smart constructor.
data AssociateGatewayToServerResponse = AssociateGatewayToServerResponse'
  { -- | The Amazon Resource Name (ARN) of a gateway.
    AssociateGatewayToServerResponse -> Maybe Text
gatewayArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    AssociateGatewayToServerResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AssociateGatewayToServerResponse
-> AssociateGatewayToServerResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateGatewayToServerResponse
-> AssociateGatewayToServerResponse -> Bool
$c/= :: AssociateGatewayToServerResponse
-> AssociateGatewayToServerResponse -> Bool
== :: AssociateGatewayToServerResponse
-> AssociateGatewayToServerResponse -> Bool
$c== :: AssociateGatewayToServerResponse
-> AssociateGatewayToServerResponse -> Bool
Prelude.Eq, ReadPrec [AssociateGatewayToServerResponse]
ReadPrec AssociateGatewayToServerResponse
Int -> ReadS AssociateGatewayToServerResponse
ReadS [AssociateGatewayToServerResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateGatewayToServerResponse]
$creadListPrec :: ReadPrec [AssociateGatewayToServerResponse]
readPrec :: ReadPrec AssociateGatewayToServerResponse
$creadPrec :: ReadPrec AssociateGatewayToServerResponse
readList :: ReadS [AssociateGatewayToServerResponse]
$creadList :: ReadS [AssociateGatewayToServerResponse]
readsPrec :: Int -> ReadS AssociateGatewayToServerResponse
$creadsPrec :: Int -> ReadS AssociateGatewayToServerResponse
Prelude.Read, Int -> AssociateGatewayToServerResponse -> ShowS
[AssociateGatewayToServerResponse] -> ShowS
AssociateGatewayToServerResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateGatewayToServerResponse] -> ShowS
$cshowList :: [AssociateGatewayToServerResponse] -> ShowS
show :: AssociateGatewayToServerResponse -> String
$cshow :: AssociateGatewayToServerResponse -> String
showsPrec :: Int -> AssociateGatewayToServerResponse -> ShowS
$cshowsPrec :: Int -> AssociateGatewayToServerResponse -> ShowS
Prelude.Show, forall x.
Rep AssociateGatewayToServerResponse x
-> AssociateGatewayToServerResponse
forall x.
AssociateGatewayToServerResponse
-> Rep AssociateGatewayToServerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateGatewayToServerResponse x
-> AssociateGatewayToServerResponse
$cfrom :: forall x.
AssociateGatewayToServerResponse
-> Rep AssociateGatewayToServerResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateGatewayToServerResponse' 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:
--
-- 'gatewayArn', 'associateGatewayToServerResponse_gatewayArn' - The Amazon Resource Name (ARN) of a gateway.
--
-- 'httpStatus', 'associateGatewayToServerResponse_httpStatus' - The response's http status code.
newAssociateGatewayToServerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateGatewayToServerResponse
newAssociateGatewayToServerResponse :: Int -> AssociateGatewayToServerResponse
newAssociateGatewayToServerResponse Int
pHttpStatus_ =
  AssociateGatewayToServerResponse'
    { $sel:gatewayArn:AssociateGatewayToServerResponse' :: Maybe Text
gatewayArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociateGatewayToServerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of a gateway.
associateGatewayToServerResponse_gatewayArn :: Lens.Lens' AssociateGatewayToServerResponse (Prelude.Maybe Prelude.Text)
associateGatewayToServerResponse_gatewayArn :: Lens' AssociateGatewayToServerResponse (Maybe Text)
associateGatewayToServerResponse_gatewayArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateGatewayToServerResponse' {Maybe Text
gatewayArn :: Maybe Text
$sel:gatewayArn:AssociateGatewayToServerResponse' :: AssociateGatewayToServerResponse -> Maybe Text
gatewayArn} -> Maybe Text
gatewayArn) (\s :: AssociateGatewayToServerResponse
s@AssociateGatewayToServerResponse' {} Maybe Text
a -> AssociateGatewayToServerResponse
s {$sel:gatewayArn:AssociateGatewayToServerResponse' :: Maybe Text
gatewayArn = Maybe Text
a} :: AssociateGatewayToServerResponse)

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

instance
  Prelude.NFData
    AssociateGatewayToServerResponse
  where
  rnf :: AssociateGatewayToServerResponse -> ()
rnf AssociateGatewayToServerResponse' {Int
Maybe Text
httpStatus :: Int
gatewayArn :: Maybe Text
$sel:httpStatus:AssociateGatewayToServerResponse' :: AssociateGatewayToServerResponse -> Int
$sel:gatewayArn:AssociateGatewayToServerResponse' :: AssociateGatewayToServerResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
gatewayArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus