{-# 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.StartCutover
-- 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)
--
-- Launches a Cutover Instance for specific Source Servers. This command
-- starts a LAUNCH job whose initiatedBy property is StartCutover and
-- changes the SourceServer.lifeCycle.state property to CUTTING_OVER.
module Amazonka.MGN.StartCutover
  ( -- * Creating a Request
    StartCutover (..),
    newStartCutover,

    -- * Request Lenses
    startCutover_tags,
    startCutover_sourceServerIDs,

    -- * Destructuring the Response
    StartCutoverResponse (..),
    newStartCutoverResponse,

    -- * Response Lenses
    startCutoverResponse_job,
    startCutoverResponse_httpStatus,
  )
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:/ 'newStartCutover' smart constructor.
data StartCutover = StartCutover'
  { -- | Start Cutover by Tags.
    StartCutover -> Maybe (Sensitive (HashMap Text Text))
tags :: Prelude.Maybe (Core.Sensitive (Prelude.HashMap Prelude.Text Prelude.Text)),
    -- | Start Cutover by Source Server IDs.
    StartCutover -> NonEmpty Text
sourceServerIDs :: Prelude.NonEmpty Prelude.Text
  }
  deriving (StartCutover -> StartCutover -> Bool
(StartCutover -> StartCutover -> Bool)
-> (StartCutover -> StartCutover -> Bool) -> Eq StartCutover
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartCutover -> StartCutover -> Bool
$c/= :: StartCutover -> StartCutover -> Bool
== :: StartCutover -> StartCutover -> Bool
$c== :: StartCutover -> StartCutover -> Bool
Prelude.Eq, Int -> StartCutover -> ShowS
[StartCutover] -> ShowS
StartCutover -> String
(Int -> StartCutover -> ShowS)
-> (StartCutover -> String)
-> ([StartCutover] -> ShowS)
-> Show StartCutover
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartCutover] -> ShowS
$cshowList :: [StartCutover] -> ShowS
show :: StartCutover -> String
$cshow :: StartCutover -> String
showsPrec :: Int -> StartCutover -> ShowS
$cshowsPrec :: Int -> StartCutover -> ShowS
Prelude.Show, (forall x. StartCutover -> Rep StartCutover x)
-> (forall x. Rep StartCutover x -> StartCutover)
-> Generic StartCutover
forall x. Rep StartCutover x -> StartCutover
forall x. StartCutover -> Rep StartCutover x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartCutover x -> StartCutover
$cfrom :: forall x. StartCutover -> Rep StartCutover x
Prelude.Generic)

-- |
-- Create a value of 'StartCutover' 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:
--
-- 'tags', 'startCutover_tags' - Start Cutover by Tags.
--
-- 'sourceServerIDs', 'startCutover_sourceServerIDs' - Start Cutover by Source Server IDs.
newStartCutover ::
  -- | 'sourceServerIDs'
  Prelude.NonEmpty Prelude.Text ->
  StartCutover
newStartCutover :: NonEmpty Text -> StartCutover
newStartCutover NonEmpty Text
pSourceServerIDs_ =
  StartCutover' :: Maybe (Sensitive (HashMap Text Text))
-> NonEmpty Text -> StartCutover
StartCutover'
    { $sel:tags:StartCutover' :: Maybe (Sensitive (HashMap Text Text))
tags = Maybe (Sensitive (HashMap Text Text))
forall a. Maybe a
Prelude.Nothing,
      $sel:sourceServerIDs:StartCutover' :: NonEmpty Text
sourceServerIDs =
        Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pSourceServerIDs_
    }

-- | Start Cutover by Tags.
startCutover_tags :: Lens.Lens' StartCutover (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
startCutover_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> StartCutover -> f StartCutover
startCutover_tags = (StartCutover -> Maybe (Sensitive (HashMap Text Text)))
-> (StartCutover
    -> Maybe (Sensitive (HashMap Text Text)) -> StartCutover)
-> Lens
     StartCutover
     StartCutover
     (Maybe (Sensitive (HashMap Text Text)))
     (Maybe (Sensitive (HashMap Text Text)))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartCutover' {Maybe (Sensitive (HashMap Text Text))
tags :: Maybe (Sensitive (HashMap Text Text))
$sel:tags:StartCutover' :: StartCutover -> Maybe (Sensitive (HashMap Text Text))
tags} -> Maybe (Sensitive (HashMap Text Text))
tags) (\s :: StartCutover
s@StartCutover' {} Maybe (Sensitive (HashMap Text Text))
a -> StartCutover
s {$sel:tags:StartCutover' :: Maybe (Sensitive (HashMap Text Text))
tags = Maybe (Sensitive (HashMap Text Text))
a} :: StartCutover) ((Maybe (Sensitive (HashMap Text Text))
  -> f (Maybe (Sensitive (HashMap Text Text))))
 -> StartCutover -> f StartCutover)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (Sensitive (HashMap Text Text))
    -> f (Maybe (Sensitive (HashMap Text Text))))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> StartCutover
