{-# 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.ImageBuilder.Types.ComponentState
-- 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.ImageBuilder.Types.ComponentState where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ImageBuilder.Types.ComponentStatus
import qualified Amazonka.Prelude as Prelude

-- | A group of fields that describe the current status of components that
-- are no longer active.
--
-- /See:/ 'newComponentState' smart constructor.
data ComponentState = ComponentState'
  { -- | Describes how or why the component changed state.
    ComponentState -> Maybe Text
reason :: Prelude.Maybe Prelude.Text,
    -- | The current state of the component.
    ComponentState -> Maybe ComponentStatus
status :: Prelude.Maybe ComponentStatus
  }
  deriving (ComponentState -> ComponentState -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentState -> ComponentState -> Bool
$c/= :: ComponentState -> ComponentState -> Bool
== :: ComponentState -> ComponentState -> Bool
$c== :: ComponentState -> ComponentState -> Bool
Prelude.Eq, ReadPrec [ComponentState]
ReadPrec ComponentState
Int -> ReadS ComponentState
ReadS [ComponentState]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComponentState]
$creadListPrec :: ReadPrec [ComponentState]
readPrec :: ReadPrec ComponentState
$creadPrec :: ReadPrec ComponentState
readList :: ReadS [ComponentState]
$creadList :: ReadS [ComponentState]
readsPrec :: Int -> ReadS ComponentState
$creadsPrec :: Int -> ReadS ComponentState
Prelude.Read, Int -> ComponentState -> ShowS
[ComponentState] -> ShowS
ComponentState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentState] -> ShowS
$cshowList :: [ComponentState] -> ShowS
show :: ComponentState -> String
$cshow :: ComponentState -> String
showsPrec :: Int -> ComponentState -> ShowS
$cshowsPrec :: Int -> ComponentState -> ShowS
Prelude.Show, forall x. Rep ComponentState x -> ComponentState
forall x. ComponentState -> Rep ComponentState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ComponentState x -> ComponentState
$cfrom :: forall x. ComponentState -> Rep ComponentState x
Prelude.Generic)

-- |
-- Create a value of 'ComponentState' 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:
--
-- 'reason', 'componentState_reason' - Describes how or why the component changed state.
--
-- 'status', 'componentState_status' - The current state of the component.
newComponentState ::
  ComponentState
newComponentState :: ComponentState
newComponentState =
  ComponentState'
    { $sel:reason:ComponentState' :: Maybe Text
reason = forall a. Maybe a
Prelude.Nothing,
      $sel:status:ComponentState' :: Maybe ComponentStatus
status = forall a. Maybe a
Prelude.Nothing
    }

-- | Describes how or why the component changed state.
componentState_reason :: Lens.Lens' ComponentState (Prelude.Maybe Prelude.Text)
componentState_reason :: Lens' ComponentState (Maybe Text)
componentState_reason = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentState' {Maybe Text
reason :: Maybe Text
$sel:reason:ComponentState' :: ComponentState -> Maybe Text
reason} -> Maybe Text
reason) (\s :: ComponentState
s@ComponentState' {} Maybe Text
a -> ComponentState
s {$sel:reason:ComponentState' :: Maybe Text
reason = Maybe Text
a} :: ComponentState)

-- | The current state of the component.
componentState_status :: Lens.Lens' ComponentState (Prelude.Maybe ComponentStatus)
componentState_status :: Lens' ComponentState (Maybe ComponentStatus)
componentState_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentState' {Maybe ComponentStatus
status :: Maybe ComponentStatus
$sel:status:ComponentState' :: ComponentState -> Maybe ComponentStatus
status} -> Maybe ComponentStatus
status) (\s :: ComponentState
s@ComponentState' {} Maybe ComponentStatus
a -> ComponentState
s {$sel:status:ComponentState' :: Maybe ComponentStatus
status = Maybe ComponentStatus
a} :: ComponentState)

instance Data.FromJSON ComponentState where
  parseJSON :: Value -> Parser ComponentState
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ComponentState"
      ( \Object
x ->
          Maybe Text -> Maybe ComponentStatus -> ComponentState
ComponentState'
            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
"reason")
            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
"status")
      )

instance Prelude.Hashable ComponentState where
  hashWithSalt :: Int -> ComponentState -> Int
hashWithSalt Int
_salt ComponentState' {Maybe Text
Maybe ComponentStatus
status :: Maybe ComponentStatus
reason :: Maybe Text
$sel:status:ComponentState' :: ComponentState -> Maybe ComponentStatus
$sel:reason:ComponentState' :: ComponentState -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
reason
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ComponentStatus
status

instance Prelude.NFData ComponentState where
  rnf :: ComponentState -> ()
rnf ComponentState' {Maybe Text
Maybe ComponentStatus
status :: Maybe ComponentStatus
reason :: Maybe Text
$sel:status:ComponentState' :: ComponentState -> Maybe ComponentStatus
$sel:reason:ComponentState' :: ComponentState -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
reason seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ComponentStatus
status