{-# 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.Synthetics.Types.CanaryStatus
-- 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.Synthetics.Types.CanaryStatus where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Synthetics.Types.CanaryState
import Amazonka.Synthetics.Types.CanaryStateReasonCode

-- | A structure that contains the current state of the canary.
--
-- /See:/ 'newCanaryStatus' smart constructor.
data CanaryStatus = CanaryStatus'
  { -- | The current state of the canary.
    CanaryStatus -> Maybe CanaryState
state :: Prelude.Maybe CanaryState,
    -- | If the canary has insufficient permissions to run, this field provides
    -- more details.
    CanaryStatus -> Maybe Text
stateReason :: Prelude.Maybe Prelude.Text,
    -- | If the canary cannot run or has failed, this field displays the reason.
    CanaryStatus -> Maybe CanaryStateReasonCode
stateReasonCode :: Prelude.Maybe CanaryStateReasonCode
  }
  deriving (CanaryStatus -> CanaryStatus -> Bool
(CanaryStatus -> CanaryStatus -> Bool)
-> (CanaryStatus -> CanaryStatus -> Bool) -> Eq CanaryStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CanaryStatus -> CanaryStatus -> Bool
$c/= :: CanaryStatus -> CanaryStatus -> Bool
== :: CanaryStatus -> CanaryStatus -> Bool
$c== :: CanaryStatus -> CanaryStatus -> Bool
Prelude.Eq, ReadPrec [CanaryStatus]
ReadPrec CanaryStatus
Int -> ReadS CanaryStatus
ReadS [CanaryStatus]
(Int -> ReadS CanaryStatus)
-> ReadS [CanaryStatus]
-> ReadPrec CanaryStatus
-> ReadPrec [CanaryStatus]
-> Read CanaryStatus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CanaryStatus]
$creadListPrec :: ReadPrec [CanaryStatus]
readPrec :: ReadPrec CanaryStatus
$creadPrec :: ReadPrec CanaryStatus
readList :: ReadS [CanaryStatus]
$creadList :: ReadS [CanaryStatus]
readsPrec :: Int -> ReadS CanaryStatus
$creadsPrec :: Int -> ReadS CanaryStatus
Prelude.Read, Int -> CanaryStatus -> ShowS
[CanaryStatus] -> ShowS
CanaryStatus -> String
(Int -> CanaryStatus -> ShowS)
-> (CanaryStatus -> String)
-> ([CanaryStatus] -> ShowS)
-> Show CanaryStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CanaryStatus] -> ShowS
$cshowList :: [CanaryStatus] -> ShowS
show :: CanaryStatus -> String
$cshow :: CanaryStatus -> String
showsPrec :: Int -> CanaryStatus -> ShowS
$cshowsPrec :: Int -> CanaryStatus -> ShowS
Prelude.Show, (forall x. CanaryStatus -> Rep CanaryStatus x)
-> (forall x. Rep CanaryStatus x -> CanaryStatus)
-> Generic CanaryStatus
forall x. Rep CanaryStatus x -> CanaryStatus
forall x. CanaryStatus -> Rep CanaryStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CanaryStatus x -> CanaryStatus
$cfrom :: forall x. CanaryStatus -> Rep CanaryStatus x
Prelude.Generic)

-- |
-- Create a value of 'CanaryStatus' 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', 'canaryStatus_state' - The current state of the canary.
--
-- 'stateReason', 'canaryStatus_stateReason' - If the canary has insufficient permissions to run, this field provides
-- more details.
--
-- 'stateReasonCode', 'canaryStatus_stateReasonCode' - If the canary cannot run or has failed, this field displays the reason.
newCanaryStatus ::
  CanaryStatus
newCanaryStatus :: CanaryStatus
newCanaryStatus =
  CanaryStatus' :: Maybe CanaryState
-> Maybe Text -> Maybe CanaryStateReasonCode -> CanaryStatus
CanaryStatus'
    { $sel:state:CanaryStatus' :: Maybe CanaryState
state = Maybe CanaryState
forall a. Maybe a
Prelude.Nothing,
      $sel:stateReason:CanaryStatus' :: Maybe Text
stateReason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stateReasonCode:CanaryStatus' :: Maybe CanaryStateReasonCode
stateReasonCode = Maybe CanaryStateReasonCode
forall a. Maybe a
Prelude.Nothing
    }

