{-# 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.StopInstance
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Stops a specific Amazon Lightsail instance that is currently running.
--
-- 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 @stop 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.StopInstance
  ( -- * Creating a Request
    StopInstance (..),
    newStopInstance,

    -- * Request Lenses
    stopInstance_force,
    stopInstance_instanceName,

    -- * Destructuring the Response
    StopInstanceResponse (..),
    newStopInstanceResponse,

    -- * Response Lenses
    stopInstanceResponse_operations,
    stopInstanceResponse_httpStatus,
  )
where

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

-- | /See:/ 'newStopInstance' smart constructor.
data StopInstance = StopInstance'
  { -- | When set to @True@, forces a Lightsail instance that is stuck in a
    -- @stopping@ state to stop.
    --
    -- Only use the @force@ parameter if your instance is stuck in the
    -- @stopping@ state. In any other state, your instance should stop normally
    -- without adding this parameter to your API request.
    StopInstance -> Maybe Bool
force :: Prelude.Maybe Prelude.Bool,
    -- | The name of the instance (a virtual private server) to stop.
    StopInstance -> Text
instanceName :: Prelude.Text
  }
  deriving (StopInstance -> StopInstance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopInstance -> StopInstance -> Bool
$c/= :: StopInstance -> StopInstance -> Bool
== :: StopInstance -> StopInstance -> Bool
$c== :: StopInstance -> StopInstance -> Bool
Prelude.Eq, ReadPrec [StopInstance]
ReadPrec StopInstance
Int -> ReadS StopInstance
ReadS [StopInstance]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopInstance]
$creadListPrec :: ReadPrec [StopInstance]
readPrec :: ReadPrec StopInstance
$creadPrec :: ReadPrec StopInstance
readList :: ReadS [StopInstance]
$creadList :: ReadS [StopInstance]
readsPrec :: Int -> ReadS StopInstance
$creadsPrec :: Int -> ReadS StopInstance
Prelude.Read, Int -> StopInstance -> ShowS
[StopInstance] -> ShowS
StopInstance -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopInstance] -> ShowS
$cshowList :: [StopInstance] -> ShowS
show :: StopInstance -> String
$cshow :: StopInstance -> String
showsPrec :: Int -> StopInstance -> ShowS
$cshowsPrec :: Int -> StopInstance -> ShowS
Prelude.Show, forall x. Rep StopInstance x -> StopInstance
forall x. StopInstance -> Rep StopInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopInstance x -> StopInstance
$cfrom :: forall x. StopInstance -> Rep StopInstance x
Prelude.Generic)

-- |
-- Create a value of 'StopInstance' 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:
--
-- 'force', 'stopInstance_force' - When set to @True@, forces a Lightsail instance that is stuck in a
-- @stopping@ state to stop.
--
-- Only use the @force@ parameter if your instance is stuck in the
-- @stopping@ state. In any other state, your instance should stop normally
-- without adding this parameter to your API request.
--
-- 'instanceName', 'stopInstance_instanceName' - The name of the instance (a virtual private server) to stop.
newStopInstance ::
  -- | 'instanceName'
  Prelude.Text ->
  StopInstance
newStopInstance :: Text -> StopInstance
newStopInstance Text
pInstanceName_ =
  StopInstance'
    { $sel:force:StopInstance' :: Maybe Bool
force = forall a. Maybe a
Prelude.Nothing,
      $sel:instanceName:StopInstance' :: Text
instanceName = Text
pInstanceName_
    }

-- | When set to @True@, forces a Lightsail instance that is stuck in a
-- @stopping@ state to stop.
--
-- Only use the @force@ parameter if your instance is stuck in the
-- @stopping@ state. In any other state, your instance should stop normally
-- without adding this parameter to your API request.
stopInstance_force :: Lens.Lens' StopInstance (Prelude.Maybe Prelude.Bool)
stopInstance_force :: Lens' StopInstance (Maybe Bool)
stopInstance_force = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopInstance' {Maybe Bool
force :: Maybe Bool
$sel:force:StopInstance' :: StopInstance -> Maybe Bool
force} -> Maybe Bool
force) (\s :: StopInstance
s@StopInstance' {} Maybe Bool
a -> StopInstance
s {$sel:force:StopInstance' :: Maybe Bool
force = Maybe Bool
a} :: StopInstance)

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

instance Core.AWSRequest StopInstance where
  type AWSResponse StopInstance = StopInstanceResponse
  request :: (Service -> Service) -> StopInstance -> Request StopInstance
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 StopInstance
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopInstance)))
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 [Operation] -> Int -> StopInstanceResponse
StopInstanceResponse'
            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
