{-# 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.Lightsail.StartInstance
-- 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)
--
-- Starts a specific Amazon Lightsail instance from a stopped state. To
-- restart an instance, use the @reboot instance@ operation.
--
-- When you start a stopped instance, Lightsail assigns a new public IP
-- address to the instance. To use the same IP address after stopping and
-- starting an instance, create a static IP address and attach it to the
-- instance. For more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/lightsail-create-static-ip Amazon Lightsail Developer Guide>.
--
-- The @start instance@ operation supports tag-based access control via
-- resource tags applied to the resource identified by @instance name@. For
-- more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Amazon Lightsail Developer Guide>.
module Amazonka.Lightsail.StartInstance
  ( -- * Creating a Request
    StartInstance (..),
    newStartInstance,

    -- * Request Lenses
    startInstance_instanceName,

    -- * Destructuring the Response
    StartInstanceResponse (..),
    newStartInstanceResponse,

    -- * Response Lenses
    startInstanceResponse_operations,
    startInstanceResponse_httpStatus,
  )
where

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

-- | /See:/ 'newStartInstance' smart constructor.
data StartInstance = StartInstance'
  { -- | The name of the instance (a virtual private server) to start.
    StartInstance -> Text
instanceName :: Prelude.Text
  }
  deriving (StartInstance -> StartInstance -> Bool
(StartInstance -> StartInstance -> Bool)
-> (StartInstance -> StartInstance -> Bool) -> Eq StartInstance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartInstance -> StartInstance -> Bool
$c/= :: StartInstance -> StartInstance -> Bool
== :: StartInstance -> StartInstance -> Bool
$c== :: StartInstance -> StartInstance -> Bool
Prelude.Eq, ReadPrec [StartInstance]
ReadPrec StartInstance
Int -> ReadS StartInstance
ReadS [StartInstance]
(Int -> ReadS StartInstance)
-> ReadS [StartInstance]
-> ReadPrec StartInstance
-> ReadPrec [StartInstance]
-> Read StartInstance
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartInstance]
$creadListPrec :: ReadPrec [StartInstance]
readPrec :: ReadPrec StartInstance
$creadPrec :: ReadPrec StartInstance
readList :: ReadS [StartInstance]
$creadList :: ReadS [StartInstance]
readsPrec :: Int -> ReadS StartInstance
$creadsPrec :: Int -> ReadS StartInstance
Prelude.Read, Int -> StartInstance -> ShowS
[StartInstance] -> ShowS
StartInstance -> String
(Int -> StartInstance -> ShowS)
-> (StartInstance -> String)
-> ([StartInstance] -> ShowS)
-> Show StartInstance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartInstance] -> ShowS
$cshowList :: [StartInstance] -> ShowS
show :: StartInstance -> String
$cshow :: StartInstance -> String
showsPrec :: Int -> StartInstance -> ShowS
$cshowsPrec :: Int -> StartInstance -> ShowS
Prelude.Show, (forall x. StartInstance -> Rep StartInstance x)
-> (forall x. Rep StartInstance x -> StartInstance)
-> Generic StartInstance
forall x. Rep StartInstance x -> StartInstance
forall x. StartInstance -> Rep StartInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartInstance x -> StartInstance
$cfrom :: forall x. StartInstance -> Rep StartInstance x
Prelude.Generic)

-- |
-- Create a value of 'StartInstance' 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:
--
-- 'instanceName', 'startInstance_instanceName' - The name of the instance (a virtual private server) to start.
newStartInstance ::
  -- | 'instanceName'
  Prelude.Text ->
  StartInstance
newStartInstance :: Text -> StartInstance
newStartInstance Text
pInstanceName_ =
  StartInstance' :: Text -> StartInstance
StartInstance' {$sel:instanceName:StartInstance' :: Text
instanceName = Text
pInstanceName_}

-- | The name of the instance (a virtual private server) to start.
startInstance_instanceName :: Lens.Lens' StartInstance Prelude.Text
startInstance_instanceName :: (Text -> f Text) -> StartInstance -> f StartInstance
startInstance_instanceName = (StartInstance -> Text)
-> (StartInstance -> Text -> StartInstance)
-> Lens StartInstance StartInstance Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartInstance' {Text
instanceName :: Text
$sel:instanceName:StartInstance' :: StartInstance -> Text
instanceName} -> Text
instanceName) (\s :: StartInstance
s@StartInstance' {} Text
a -> StartInstance
s {$sel:instanceName:StartInstance' :: Text
instanceName = Text
a} :: StartInstance)

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

instance Prelude.NFData StartInstance

instance Core.ToHeaders StartInstance where
  toHeaders :: StartInstance -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartInstance -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"Lightsail_20161128.StartInstance" ::
                          Prelude.ByteString
                      ),
            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 StartInstance where
  toJSON :: StartInstance -> Value
