{-# 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.MGN.ChangeServerLifeCycleState
-- 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)
--
-- Allows the user to set the SourceServer.LifeCycle.state property for
-- specific Source Server IDs to one of the following: READY_FOR_TEST or
-- READY_FOR_CUTOVER. This command only works if the Source Server is
-- already launchable (dataReplicationInfo.lagDuration is not null.)
module Amazonka.MGN.ChangeServerLifeCycleState
  ( -- * Creating a Request
    ChangeServerLifeCycleState (..),
    newChangeServerLifeCycleState,

    -- * Request Lenses
    changeServerLifeCycleState_lifeCycle,
    changeServerLifeCycleState_sourceServerID,

    -- * Destructuring the Response
    SourceServer (..),
    newSourceServer,

    -- * Response Lenses
    sourceServer_sourceProperties,
    sourceServer_arn,
    sourceServer_launchedInstance,
    sourceServer_lifeCycle,
    sourceServer_isArchived,
    sourceServer_dataReplicationInfo,
    sourceServer_sourceServerID,
    sourceServer_tags,
  )
where

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

-- | /See:/ 'newChangeServerLifeCycleState' smart constructor.
data ChangeServerLifeCycleState = ChangeServerLifeCycleState'
  { -- | The request to change the source server migration lifecycle state.
    ChangeServerLifeCycleState
-> ChangeServerLifeCycleStateSourceServerLifecycle
lifeCycle :: ChangeServerLifeCycleStateSourceServerLifecycle,
    -- | The request to change the source server migration lifecycle state by
    -- source server ID.
    ChangeServerLifeCycleState -> Text
sourceServerID :: Prelude.Text
  }
  deriving (ChangeServerLifeCycleState -> ChangeServerLifeCycleState -> Bool
(ChangeServerLifeCycleState -> ChangeServerLifeCycleState -> Bool)
-> (ChangeServerLifeCycleState
    -> ChangeServerLifeCycleState -> Bool)
-> Eq ChangeServerLifeCycleState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChangeServerLifeCycleState -> ChangeServerLifeCycleState -> Bool
$c/= :: ChangeServerLifeCycleState -> ChangeServerLifeCycleState -> Bool
== :: ChangeServerLifeCycleState -> ChangeServerLifeCycleState -> Bool
$c== :: ChangeServerLifeCycleState -> ChangeServerLifeCycleState -> Bool
Prelude.Eq, ReadPrec [ChangeServerLifeCycleState]
ReadPrec ChangeServerLifeCycleState
Int -> ReadS ChangeServerLifeCycleState
ReadS [ChangeServerLifeCycleState]
(Int -> ReadS ChangeServerLifeCycleState)
-> ReadS [ChangeServerLifeCycleState]
-> ReadPrec ChangeServerLifeCycleState
-> ReadPrec [ChangeServerLifeCycleState]
-> Read ChangeServerLifeCycleState
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ChangeServerLifeCycleState]
$creadListPrec :: ReadPrec [ChangeServerLifeCycleState]
readPrec :: ReadPrec ChangeServerLifeCycleState
$creadPrec :: ReadPrec ChangeServerLifeCycleState
readList :: ReadS [ChangeServerLifeCycleState]
$creadList :: ReadS [ChangeServerLifeCycleState]
readsPrec :: Int -> ReadS ChangeServerLifeCycleState
$creadsPrec :: Int -> ReadS ChangeServerLifeCycleState
Prelude.Read, Int -> ChangeServerLifeCycleState -> ShowS
[ChangeServerLifeCycleState] -> ShowS
ChangeServerLifeCycleState -> String
(Int -> ChangeServerLifeCycleState -> ShowS)
-> (ChangeServerLifeCycleState -> String)
-> ([ChangeServerLifeCycleState] -> ShowS)
-> Show ChangeServerLifeCycleState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChangeServerLifeCycleState] -> ShowS
$cshowList :: [ChangeServerLifeCycleState] -> ShowS
show :: ChangeServerLifeCycleState -> String
$cshow :: ChangeServerLifeCycleState -> String
showsPrec :: Int -> ChangeServerLifeCycleState -> ShowS
$cshowsPrec :: Int -> ChangeServerLifeCycleState -> ShowS
Prelude.Show, (forall x.
 ChangeServerLifeCycleState -> Rep ChangeServerLifeCycleState x)
-> (forall x.
    Rep ChangeServerLifeCycleState x -> ChangeServerLifeCycleState)
-> Generic ChangeServerLifeCycleState
forall x.
Rep ChangeServerLifeCycleState x -> ChangeServerLifeCycleState
forall x.
ChangeServerLifeCycleState -> Rep ChangeServerLifeCycleState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ChangeServerLifeCycleState x -> ChangeServerLifeCycleState
$cfrom :: forall x.
ChangeServerLifeCycleState -> Rep ChangeServerLifeCycleState x
Prelude.Generic)

-- |
-- Create a value of 'ChangeServerLifeCycleState' 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:
--
-- 'lifeCycle', 'changeServerLifeCycleState_lifeCycle' - The request to change the source server migration lifecycle state.
--
-- 'sourceServerID', 'changeServerLifeCycleState_sourceServerID' - The request to change the source server migration lifecycle state by
-- source server ID.
newChangeServerLifeCycleState ::
  -- | 'lifeCycle'
  ChangeServerLifeCycleStateSourceServerLifecycle ->
  -- | 'sourceServerID'
  Prelude.Text ->
  ChangeServerLifeCycleState
