{-# 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.EC2.Types.StateReason
-- 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.EC2.Types.StateReason where

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

-- | Describes a state change.
--
-- /See:/ 'newStateReason' smart constructor.
data StateReason = StateReason'
  { -- | The reason code for the state change.
    StateReason -> Maybe Text
code :: Prelude.Maybe Prelude.Text,
    -- | The message for the state change.
    --
    -- -   @Server.InsufficientInstanceCapacity@: There was insufficient
    --     capacity available to satisfy the launch request.
    --
    -- -   @Server.InternalError@: An internal error caused the instance to
    --     terminate during launch.
    --
    -- -   @Server.ScheduledStop@: The instance was stopped due to a scheduled
    --     retirement.
    --
    -- -   @Server.SpotInstanceShutdown@: The instance was stopped because the
    --     number of Spot requests with a maximum price equal to or higher than
    --     the Spot price exceeded available capacity or because of an increase
    --     in the Spot price.
    --
    -- -   @Server.SpotInstanceTermination@: The instance was terminated
    --     because the number of Spot requests with a maximum price equal to or
    --     higher than the Spot price exceeded available capacity or because of
    --     an increase in the Spot price.
    --
    -- -   @Client.InstanceInitiatedShutdown@: The instance was shut down using
    --     the @shutdown -h@ command from the instance.
    --
    -- -   @Client.InstanceTerminated@: The instance was terminated or rebooted
    --     during AMI creation.
    --
    -- -   @Client.InternalError@: A client error caused the instance to
    --     terminate during launch.
    --
    -- -   @Client.InvalidSnapshot.NotFound@: The specified snapshot was not
    --     found.
    --
    -- -   @Client.UserInitiatedHibernate@: Hibernation was initiated on the
    --     instance.
    --
    -- -   @Client.UserInitiatedShutdown@: The instance was shut down using the
    --     Amazon EC2 API.
    --
    -- -   @Client.VolumeLimitExceeded@: The limit on the number of EBS volumes
    --     or total storage was exceeded. Decrease usage or request an increase
    --     in your account limits.
    StateReason -> Maybe Text
message :: Prelude.Maybe Prelude.Text
  }
  deriving (StateReason -> StateReason -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StateReason -> StateReason -> Bool
$c/= :: StateReason -> StateReason -> Bool
== :: StateReason -> StateReason -> Bool
$c== :: StateReason -> StateReason -> Bool
Prelude.Eq, ReadPrec [StateReason]
ReadPrec StateReason
Int -> ReadS StateReason
ReadS [StateReason]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StateReason]
$creadListPrec :: ReadPrec [StateReason]
readPrec :: ReadPrec StateReason
$creadPrec :: ReadPrec StateReason
readList :: ReadS [StateReason]
$creadList :: ReadS [StateReason]
readsPrec :: Int -> ReadS StateReason
$creadsPrec :: Int -> ReadS StateReason
Prelude.Read, Int -> StateReason -> ShowS
[StateReason] -> ShowS
StateReason -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StateReason] -> ShowS
$cshowList :: [StateReason] -> ShowS
show :: StateReason -> String
$cshow :: StateReason -> String
showsPrec :: Int -> StateReason -> ShowS
$cshowsPrec :: Int -> StateReason -> ShowS
Prelude.Show, forall x. Rep StateReason x -> StateReason
forall x. StateReason -> Rep StateReason x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StateReason x -> StateReason
$cfrom :: forall x. StateReason -> Rep StateReason x
Prelude.Generic)