toJSON StartInstance' {Text
instanceName :: Text
$sel:instanceName:StartInstance' :: StartInstance -> 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
"instanceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceName)]
      )

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

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

-- | /See:/ 'newStartInstanceResponse' smart constructor.
data StartInstanceResponse = StartInstanceResponse'
  { -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    StartInstanceResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    StartInstanceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartInstanceResponse -> StartInstanceResponse -> Bool
(StartInstanceResponse -> StartInstanceResponse -> Bool)
-> (StartInstanceResponse -> StartInstanceResponse -> Bool)
-> Eq StartInstanceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartInstanceResponse -> StartInstanceResponse -> Bool
$c/= :: StartInstanceResponse -> StartInstanceResponse -> Bool
== :: StartInstanceResponse -> StartInstanceResponse -> Bool
$c== :: StartInstanceResponse -> StartInstanceResponse -> Bool
Prelude.Eq, ReadPrec [StartInstanceResponse]
ReadPrec StartInstanceResponse
Int -> ReadS StartInstanceResponse
ReadS [StartInstanceResponse]
(Int -> ReadS StartInstanceResponse)
-> ReadS [StartInstanceResponse]
-> ReadPrec StartInstanceResponse
-> ReadPrec [StartInstanceResponse]
-> Read StartInstanceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartInstanceResponse]
$creadListPrec :: ReadPrec [StartInstanceResponse]
readPrec :: ReadPrec StartInstanceResponse
$creadPrec :: ReadPrec StartInstanceResponse
readList :: ReadS [StartInstanceResponse]
$creadList :: ReadS [StartInstanceResponse]
readsPrec :: Int -> ReadS StartInstanceResponse
$creadsPrec :: Int -> ReadS StartInstanceResponse
Prelude.Read, Int -> StartInstanceResponse -> ShowS
[StartInstanceResponse] -> ShowS
StartInstanceResponse -> String
(Int -> StartInstanceResponse -> ShowS)
-> (StartInstanceResponse -> String)
-> ([StartInstanceResponse] -> ShowS)
-> Show StartInstanceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartInstanceResponse] -> ShowS
$cshowList :: [StartInstanceResponse] -> ShowS
show :: StartInstanceResponse -> String
$cshow :: StartInstanceResponse -> String
showsPrec :: Int -> StartInstanceResponse -> ShowS
$cshowsPrec :: Int -> StartInstanceResponse -> ShowS
Prelude.Show, (forall x. StartInstanceResponse -> Rep StartInstanceResponse x)
-> (forall x. Rep StartInstanceResponse x -> StartInstanceResponse)
-> Generic StartInstanceResponse
forall x. Rep StartInstanceResponse x -> StartInstanceResponse
forall x. StartInstanceResponse -> Rep StartInstanceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartInstanceResponse x -> StartInstanceResponse
$cfrom :: forall x. StartInstanceResponse -> Rep StartInstanceResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartInstanceResponse' 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:
--
-- 'operations', 'startInstanceResponse_operations' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'startInstanceResponse_httpStatus' - The response's http status code.
newStartInstanceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartInstanceResponse
newStartInstanceResponse :: Int -> StartInstanceResponse
newStartInstanceResponse Int
pHttpStatus_ =
  StartInstanceResponse' :: Maybe [Operation] -> Int -> StartInstanceResponse
StartInstanceResponse'
    { $sel:operations:StartInstanceResponse' :: Maybe [Operation]
operations =
        Maybe [Operation]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartInstanceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
startInstanceResponse_operations :: Lens.Lens' StartInstanceResponse (Prelude.Maybe [Operation])
startInstanceResponse_operations :: (Maybe [Operation] -> f (Maybe [Operation]))
-> StartInstanceResponse -> f StartInstanceResponse
startInstanceResponse_operations = (StartInstanceResponse -> Maybe [Operation])
-> (StartInstanceResponse
    -> Maybe [Operation] -> StartInstanceResponse)
-> Lens
     StartInstanceResponse
     StartInstanceResponse
     (Maybe [Operation])
     (Maybe [Operation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartInstanceResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:StartInstanceResponse' :: StartInstanceResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: StartInstanceResponse
s@StartInstanceResponse' {} Maybe [Operation]
a -> StartInstanceResponse
s {$sel:operations:StartInstanceResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: StartInstanceResponse) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> StartInstanceResponse -> f StartInstanceResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> StartInstanceResponse
-> f StartInstanceResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Operation] [Operation] [Operation] [Operation]
-> Iso
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
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 [Operation] [Operation] [Operation] [Operation]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData StartInstanceResponse