{-# 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.RebootInstance
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Restarts a specific instance.
--
-- The @reboot 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.RebootInstance
  ( -- * Creating a Request
    RebootInstance (..),
    newRebootInstance,

    -- * Request Lenses
    rebootInstance_instanceName,

    -- * Destructuring the Response
    RebootInstanceResponse (..),
    newRebootInstanceResponse,

    -- * Response Lenses
    rebootInstanceResponse_operations,
    rebootInstanceResponse_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:/ 'newRebootInstance' smart constructor.
data RebootInstance = RebootInstance'
  { -- | The name of the instance to reboot.
    RebootInstance -> Text
instanceName :: Prelude.Text
  }
  deriving (RebootInstance -> RebootInstance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RebootInstance -> RebootInstance -> Bool
$c/= :: RebootInstance -> RebootInstance -> Bool
== :: RebootInstance -> RebootInstance -> Bool
$c== :: RebootInstance -> RebootInstance -> Bool
Prelude.Eq, ReadPrec [RebootInstance]
ReadPrec RebootInstance
Int -> ReadS RebootInstance
ReadS [RebootInstance]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RebootInstance]
$creadListPrec :: ReadPrec [RebootInstance]
readPrec :: ReadPrec RebootInstance
$creadPrec :: ReadPrec RebootInstance
readList :: ReadS [RebootInstance]
$creadList :: ReadS [RebootInstance]
readsPrec :: Int -> ReadS RebootInstance
$creadsPrec :: Int -> ReadS RebootInstance
Prelude.Read, Int -> RebootInstance -> ShowS
[RebootInstance] -> ShowS
RebootInstance -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RebootInstance] -> ShowS
$cshowList :: [RebootInstance] -> ShowS
show :: RebootInstance -> String
$cshow :: RebootInstance -> String
showsPrec :: Int -> RebootInstance -> ShowS
$cshowsPrec :: Int -> RebootInstance -> ShowS
Prelude.Show, forall x. Rep RebootInstance x -> RebootInstance
forall x. RebootInstance -> Rep RebootInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RebootInstance x -> RebootInstance
$cfrom :: forall x. RebootInstance -> Rep RebootInstance x
Prelude.Generic)

-- |
-- Create a value of 'RebootInstance' 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', 'rebootInstance_instanceName' - The name of the instance to reboot.
newRebootInstance ::
  -- | 'instanceName'
  Prelude.Text ->
  RebootInstance
newRebootInstance :: Text -> RebootInstance
newRebootInstance Text
pInstanceName_ =
  RebootInstance' {$sel:instanceName:RebootInstance' :: Text
instanceName = Text
pInstanceName_}

-- | The name of the instance to reboot.
rebootInstance_instanceName :: Lens.Lens' RebootInstance Prelude.Text
rebootInstance_instanceName :: Lens' RebootInstance Text
rebootInstance_instanceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RebootInstance' {Text
instanceName :: Text
$sel:instanceName:RebootInstance' :: RebootInstance -> Text
instanceName} -> Text
instanceName) (\s :: RebootInstance
s@RebootInstance' {} Text
a -> RebootInstance
s {$sel:instanceName:RebootInstance' :: Text
instanceName = Text
a} :: RebootInstance)

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

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

instance Data.ToHeaders RebootInstance where
  toHeaders :: RebootInstance -> 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.RebootInstance" ::
                          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 RebootInstance where
  toJSON :: RebootInstance -> Value
toJSON RebootInstance' {Text
instanceName :: Text
$sel:instanceName:RebootInstance' :: RebootInstance -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [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 RebootInstance where
  toPath :: RebootInstance -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'RebootInstanceResponse' 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', 'rebootInstanceResponse_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', 'rebootInstanceResponse_httpStatus' - The response's http status code.
newRebootInstanceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RebootInstanceResponse
newRebootInstanceResponse :: Int -> RebootInstanceResponse
newRebootInstanceResponse Int
pHttpStatus_ =
  RebootInstanceResponse'
    { $sel:operations:RebootInstanceResponse' :: Maybe [Operation]
operations =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RebootInstanceResponse' :: 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.
rebootInstanceResponse_operations :: Lens.Lens' RebootInstanceResponse (Prelude.Maybe [Operation])
rebootInstanceResponse_operations :: Lens' RebootInstanceResponse (Maybe [Operation])
rebootInstanceResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RebootInstanceResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:RebootInstanceResponse' :: RebootInstanceResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: RebootInstanceResponse
s@RebootInstanceResponse' {} Maybe [Operation]
a -> RebootInstanceResponse
s {$sel:operations:RebootInstanceResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: RebootInstanceResponse) 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.
rebootInstanceResponse_httpStatus :: Lens.Lens' RebootInstanceResponse Prelude.Int
rebootInstanceResponse_httpStatus :: Lens' RebootInstanceResponse Int
rebootInstanceResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RebootInstanceResponse' {Int
httpStatus :: Int
$sel:httpStatus:RebootInstanceResponse' :: RebootInstanceResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: RebootInstanceResponse
s@RebootInstanceResponse' {} Int
a -> RebootInstanceResponse
s {$sel:httpStatus:RebootInstanceResponse' :: Int
httpStatus = Int
a} :: RebootInstanceResponse)

instance Prelude.NFData RebootInstanceResponse where
  rnf :: RebootInstanceResponse -> ()
rnf RebootInstanceResponse' {Int
Maybe [Operation]
httpStatus :: Int
operations :: Maybe [Operation]
$sel:httpStatus:RebootInstanceResponse' :: RebootInstanceResponse -> Int
$sel:operations:RebootInstanceResponse' :: RebootInstanceResponse -> 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