-- |
-- Create a value of 'StateReason' 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', 'stateReason_code' - The reason code for the state change.
--
-- 'message', 'stateReason_message' - The message for the state change.
--
-- -   @Server.InsufficientInstanceCapacity@: There was insufficient
--     capacity available to satisfy the launch request.
--
-- -   @Server.InternalError@: An internal error caused the instance to
--     terminate during launch.
--
-- -   @Server.ScheduledStop@: The instance was stopped due to a scheduled
--     retirement.
--
-- -   @Server.SpotInstanceShutdown@: The instance was stopped because the
--     number of Spot requests with a maximum price equal to or higher than
--     the Spot price exceeded available capacity or because of an increase
--     in the Spot price.
--
-- -   @Server.SpotInstanceTermination@: The instance was terminated
--     because the number of Spot requests with a maximum price equal to or
--     higher than the Spot price exceeded available capacity or because of
--     an increase in the Spot price.
--
-- -   @Client.InstanceInitiatedShutdown@: The instance was shut down using
--     the @shutdown -h@ command from the instance.
--
-- -   @Client.InstanceTerminated@: The instance was terminated or rebooted
--     during AMI creation.
--
-- -   @Client.InternalError@: A client error caused the instance to
--     terminate during launch.
--
-- -   @Client.InvalidSnapshot.NotFound@: The specified snapshot was not
--     found.
--
-- -   @Client.UserInitiatedHibernate@: Hibernation was initiated on the
--     instance.
--
-- -   @Client.UserInitiatedShutdown@: The instance was shut down using the
--     Amazon EC2 API.
--
-- -   @Client.VolumeLimitExceeded@: The limit on the number of EBS volumes
--     or total storage was exceeded. Decrease usage or request an increase
--     in your account limits.
newStateReason ::
  StateReason
newStateReason :: StateReason
newStateReason =
  StateReason'
    { $sel:code:StateReason' :: Maybe Text
code = forall a. Maybe a
Prelude.Nothing,
      $sel:message:StateReason' :: Maybe Text
message = forall a. Maybe a
Prelude.Nothing
    }

-- | The reason code for the state change.
stateReason_code :: Lens.Lens' StateReason (Prelude.Maybe Prelude.Text)
stateReason_code :: Lens' StateReason (Maybe Text)
stateReason_code = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StateReason' {Maybe Text
code :: Maybe Text
$sel:code:StateReason' :: StateReason -> Maybe Text
code} -> Maybe Text
code) (\s :: StateReason
s@StateReason' {} Maybe Text
a -> StateReason
s {$sel:code:StateReason' :: Maybe Text
code = Maybe Text
a} :: StateReason)

-- | The message for the state change.
--
-- -   @Server.InsufficientInstanceCapacity@: There was insufficient
--     capacity available to satisfy the launch request.
--
-- -   @Server.InternalError@: An internal error caused the instance to
--     terminate during launch.
--
-- -   @Server.ScheduledStop@: The instance was stopped due to a scheduled
--     retirement.
--
-- -   @Server.SpotInstanceShutdown@: The instance was stopped because the
--     number of Spot requests with a maximum price equal to or higher than
--     the Spot price exceeded available capacity or because of an increase
--     in the Spot price.
--
-- -   @Server.SpotInstanceTermination@: The instance was terminated
--     because the number of Spot requests with a maximum price equal to or
--     higher than the Spot price exceeded available capacity or because of
--     an increase in the Spot price.
--
-- -   @Client.InstanceInitiatedShutdown@: The instance was shut down using
--     the @shutdown -h@ command from the instance.
--
-- -   @Client.InstanceTerminated@: The instance was terminated or rebooted
--     during AMI creation.
--
-- -   @Client.InternalError@: A client error caused the instance to
--     terminate during launch.
--
-- -   @Client.InvalidSnapshot.NotFound@: The specified snapshot was not
--     found.
--
-- -   @Client.UserInitiatedHibernate@: Hibernation was initiated on the
--     instance.
--
-- -   @Client.UserInitiatedShutdown@: The instance was shut down using the
--     Amazon EC2 API.
--
-- -   @Client.VolumeLimitExceeded@: The limit on the number of EBS volumes
--     or total storage was exceeded. Decrease usage or request an increase
--     in your account limits.
stateReason_message :: Lens.Lens' StateReason (Prelude.Maybe Prelude.Text)
stateReason_message :: Lens' StateReason (Maybe Text)
stateReason_message = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StateReason' {Maybe Text
message :: Maybe Text
$sel:message:StateReason' :: StateReason -> Maybe Text
message} -> Maybe Text
message) (\s :: StateReason
s@StateReason' {} Maybe Text
a -> StateReason
s {$sel:message:StateReason' :: Maybe Text
message = Maybe Text
a} :: StateReason)

instance Data.FromXML StateReason where
  parseXML :: [Node] -> Either String StateReason
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> StateReason
StateReason'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"code")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"message")

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

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