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

import qualified Amazonka.Core as Core
import Amazonka.ImageBuilder.Types.ComponentStatus
import qualified Amazonka.Lens as Lens
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'
  { -- | The current state of the component.
    ComponentState -> Maybe ComponentStatus
status :: Prelude.Maybe ComponentStatus,
    -- | Describes how or why the component changed state.
    ComponentState -> Maybe Text
reason :: Prelude.Maybe Prelude.Text
  }
  deriving (ComponentState -> ComponentState -> Bool
(ComponentState -> ComponentState -> Bool)
-> (ComponentState -> ComponentState -> Bool) -> Eq ComponentState
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]
(Int -> ReadS ComponentState)
-> ReadS [ComponentState]
-> ReadPrec ComponentState
-> ReadPrec [ComponentState]
-> Read 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
(Int -> ComponentState -> ShowS)
-> (ComponentState -> String)
-> ([ComponentState] -> ShowS)
-> Show ComponentState
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. ComponentState -> Rep ComponentState x)
-> (forall x. Rep ComponentState x -> ComponentState)
-> Generic ComponentState
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:
--
-- 'status', 'componentState_status' - The current state of the component.
--
-- 'reason', 'componentState_reason' - Describes how or why the component changed state.
newComponentState ::
  ComponentState
newComponentState :: ComponentState
newComponentState =
  ComponentState' :: Maybe ComponentStatus -> Maybe Text -> ComponentState
ComponentState'
    { $sel:status:ComponentState' :: Maybe ComponentStatus
status = Maybe ComponentStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:reason:ComponentState' :: Maybe Text
reason = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The current state of the component.
componentState_status :: Lens.Lens' ComponentState (Prelude.Maybe ComponentStatus)
componentState_status :: (Maybe ComponentStatus -> f (Maybe ComponentStatus))
-> ComponentState -> f ComponentState
componentState_status = (ComponentState -> Maybe ComponentStatus)
-> (ComponentState -> Maybe ComponentStatus -> ComponentState)
-> Lens
     ComponentState
     ComponentState
     (Maybe ComponentStatus)
     (Maybe ComponentStatus)
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)

-- | Describes how or why the component changed state.
componentState_reason :: Lens.Lens' ComponentState (Prelude.Maybe Prelude.Text)
componentState_reason :: (Maybe Text -> f (Maybe Text))
-> ComponentState -> f ComponentState
componentState_reason = (ComponentState -> Maybe Text)
-> (ComponentState -> Maybe Text -> ComponentState)
-> Lens ComponentState ComponentState (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON ComponentState where
  parseJSON :: Value -> Parser ComponentState
parseJSON =
    String
-> (Object -> Parser ComponentState)
-> Value
-> Parser ComponentState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ComponentState"
      ( \Object
x ->
          Maybe ComponentStatus -> Maybe Text -> ComponentState
ComponentState'
            (Maybe ComponentStatus -> Maybe Text -> ComponentState)
-> Parser (Maybe ComponentStatus)
-> Parser (Maybe Text -> ComponentState)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ComponentStatus)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"status")
            Parser (Maybe Text -> ComponentState)
-> Parser (Maybe Text) -> Parser ComponentState
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"reason")
      )

instance Prelude.Hashable ComponentState

instance Prelude.NFData ComponentState