{-# 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.GetInstanceState
-- 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)
--
-- Returns the state of a specific instance. Works on one instance at a
-- time.
module Amazonka.Lightsail.GetInstanceState
  ( -- * Creating a Request
    GetInstanceState (..),
    newGetInstanceState,

    -- * Request Lenses
    getInstanceState_instanceName,

    -- * Destructuring the Response
    GetInstanceStateResponse (..),
    newGetInstanceStateResponse,

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

-- |
-- Create a value of 'GetInstanceState' 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', 'getInstanceState_instanceName' - The name of the instance to get state information about.
newGetInstanceState ::
  -- | 'instanceName'
  Prelude.Text ->
  GetInstanceState
newGetInstanceState :: Text -> GetInstanceState
newGetInstanceState Text
pInstanceName_ =
  GetInstanceState' :: Text -> GetInstanceState
GetInstanceState' {$sel:instanceName:GetInstanceState' :: Text
instanceName = Text
pInstanceName_}

-- | The name of the instance to get state information about.
getInstanceState_instanceName :: Lens.Lens' GetInstanceState Prelude.Text
getInstanceState_instanceName :: (Text -> f Text) -> GetInstanceState -> f GetInstanceState
getInstanceState_instanceName = (GetInstanceState -> Text)
-> (GetInstanceState -> Text -> GetInstanceState)
-> Lens GetInstanceState GetInstanceState Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstanceState' {Text
instanceName :: Text
$sel:instanceName:GetInstanceState' :: GetInstanceState -> Text
instanceName} -> Text
instanceName) (\s :: GetInstanceState
s@GetInstanceState' {} Text
a -> GetInstanceState
s {$sel:instanceName:GetInstanceState' :: Text
instanceName = Text
a} :: GetInstanceState)

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

instance Prelude.NFData GetInstanceState

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

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

-- | /See:/ 'newGetInstanceStateResponse' smart constructor.
data GetInstanceStateResponse = GetInstanceStateResponse'
  { -- | The state of the instance.
    GetInstanceStateResponse -> Maybe InstanceState
state :: Prelude.Maybe InstanceState,
    -- | The response's http status code.
    GetInstanceStateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetInstanceStateResponse -> GetInstanceStateResponse -> Bool
(GetInstanceStateResponse -> GetInstanceStateResponse -> Bool)
-> (GetInstanceStateResponse -> GetInstanceStateResponse -> Bool)
-> Eq GetInstanceStateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInstanceStateResponse -> GetInstanceStateResponse -> Bool
$c/= :: GetInstanceStateResponse -> GetInstanceStateResponse -> Bool
== :: GetInstanceStateResponse -> GetInstanceStateResponse -> Bool
$c== :: GetInstanceStateResponse -> GetInstanceStateResponse -> Bool
Prelude.Eq, ReadPrec [GetInstanceStateResponse]
ReadPrec GetInstanceStateResponse
Int -> ReadS GetInstanceStateResponse
ReadS [GetInstanceStateResponse]
(Int -> ReadS GetInstanceStateResponse)
-> ReadS [GetInstanceStateResponse]
-> ReadPrec GetInstanceStateResponse
-> ReadPrec [GetInstanceStateResponse]
-> Read GetInstanceStateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInstanceStateResponse]
$creadListPrec :: ReadPrec [GetInstanceStateResponse]
readPrec :: ReadPrec GetInstanceStateResponse
$creadPrec :: ReadPrec GetInstanceStateResponse
readList :: ReadS [GetInstanceStateResponse]
$creadList :: ReadS [GetInstanceStateResponse]
readsPrec :: Int -> ReadS GetInstanceStateResponse
$creadsPrec :: Int -> ReadS GetInstanceStateResponse
Prelude.Read, Int -> GetInstanceStateResponse -> ShowS
[GetInstanceStateResponse] -> ShowS
GetInstanceStateResponse -> String
(Int -> GetInstanceStateResponse -> ShowS)
-> (GetInstanceStateResponse -> String)
-> ([GetInstanceStateResponse] -> ShowS)
-> Show GetInstanceStateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInstanceStateResponse] -> ShowS
$cshowList :: [GetInstanceStateResponse] -> ShowS
show :: GetInstanceStateResponse -> String
$cshow :: GetInstanceStateResponse -> String
showsPrec :: Int -> GetInstanceStateResponse -> ShowS
$cshowsPrec :: Int -> GetInstanceStateResponse -> ShowS
Prelude.Show, (forall x.
 GetInstanceStateResponse -> Rep GetInstanceStateResponse x)
-> (forall x.
    Rep GetInstanceStateResponse x -> GetInstanceStateResponse)
-> Generic GetInstanceStateResponse
forall x.
Rep GetInstanceStateResponse x -> GetInstanceStateResponse
forall x.
GetInstanceStateResponse -> Rep GetInstanceStateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetInstanceStateResponse x -> GetInstanceStateResponse
$cfrom :: forall x.
GetInstanceStateResponse -> Rep GetInstanceStateResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetInstanceStateResponse' 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:
--
-- 'state', 'getInstanceStateResponse_state' - The state of the instance.
--
-- 'httpStatus', 'getInstanceStateResponse_httpStatus' - The response's http status code.
newGetInstanceStateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetInstanceStateResponse
newGetInstanceStateResponse :: Int -> GetInstanceStateResponse
newGetInstanceStateResponse Int
pHttpStatus_ =
  GetInstanceStateResponse' :: Maybe InstanceState -> Int -> GetInstanceStateResponse
GetInstanceStateResponse'
    { $sel:state:GetInstanceStateResponse' :: Maybe InstanceState
state = Maybe InstanceState
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetInstanceStateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The state of the instance.
getInstanceStateResponse_state :: Lens.Lens' GetInstanceStateResponse (Prelude.Maybe InstanceState)
getInstanceStateResponse_state :: (Maybe InstanceState -> f (Maybe InstanceState))
-> GetInstanceStateResponse -> f GetInstanceStateResponse
getInstanceStateResponse_state = (GetInstanceStateResponse -> Maybe InstanceState)
-> (GetInstanceStateResponse
    -> Maybe InstanceState -> GetInstanceStateResponse)
-> Lens
     GetInstanceStateResponse
     GetInstanceStateResponse
     (Maybe InstanceState)
     (Maybe InstanceState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstanceStateResponse' {Maybe InstanceState
state :: Maybe InstanceState
$sel:state:GetInstanceStateResponse' :: GetInstanceStateResponse -> Maybe InstanceState
state} -> Maybe InstanceState
state) (\s :: GetInstanceStateResponse
s@GetInstanceStateResponse' {} Maybe InstanceState
a -> GetInstanceStateResponse
s {$sel:state:GetInstanceStateResponse' :: Maybe InstanceState
state = Maybe InstanceState
a} :: GetInstanceStateResponse)

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

instance Prelude.NFData GetInstanceStateResponse