{-# 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.DrS.ReverseReplication
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Start replication to origin \/ target region - applies only to protected
-- instances that originated in EC2. For recovery instances on target
-- region - starts replication back to origin region. For failback
-- instances on origin region - starts replication to target region to
-- re-protect them.
module Amazonka.DrS.ReverseReplication
  ( -- * Creating a Request
    ReverseReplication (..),
    newReverseReplication,

    -- * Request Lenses
    reverseReplication_recoveryInstanceID,

    -- * Destructuring the Response
    ReverseReplicationResponse (..),
    newReverseReplicationResponse,

    -- * Response Lenses
    reverseReplicationResponse_reversedDirectionSourceServerArn,
    reverseReplicationResponse_httpStatus,
  )
where

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

-- | /See:/ 'newReverseReplication' smart constructor.
data ReverseReplication = ReverseReplication'
  { -- | The ID of the Recovery Instance that we want to reverse the replication
    -- for.
    ReverseReplication -> Text
recoveryInstanceID :: Prelude.Text
  }
  deriving (ReverseReplication -> ReverseReplication -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReverseReplication -> ReverseReplication -> Bool
$c/= :: ReverseReplication -> ReverseReplication -> Bool
== :: ReverseReplication -> ReverseReplication -> Bool
$c== :: ReverseReplication -> ReverseReplication -> Bool
Prelude.Eq, ReadPrec [ReverseReplication]
ReadPrec ReverseReplication
Int -> ReadS ReverseReplication
ReadS [ReverseReplication]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReverseReplication]
$creadListPrec :: ReadPrec [ReverseReplication]
readPrec :: ReadPrec ReverseReplication
$creadPrec :: ReadPrec ReverseReplication
readList :: ReadS [ReverseReplication]
$creadList :: ReadS [ReverseReplication]
readsPrec :: Int -> ReadS ReverseReplication
$creadsPrec :: Int -> ReadS ReverseReplication
Prelude.Read, Int -> ReverseReplication -> ShowS
[ReverseReplication] -> ShowS
ReverseReplication -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReverseReplication] -> ShowS
$cshowList :: [ReverseReplication] -> ShowS
show :: ReverseReplication -> String
$cshow :: ReverseReplication -> String
showsPrec :: Int -> ReverseReplication -> ShowS
$cshowsPrec :: Int -> ReverseReplication -> ShowS
Prelude.Show, forall x. Rep ReverseReplication x -> ReverseReplication
forall x. ReverseReplication -> Rep ReverseReplication x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReverseReplication x -> ReverseReplication
$cfrom :: forall x. ReverseReplication -> Rep ReverseReplication x
Prelude.Generic)

-- |
-- Create a value of 'ReverseReplication' 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:
--
-- 'recoveryInstanceID', 'reverseReplication_recoveryInstanceID' - The ID of the Recovery Instance that we want to reverse the replication
-- for.
newReverseReplication ::
  -- | 'recoveryInstanceID'
  Prelude.Text ->
  ReverseReplication
newReverseReplication :: Text -> ReverseReplication
newReverseReplication Text
pRecoveryInstanceID_ =
  ReverseReplication'
    { $sel:recoveryInstanceID:ReverseReplication' :: Text
recoveryInstanceID =
        Text
pRecoveryInstanceID_
    }

-- | The ID of the Recovery Instance that we want to reverse the replication
-- for.
reverseReplication_recoveryInstanceID :: Lens.Lens' ReverseReplication Prelude.Text
reverseReplication_recoveryInstanceID :: Lens' ReverseReplication Text
reverseReplication_recoveryInstanceID = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReverseReplication' {Text
recoveryInstanceID :: Text
$sel:recoveryInstanceID:ReverseReplication' :: ReverseReplication -> Text
recoveryInstanceID} -> Text
recoveryInstanceID) (\s :: ReverseReplication
s@ReverseReplication' {} Text
a -> ReverseReplication
s {$sel:recoveryInstanceID:ReverseReplication' :: Text
recoveryInstanceID = Text
a} :: ReverseReplication)

instance Core.AWSRequest ReverseReplication where
  type
    AWSResponse ReverseReplication =
      ReverseReplicationResponse
  request :: (Service -> Service)
-> ReverseReplication -> Request ReverseReplication
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 ReverseReplication
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ReverseReplication)))
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 -> ReverseReplicationResponse
ReverseReplicationResponse'
            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
"reversedDirectionSourceServerArn")
            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 ReverseReplication where
  hashWithSalt :: Int -> ReverseReplication -> Int
hashWithSalt Int
_salt ReverseReplication' {Text
recoveryInstanceID :: Text
$sel:recoveryInstanceID:ReverseReplication' :: ReverseReplication -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
recoveryInstanceID

instance Prelude.NFData ReverseReplication where
  rnf :: ReverseReplication -> ()
rnf ReverseReplication' {Text
recoveryInstanceID :: Text
$sel:recoveryInstanceID:ReverseReplication' :: ReverseReplication -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
recoveryInstanceID

instance Data.ToHeaders ReverseReplication where
  toHeaders :: ReverseReplication -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

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

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

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

-- |
-- Create a value of 'ReverseReplicationResponse' 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:
--
-- 'reversedDirectionSourceServerArn', 'reverseReplicationResponse_reversedDirectionSourceServerArn' - ARN of created SourceServer.
--
-- 'httpStatus', 'reverseReplicationResponse_httpStatus' - The response's http status code.
newReverseReplicationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ReverseReplicationResponse
newReverseReplicationResponse :: Int -> ReverseReplicationResponse
newReverseReplicationResponse Int
pHttpStatus_ =
  ReverseReplicationResponse'
    { $sel:reversedDirectionSourceServerArn:ReverseReplicationResponse' :: Maybe Text
reversedDirectionSourceServerArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ReverseReplicationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | ARN of created SourceServer.
reverseReplicationResponse_reversedDirectionSourceServerArn :: Lens.Lens' ReverseReplicationResponse (Prelude.Maybe Prelude.Text)
reverseReplicationResponse_reversedDirectionSourceServerArn :: Lens' ReverseReplicationResponse (Maybe Text)
reverseReplicationResponse_reversedDirectionSourceServerArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReverseReplicationResponse' {Maybe Text
reversedDirectionSourceServerArn :: Maybe Text
$sel:reversedDirectionSourceServerArn:ReverseReplicationResponse' :: ReverseReplicationResponse -> Maybe Text
reversedDirectionSourceServerArn} -> Maybe Text
reversedDirectionSourceServerArn) (\s :: ReverseReplicationResponse
s@ReverseReplicationResponse' {} Maybe Text
a -> ReverseReplicationResponse
s {$sel:reversedDirectionSourceServerArn:ReverseReplicationResponse' :: Maybe Text
reversedDirectionSourceServerArn = Maybe Text
a} :: ReverseReplicationResponse)

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

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