{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.InstanceState
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Lightsail.Types.InstanceState where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Describes the virtual private server (or /instance/) status.
--
-- /See:/ 'newInstanceState' smart constructor.
data InstanceState = InstanceState'
  { -- | The status code for the instance.
    InstanceState -> Maybe Int
code :: Prelude.Maybe Prelude.Int,
    -- | The state of the instance (e.g., @running@ or @pending@).
    InstanceState -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (InstanceState -> InstanceState -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceState -> InstanceState -> Bool
$c/= :: InstanceState -> InstanceState -> Bool
== :: InstanceState -> InstanceState -> Bool
$c== :: InstanceState -> InstanceState -> Bool
Prelude.Eq, ReadPrec [InstanceState]
ReadPrec InstanceState
Int -> ReadS InstanceState
ReadS [InstanceState]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceState]
$creadListPrec :: ReadPrec [InstanceState]
readPrec :: ReadPrec InstanceState
$creadPrec :: ReadPrec InstanceState
readList :: ReadS [InstanceState]
$creadList :: ReadS [InstanceState]
readsPrec :: Int -> ReadS InstanceState
$creadsPrec :: Int -> ReadS InstanceState
Prelude.Read, Int -> InstanceState -> ShowS
[InstanceState] -> ShowS
InstanceState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceState] -> ShowS
$cshowList :: [InstanceState] -> ShowS
show :: InstanceState -> String
$cshow :: InstanceState -> String
showsPrec :: Int -> InstanceState -> ShowS
$cshowsPrec :: Int -> InstanceState -> ShowS
Prelude.Show, forall x. Rep InstanceState x -> InstanceState
forall x. InstanceState -> Rep InstanceState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceState x -> InstanceState
$cfrom :: forall x. InstanceState -> Rep InstanceState x
Prelude.Generic)

-- |
-- Create a value of 'InstanceState' 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:
--
-- 'code', 'instanceState_code' - The status code for the instance.
--
-- 'name', 'instanceState_name' - The state of the instance (e.g., @running@ or @pending@).
newInstanceState ::
  InstanceState
newInstanceState :: InstanceState
newInstanceState =
  InstanceState'
    { $sel:code:InstanceState' :: Maybe Int
code = forall a. Maybe a
Prelude.Nothing,
      $sel:name:InstanceState' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing
    }

-- | The status code for the instance.
instanceState_code :: Lens.Lens' InstanceState (Prelude.Maybe Prelude.Int)
instanceState_code :: Lens' InstanceState (Maybe Int)
instanceState_code = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceState' {Maybe Int
code :: Maybe Int
$sel:code:InstanceState' :: InstanceState -> Maybe Int
code} -> Maybe Int
code) (\s :: InstanceState
s@InstanceState' {} Maybe Int
a -> InstanceState
s {$sel:code:InstanceState' :: Maybe Int
code = Maybe Int
a} :: InstanceState)

-- | The state of the instance (e.g., @running@ or @pending@).
instanceState_name :: Lens.Lens' InstanceState (Prelude.Maybe Prelude.Text)
instanceState_name :: Lens' InstanceState (Maybe Text)
instanceState_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceState' {Maybe Text
name :: Maybe Text
$sel:name:InstanceState' :: InstanceState -> Maybe Text
name} -> Maybe Text
name) (\s :: InstanceState
s@InstanceState' {} Maybe Text
a -> InstanceState
s {$sel:name:InstanceState' :: Maybe Text
name = Maybe Text
a} :: InstanceState)

instance Data.FromJSON InstanceState where
  parseJSON :: Value -> Parser InstanceState
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"InstanceState"
      ( \Object
x ->
          Maybe Int -> Maybe Text -> InstanceState
InstanceState'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"code")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"name")
      )

instance Prelude.Hashable InstanceState where
  hashWithSalt :: Int -> InstanceState -> Int
hashWithSalt Int
_salt InstanceState' {Maybe Int
Maybe Text
name :: Maybe Text
code :: Maybe Int
$sel:name:InstanceState' :: InstanceState -> Maybe Text
$sel:code:InstanceState' :: InstanceState -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
code
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name

instance Prelude.NFData InstanceState where
  rnf :: InstanceState -> ()
rnf InstanceState' {Maybe Int
Maybe Text
name :: Maybe Text
code :: Maybe Int
$sel:name:InstanceState' :: InstanceState -> Maybe Text
$sel:code:InstanceState' :: InstanceState -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
code seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name