-- | The current state of the canary.
canaryStatus_state :: Lens.Lens' CanaryStatus (Prelude.Maybe CanaryState)
canaryStatus_state :: (Maybe CanaryState -> f (Maybe CanaryState))
-> CanaryStatus -> f CanaryStatus
canaryStatus_state = (CanaryStatus -> Maybe CanaryState)
-> (CanaryStatus -> Maybe CanaryState -> CanaryStatus)
-> Lens
     CanaryStatus CanaryStatus (Maybe CanaryState) (Maybe CanaryState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryStatus' {Maybe CanaryState
state :: Maybe CanaryState
$sel:state:CanaryStatus' :: CanaryStatus -> Maybe CanaryState
state} -> Maybe CanaryState
state) (\s :: CanaryStatus
s@CanaryStatus' {} Maybe CanaryState
a -> CanaryStatus
s {$sel:state:CanaryStatus' :: Maybe CanaryState
state = Maybe CanaryState
a} :: CanaryStatus)

-- | If the canary has insufficient permissions to run, this field provides
-- more details.
canaryStatus_stateReason :: Lens.Lens' CanaryStatus (Prelude.Maybe Prelude.Text)
canaryStatus_stateReason :: (Maybe Text -> f (Maybe Text)) -> CanaryStatus -> f CanaryStatus
canaryStatus_stateReason = (CanaryStatus -> Maybe Text)
-> (CanaryStatus -> Maybe Text -> CanaryStatus)
-> Lens CanaryStatus CanaryStatus (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryStatus' {Maybe Text
stateReason :: Maybe Text
$sel:stateReason:CanaryStatus' :: CanaryStatus -> Maybe Text
stateReason} -> Maybe Text
stateReason) (\s :: CanaryStatus
s@CanaryStatus' {} Maybe Text
a -> CanaryStatus
s {$sel:stateReason:CanaryStatus' :: Maybe Text
stateReason = Maybe Text
a} :: CanaryStatus)

-- | If the canary cannot run or has failed, this field displays the reason.
canaryStatus_stateReasonCode :: Lens.Lens' CanaryStatus (Prelude.Maybe CanaryStateReasonCode)
canaryStatus_stateReasonCode :: (Maybe CanaryStateReasonCode -> f (Maybe CanaryStateReasonCode))
-> CanaryStatus -> f CanaryStatus
canaryStatus_stateReasonCode = (CanaryStatus -> Maybe CanaryStateReasonCode)
-> (CanaryStatus -> Maybe CanaryStateReasonCode -> CanaryStatus)
-> Lens
     CanaryStatus
     CanaryStatus
     (Maybe CanaryStateReasonCode)
     (Maybe CanaryStateReasonCode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryStatus' {Maybe CanaryStateReasonCode
stateReasonCode :: Maybe CanaryStateReasonCode
$sel:stateReasonCode:CanaryStatus' :: CanaryStatus -> Maybe CanaryStateReasonCode
stateReasonCode} -> Maybe CanaryStateReasonCode
stateReasonCode) (\s :: CanaryStatus
s@CanaryStatus' {} Maybe CanaryStateReasonCode
a -> CanaryStatus
s {$sel:stateReasonCode:CanaryStatus' :: Maybe CanaryStateReasonCode
stateReasonCode = Maybe CanaryStateReasonCode
a} :: CanaryStatus)

instance Core.FromJSON CanaryStatus where
  parseJSON :: Value -> Parser CanaryStatus
parseJSON =
    String
-> (Object -> Parser CanaryStatus) -> Value -> Parser CanaryStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CanaryStatus"
      ( \Object
x ->
          Maybe CanaryState
-> Maybe Text -> Maybe CanaryStateReasonCode -> CanaryStatus
CanaryStatus'
            (Maybe CanaryState
 -> Maybe Text -> Maybe CanaryStateReasonCode -> CanaryStatus)
-> Parser (Maybe CanaryState)
-> Parser
     (Maybe Text -> Maybe CanaryStateReasonCode -> CanaryStatus)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CanaryState)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"State")
            Parser (Maybe Text -> Maybe CanaryStateReasonCode -> CanaryStatus)
-> Parser (Maybe Text)
-> Parser (Maybe CanaryStateReasonCode -> CanaryStatus)
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
"StateReason")
            Parser (Maybe CanaryStateReasonCode -> CanaryStatus)
-> Parser (Maybe CanaryStateReasonCode) -> Parser CanaryStatus
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe CanaryStateReasonCode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"StateReasonCode")
      )

instance Prelude.Hashable CanaryStatus

instance Prelude.NFData CanaryStatus