{-# 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-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)
--
-- 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.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:/ 'newRebootInstance' smart constructor.
data RebootInstance = RebootInstance'
  { -- | The name of the instance to reboot.
    RebootInstance -> Text
instanceName :: Prelude.Text
  }
  deriving (RebootInstance -> RebootInstance -> Bool
(RebootInstance -> RebootInstance -> Bool)
-> (RebootInstance -> RebootInstance -> Bool) -> Eq RebootInstance
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]
(Int -> ReadS RebootInstance)
-> ReadS [RebootInstance]
-> ReadPrec RebootInstance
-> ReadPrec [RebootInstance]
-> Read 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
(Int -> RebootInstance -> ShowS)
-> (RebootInstance -> String)
-> ([RebootInstance] -> ShowS)
-> Show RebootInstance
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. RebootInstance -> Rep RebootInstance x)
-> (forall x. Rep RebootInstance x -> RebootInstance)
-> Generic RebootInstance
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' :: Text -> RebootInstance
RebootInstance' {$sel:instanceName:RebootInstance' :: Text
instanceName = Text
pInstanceName_}

-- | The name of the instance to reboot.
rebootInstance_instanceName :: Lens.Lens' RebootInstance Prelude.Text
rebootInstance_instanceName :: (Text -> f Text) -> RebootInstance -> f RebootInstance
rebootInstance_instanceName = (RebootInstance -> Text)
-> (RebootInstance -> Text -> RebootInstance)
-> Lens RebootInstance RebootInstance Text Text
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 :: RebootInstance -> Request RebootInstance
request = Service -> RebootInstance -> Request RebootInstance
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RebootInstance
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RebootInstance)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse RebootInstance))
-> Logger
-> Service
-> Proxy RebootInstance
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RebootInstance)))
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 -> RebootInstanceResponse
RebootInstanceResponse'
            (Maybe [Operation] -> Int -> RebootInstanceResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> RebootInstanceResponse)
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 -> RebootInstanceResponse)
-> Either String Int -> Either String RebootInstanceResponse
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 RebootInstance

instance Prelude.NFData RebootInstance

instance Core.ToHeaders RebootInstance where
  toHeaders :: RebootInstance -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RebootInstance -> 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.RebootInstance" ::
                          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 RebootInstance where
  toJSON :: RebootInstance -> Value
toJSON RebootInstance' {Text
instanceName :: Text
$sel:instanceName:RebootInstance' :: RebootInstance -> 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 RebootInstance where
  toPath :: RebootInstance -> ByteString
toPath = ByteString -> RebootInstance -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery RebootInstance where
  toQuery :: RebootInstance -> QueryString
toQuery = QueryString -> RebootInstance -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(RebootInstanceResponse -> RebootInstanceResponse -> Bool)
-> (RebootInstanceResponse -> RebootInstanceResponse -> Bool)
-> Eq RebootInstanceResponse
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]
(Int -> ReadS RebootInstanceResponse)
-> ReadS [RebootInstanceResponse]
-> ReadPrec RebootInstanceResponse
-> ReadPrec [RebootInstanceResponse]
-> Read 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
(Int -> RebootInstanceResponse -> ShowS)
-> (RebootInstanceResponse -> String)
-> ([RebootInstanceResponse] -> ShowS)
-> Show RebootInstanceResponse
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. RebootInstanceResponse -> Rep RebootInstanceResponse x)
-> (forall x.
    Rep RebootInstanceResponse x -> RebootInstanceResponse)
-> Generic RebootInstanceResponse
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' :: Maybe [Operation] -> Int -> RebootInstanceResponse
RebootInstanceResponse'
    { $sel:operations:RebootInstanceResponse' :: Maybe [Operation]
operations =
        Maybe [Operation]
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 :: (Maybe [Operation] -> f (Maybe [Operation]))
-> RebootInstanceResponse -> f RebootInstanceResponse
rebootInstanceResponse_operations = (RebootInstanceResponse -> Maybe [Operation])
-> (RebootInstanceResponse
    -> Maybe [Operation] -> RebootInstanceResponse)
-> Lens
     RebootInstanceResponse
     RebootInstanceResponse
     (Maybe [Operation])
     (Maybe [Operation])
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) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> RebootInstanceResponse -> f RebootInstanceResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> RebootInstanceResponse
-> f RebootInstanceResponse
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.
rebootInstanceResponse_httpStatus :: Lens.Lens' RebootInstanceResponse Prelude.Int
rebootInstanceResponse_httpStatus :: (Int -> f Int)
-> RebootInstanceResponse -> f RebootInstanceResponse
rebootInstanceResponse_httpStatus = (RebootInstanceResponse -> Int)
-> (RebootInstanceResponse -> Int -> RebootInstanceResponse)
-> Lens RebootInstanceResponse RebootInstanceResponse Int Int
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