newChangeServerLifeCycleState :: ChangeServerLifeCycleStateSourceServerLifecycle
-> Text -> ChangeServerLifeCycleState
newChangeServerLifeCycleState
  ChangeServerLifeCycleStateSourceServerLifecycle
pLifeCycle_
  Text
pSourceServerID_ =
    ChangeServerLifeCycleState' :: ChangeServerLifeCycleStateSourceServerLifecycle
-> Text -> ChangeServerLifeCycleState
ChangeServerLifeCycleState'
      { $sel:lifeCycle:ChangeServerLifeCycleState' :: ChangeServerLifeCycleStateSourceServerLifecycle
lifeCycle =
          ChangeServerLifeCycleStateSourceServerLifecycle
pLifeCycle_,
        $sel:sourceServerID:ChangeServerLifeCycleState' :: Text
sourceServerID = Text
pSourceServerID_
      }

-- | The request to change the source server migration lifecycle state.
changeServerLifeCycleState_lifeCycle :: Lens.Lens' ChangeServerLifeCycleState ChangeServerLifeCycleStateSourceServerLifecycle
changeServerLifeCycleState_lifeCycle :: (ChangeServerLifeCycleStateSourceServerLifecycle
 -> f ChangeServerLifeCycleStateSourceServerLifecycle)
-> ChangeServerLifeCycleState -> f ChangeServerLifeCycleState
changeServerLifeCycleState_lifeCycle = (ChangeServerLifeCycleState
 -> ChangeServerLifeCycleStateSourceServerLifecycle)
-> (ChangeServerLifeCycleState
    -> ChangeServerLifeCycleStateSourceServerLifecycle
    -> ChangeServerLifeCycleState)
-> Lens
     ChangeServerLifeCycleState
     ChangeServerLifeCycleState
     ChangeServerLifeCycleStateSourceServerLifecycle
     ChangeServerLifeCycleStateSourceServerLifecycle
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangeServerLifeCycleState' {ChangeServerLifeCycleStateSourceServerLifecycle
lifeCycle :: ChangeServerLifeCycleStateSourceServerLifecycle
$sel:lifeCycle:ChangeServerLifeCycleState' :: ChangeServerLifeCycleState
-> ChangeServerLifeCycleStateSourceServerLifecycle
lifeCycle} -> ChangeServerLifeCycleStateSourceServerLifecycle
lifeCycle) (\s :: ChangeServerLifeCycleState
s@ChangeServerLifeCycleState' {} ChangeServerLifeCycleStateSourceServerLifecycle
a -> ChangeServerLifeCycleState
s {$sel:lifeCycle:ChangeServerLifeCycleState' :: ChangeServerLifeCycleStateSourceServerLifecycle
lifeCycle = ChangeServerLifeCycleStateSourceServerLifecycle
a} :: ChangeServerLifeCycleState)

-- | The request to change the source server migration lifecycle state by
-- source server ID.
changeServerLifeCycleState_sourceServerID :: Lens.Lens' ChangeServerLifeCycleState Prelude.Text
changeServerLifeCycleState_sourceServerID :: (Text -> f Text)
-> ChangeServerLifeCycleState -> f ChangeServerLifeCycleState
changeServerLifeCycleState_sourceServerID = (ChangeServerLifeCycleState -> Text)
-> (ChangeServerLifeCycleState
    -> Text -> ChangeServerLifeCycleState)
-> Lens
     ChangeServerLifeCycleState ChangeServerLifeCycleState Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangeServerLifeCycleState' {Text
sourceServerID :: Text
$sel:sourceServerID:ChangeServerLifeCycleState' :: ChangeServerLifeCycleState -> Text
sourceServerID} -> Text
sourceServerID) (\s :: ChangeServerLifeCycleState
s@ChangeServerLifeCycleState' {} Text
a -> ChangeServerLifeCycleState
s {$sel:sourceServerID:ChangeServerLifeCycleState' :: Text
sourceServerID = Text
a} :: ChangeServerLifeCycleState)

instance Core.AWSRequest ChangeServerLifeCycleState where
  type
    AWSResponse ChangeServerLifeCycleState =
      SourceServer
  request :: ChangeServerLifeCycleState -> Request ChangeServerLifeCycleState
request = Service
-> ChangeServerLifeCycleState -> Request ChangeServerLifeCycleState
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ChangeServerLifeCycleState
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ChangeServerLifeCycleState)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ChangeServerLifeCycleState))
-> Logger
-> Service
-> Proxy ChangeServerLifeCycleState
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ChangeServerLifeCycleState)))
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 -> Object -> Either String SourceServer
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable ChangeServerLifeCycleState

instance Prelude.NFData ChangeServerLifeCycleState

instance Core.ToHeaders ChangeServerLifeCycleState where
  toHeaders :: ChangeServerLifeCycleState -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ChangeServerLifeCycleState -> 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 ChangeServerLifeCycleState where
  toJSON :: ChangeServerLifeCycleState -> Value
toJSON ChangeServerLifeCycleState' {Text
ChangeServerLifeCycleStateSourceServerLifecycle
sourceServerID :: Text
lifeCycle :: ChangeServerLifeCycleStateSourceServerLifecycle
$sel:sourceServerID:ChangeServerLifeCycleState' :: ChangeServerLifeCycleState -> Text
$sel:lifeCycle:ChangeServerLifeCycleState' :: ChangeServerLifeCycleState
-> ChangeServerLifeCycleStateSourceServerLifecycle
..} =
    [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
"lifeCycle" Text -> ChangeServerLifeCycleStateSourceServerLifecycle -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ChangeServerLifeCycleStateSourceServerLifecycle
lifeCycle),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"sourceServerID" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
sourceServerID)
          ]
      )

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

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