-> f StartCutover
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (Sensitive (HashMap Text Text))
  (Sensitive (HashMap Text Text))
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (Sensitive (HashMap Text Text)))
     (Maybe (Sensitive (HashMap Text Text)))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping (AnIso
  (Sensitive (HashMap Text Text))
  (Sensitive (HashMap Text Text))
  (HashMap Text Text)
  (HashMap Text Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive AnIso
  (Sensitive (HashMap Text Text))
  (Sensitive (HashMap Text Text))
  (HashMap Text Text)
  (HashMap Text Text)
-> (Exchange
      (HashMap Text Text)
      (HashMap Text Text)
      (HashMap Text Text)
      (Identity (HashMap Text Text))
    -> Exchange
         (HashMap Text Text)
         (HashMap Text Text)
         (HashMap Text Text)
         (Identity (HashMap Text Text)))
-> AnIso
     (Sensitive (HashMap Text Text))
     (Sensitive (HashMap Text Text))
     (HashMap Text Text)
     (HashMap Text Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Exchange
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (Identity (HashMap Text Text))
-> Exchange
     (HashMap Text Text)
     (HashMap Text Text)
     (HashMap Text Text)
     (Identity (HashMap Text Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced)

-- | Start Cutover by Source Server IDs.
startCutover_sourceServerIDs :: Lens.Lens' StartCutover (Prelude.NonEmpty Prelude.Text)
startCutover_sourceServerIDs :: (NonEmpty Text -> f (NonEmpty Text))
-> StartCutover -> f StartCutover
startCutover_sourceServerIDs = (StartCutover -> NonEmpty Text)
-> (StartCutover -> NonEmpty Text -> StartCutover)
-> Lens StartCutover StartCutover (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartCutover' {NonEmpty Text
sourceServerIDs :: NonEmpty Text
$sel:sourceServerIDs:StartCutover' :: StartCutover -> NonEmpty Text
sourceServerIDs} -> NonEmpty Text
sourceServerIDs) (\s :: StartCutover
s@StartCutover' {} NonEmpty Text
a -> StartCutover
s {$sel:sourceServerIDs:StartCutover' :: NonEmpty Text
sourceServerIDs = NonEmpty Text
a} :: StartCutover) ((NonEmpty Text -> f (NonEmpty Text))
 -> StartCutover -> f StartCutover)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> StartCutover
-> f StartCutover
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData StartCutover

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

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

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

-- | /See:/ 'newStartCutoverResponse' smart constructor.
data StartCutoverResponse = StartCutoverResponse'
  { -- | Start Cutover Job response.
    StartCutoverResponse -> Maybe Job
job :: Prelude.Maybe Job,
    -- | The response's http status code.
    StartCutoverResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartCutoverResponse -> StartCutoverResponse -> Bool
(StartCutoverResponse -> StartCutoverResponse -> Bool)
-> (StartCutoverResponse -> StartCutoverResponse -> Bool)
-> Eq StartCutoverResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartCutoverResponse -> StartCutoverResponse -> Bool
$c/= :: StartCutoverResponse -> StartCutoverResponse -> Bool
== :: StartCutoverResponse -> StartCutoverResponse -> Bool
$c== :: StartCutoverResponse -> StartCutoverResponse -> Bool
Prelude.Eq, Int -> StartCutoverResponse -> ShowS
[StartCutoverResponse] -> ShowS
StartCutoverResponse -> String
(Int -> StartCutoverResponse -> ShowS)
-> (StartCutoverResponse -> String)
-> ([StartCutoverResponse] -> ShowS)
-> Show StartCutoverResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartCutoverResponse] -> ShowS
$cshowList :: [StartCutoverResponse] -> ShowS
show :: StartCutoverResponse -> String
$cshow :: StartCutoverResponse -> String
showsPrec :: Int -> StartCutoverResponse -> ShowS
$cshowsPrec :: Int -> StartCutoverResponse -> ShowS
Prelude.Show, (forall x. StartCutoverResponse -> Rep StartCutoverResponse x)
-> (forall x. Rep StartCutoverResponse x -> StartCutoverResponse)
-> Generic StartCutoverResponse
forall x. Rep StartCutoverResponse x -> StartCutoverResponse
forall x. StartCutoverResponse -> Rep StartCutoverResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartCutoverResponse x -> StartCutoverResponse
$cfrom :: forall x. StartCutoverResponse -> Rep StartCutoverResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartCutoverResponse' 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:
--
-- 'job', 'startCutoverResponse_job' - Start Cutover Job response.
--
-- 'httpStatus', 'startCutoverResponse_httpStatus' - The response's http status code.
newStartCutoverResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartCutoverResponse
newStartCutoverResponse :: Int -> StartCutoverResponse
newStartCutoverResponse Int
pHttpStatus_ =
  StartCutoverResponse' :: Maybe Job -> Int -> StartCutoverResponse
StartCutoverResponse'
    { $sel:job:StartCutoverResponse' :: Maybe Job
job = Maybe Job
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartCutoverResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Start Cutover Job response.
startCutoverResponse_job :: Lens.Lens' StartCutoverResponse (Prelude.Maybe Job)
startCutoverResponse_job :: (Maybe Job -> f (Maybe Job))
-> StartCutoverResponse -> f StartCutoverResponse
startCutoverResponse_job = (StartCutoverResponse -> Maybe Job)
-> (StartCutoverResponse -> Maybe Job -> StartCutoverResponse)
-> Lens
     StartCutoverResponse StartCutoverResponse (Maybe Job) (Maybe Job)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartCutoverResponse' {Maybe Job
job :: Maybe Job
$sel:job:StartCutoverResponse' :: StartCutoverResponse -> Maybe Job
job} -> Maybe Job
job) (\s :: StartCutoverResponse
s@StartCutoverResponse' {} Maybe Job
a -> StartCutoverResponse
s {$sel:job:StartCutoverResponse' :: Maybe Job
job = Maybe Job
a} :: StartCutoverResponse)

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

instance Prelude.NFData StartCutoverResponse