"operations" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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 StopInstance where
  hashWithSalt :: Int -> StopInstance -> Int
hashWithSalt Int
_salt StopInstance' {Maybe Bool
Text
instanceName :: Text
force :: Maybe Bool
$sel:instanceName:StopInstance' :: StopInstance -> Text
$sel:force:StopInstance' :: StopInstance -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
force
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
instanceName

instance Prelude.NFData StopInstance where
  rnf :: StopInstance -> ()
rnf StopInstance' {Maybe Bool
Text
instanceName :: Text
force :: Maybe Bool
$sel:instanceName:StopInstance' :: StopInstance -> Text
$sel:force:StopInstance' :: StopInstance -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
force
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
instanceName

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

instance Data.ToJSON StopInstance where
  toJSON :: StopInstance -> Value
toJSON StopInstance' {Maybe Bool
Text
instanceName :: Text
force :: Maybe Bool
$sel:instanceName:StopInstance' :: StopInstance -> Text
$sel:force:StopInstance' :: StopInstance -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"force" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
force,
            forall a. a -> Maybe a
Prelude.Just (Key
"instanceName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
instanceName)
          ]
      )

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

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

-- | /See:/ 'newStopInstanceResponse' smart constructor.
data StopInstanceResponse = StopInstanceResponse'
  { -- | 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.
    StopInstanceResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    StopInstanceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopInstanceResponse -> StopInstanceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopInstanceResponse -> StopInstanceResponse -> Bool
$c/= :: StopInstanceResponse -> StopInstanceResponse -> Bool
== :: StopInstanceResponse -> StopInstanceResponse -> Bool
$c== :: StopInstanceResponse -> StopInstanceResponse -> Bool
Prelude.Eq, ReadPrec [StopInstanceResponse]
ReadPrec StopInstanceResponse
Int -> ReadS StopInstanceResponse
ReadS [StopInstanceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopInstanceResponse]
$creadListPrec :: ReadPrec [StopInstanceResponse]
readPrec :: ReadPrec StopInstanceResponse
$creadPrec :: ReadPrec StopInstanceResponse
readList :: ReadS [StopInstanceResponse]
$creadList :: ReadS [StopInstanceResponse]
readsPrec :: Int -> ReadS StopInstanceResponse
$creadsPrec :: Int -> ReadS StopInstanceResponse
Prelude.Read, Int -> StopInstanceResponse -> ShowS
[StopInstanceResponse] -> ShowS
StopInstanceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopInstanceResponse] -> ShowS
$cshowList :: [StopInstanceResponse] -> ShowS
show :: StopInstanceResponse -> String
$cshow :: StopInstanceResponse -> String
showsPrec :: Int -> StopInstanceResponse -> ShowS
$cshowsPrec :: Int -> StopInstanceResponse -> ShowS
Prelude.Show, forall x. Rep StopInstanceResponse x -> StopInstanceResponse
forall x. StopInstanceResponse -> Rep StopInstanceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopInstanceResponse x -> StopInstanceResponse
$cfrom :: forall x. StopInstanceResponse -> Rep StopInstanceResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopInstanceResponse' 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', 'stopInstanceResponse_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', 'stopInstanceResponse_httpStatus' - The response's http status code.
newStopInstanceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopInstanceResponse
newStopInstanceResponse :: Int -> StopInstanceResponse
newStopInstanceResponse Int
pHttpStatus_ =
  StopInstanceResponse'
    { $sel:operations:StopInstanceResponse' :: Maybe [Operation]
operations = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopInstanceResponse' :: 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.
stopInstanceResponse_operations :: Lens.Lens' StopInstanceResponse (Prelude.Maybe [Operation])
stopInstanceResponse_operations :: Lens' StopInstanceResponse (Maybe [Operation])
stopInstanceResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopInstanceResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:StopInstanceResponse' :: StopInstanceResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: StopInstanceResponse
s@StopInstanceResponse' {} Maybe [Operation]
a -> StopInstanceResponse
s {$sel:operations:StopInstanceResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: StopInstanceResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData StopInstanceResponse where
  rnf :: StopInstanceResponse -> ()
rnf StopInstanceResponse' {Int
Maybe [Operation]
httpStatus :: Int
operations :: Maybe [Operation]
$sel:httpStatus:StopInstanceResponse' :: StopInstanceResponse -> Int
$sel:operations:StopInstanceResponse' :: StopInstanceResponse -> Maybe [Operation]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Operation]
operations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus