{-# 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.CanaryRunStatus
-- 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.CanaryRunStatus where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Synthetics.Types.CanaryRunState
import Amazonka.Synthetics.Types.CanaryRunStateReasonCode

-- | This structure contains the status information about a canary run.
--
-- /See:/ 'newCanaryRunStatus' smart constructor.
data CanaryRunStatus = CanaryRunStatus'
  { -- | The current state of the run.
    CanaryRunStatus -> Maybe CanaryRunState
state :: Prelude.Maybe CanaryRunState,
    -- | If run of the canary failed, this field contains the reason for the
    -- error.
    CanaryRunStatus -> Maybe Text
stateReason :: Prelude.Maybe Prelude.Text,
    -- | If this value is @CANARY_FAILURE@, an exception occurred in the canary
    -- code. If this value is @EXECUTION_FAILURE@, an exception occurred in
    -- CloudWatch Synthetics.
    CanaryRunStatus -> Maybe CanaryRunStateReasonCode
stateReasonCode :: Prelude.Maybe CanaryRunStateReasonCode
  }
  deriving (CanaryRunStatus -> CanaryRunStatus -> Bool
(CanaryRunStatus -> CanaryRunStatus -> Bool)
-> (CanaryRunStatus -> CanaryRunStatus -> Bool)
-> Eq CanaryRunStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CanaryRunStatus -> CanaryRunStatus -> Bool
$c/= :: CanaryRunStatus -> CanaryRunStatus -> Bool
== :: CanaryRunStatus -> CanaryRunStatus -> Bool
$c== :: CanaryRunStatus -> CanaryRunStatus -> Bool
Prelude.Eq, ReadPrec [CanaryRunStatus]
ReadPrec CanaryRunStatus
Int -> ReadS CanaryRunStatus
ReadS [CanaryRunStatus]
(Int -> ReadS CanaryRunStatus)
-> ReadS [CanaryRunStatus]
-> ReadPrec CanaryRunStatus
-> ReadPrec [CanaryRunStatus]
-> Read CanaryRunStatus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CanaryRunStatus]
$creadListPrec :: ReadPrec [CanaryRunStatus]
readPrec :: ReadPrec CanaryRunStatus
$creadPrec :: ReadPrec CanaryRunStatus
readList :: ReadS [CanaryRunStatus]
$creadList :: ReadS [CanaryRunStatus]
readsPrec :: Int -> ReadS CanaryRunStatus
$creadsPrec :: Int -> ReadS CanaryRunStatus
Prelude.Read, Int -> CanaryRunStatus -> ShowS
[CanaryRunStatus] -> ShowS
CanaryRunStatus -> String
(Int -> CanaryRunStatus -> ShowS)
-> (CanaryRunStatus -> String)
-> ([CanaryRunStatus] -> ShowS)
-> Show CanaryRunStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CanaryRunStatus] -> ShowS
$cshowList :: [CanaryRunStatus] -> ShowS
show :: CanaryRunStatus -> String
$cshow :: CanaryRunStatus -> String
showsPrec :: Int -> CanaryRunStatus -> ShowS
$cshowsPrec :: Int -> CanaryRunStatus -> ShowS
Prelude.Show, (forall x. CanaryRunStatus -> Rep CanaryRunStatus x)
-> (forall x. Rep CanaryRunStatus x -> CanaryRunStatus)
-> Generic CanaryRunStatus
forall x. Rep CanaryRunStatus x -> CanaryRunStatus
forall x. CanaryRunStatus -> Rep CanaryRunStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CanaryRunStatus x -> CanaryRunStatus
$cfrom :: forall x. CanaryRunStatus -> Rep CanaryRunStatus x
Prelude.Generic)

-- |
-- Create a value of 'CanaryRunStatus' 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', 'canaryRunStatus_state' - The current state of the run.
--
-- 'stateReason', 'canaryRunStatus_stateReason' - If run of the canary failed, this field contains the reason for the
-- error.
--
-- 'stateReasonCode', 'canaryRunStatus_stateReasonCode' - If this value is @CANARY_FAILURE@, an exception occurred in the canary
-- code. If this value is @EXECUTION_FAILURE@, an exception occurred in
-- CloudWatch Synthetics.
newCanaryRunStatus ::
  CanaryRunStatus
newCanaryRunStatus :: CanaryRunStatus
newCanaryRunStatus =
  CanaryRunStatus' :: Maybe CanaryRunState
-> Maybe Text -> Maybe CanaryRunStateReasonCode -> CanaryRunStatus
CanaryRunStatus'
    { $sel:state:CanaryRunStatus' :: Maybe CanaryRunState
state = Maybe CanaryRunState
forall a. Maybe a
Prelude.Nothing,
      $sel:stateReason:CanaryRunStatus' :: Maybe Text
stateReason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stateReasonCode:CanaryRunStatus' :: Maybe CanaryRunStateReasonCode
stateReasonCode = Maybe CanaryRunStateReasonCode
forall a. Maybe a
Prelude.Nothing
    }

-- | The current state of the run.
canaryRunStatus_state :: Lens.Lens' CanaryRunStatus (Prelude.Maybe CanaryRunState)
canaryRunStatus_state :: (Maybe CanaryRunState -> f (Maybe CanaryRunState))
-> CanaryRunStatus -> f CanaryRunStatus
canaryRunStatus_state = (CanaryRunStatus -> Maybe CanaryRunState)
-> (CanaryRunStatus -> Maybe CanaryRunState -> CanaryRunStatus)
-> Lens
     CanaryRunStatus
     CanaryRunStatus
     (Maybe CanaryRunState)
     (Maybe CanaryRunState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryRunStatus' {Maybe CanaryRunState
state :: Maybe CanaryRunState
$sel:state:CanaryRunStatus' :: CanaryRunStatus -> Maybe CanaryRunState
state} -> Maybe CanaryRunState
state) (\s :: CanaryRunStatus
s@CanaryRunStatus' {} Maybe CanaryRunState
a -> CanaryRunStatus
s {$sel:state:CanaryRunStatus' :: Maybe CanaryRunState
state = Maybe CanaryRunState
a} :: CanaryRunStatus)

-- | If run of the canary failed, this field contains the reason for the
-- error.
canaryRunStatus_stateReason :: Lens.Lens' CanaryRunStatus (Prelude.Maybe Prelude.Text)
canaryRunStatus_stateReason :: (Maybe Text -> f (Maybe Text))
-> CanaryRunStatus -> f CanaryRunStatus
canaryRunStatus_stateReason = (CanaryRunStatus -> Maybe Text)
-> (CanaryRunStatus -> Maybe Text -> CanaryRunStatus)
-> Lens CanaryRunStatus CanaryRunStatus (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryRunStatus' {Maybe Text
stateReason :: Maybe Text
$sel:stateReason:CanaryRunStatus' :: CanaryRunStatus -> Maybe Text
stateReason} -> Maybe Text
stateReason) (\s :: CanaryRunStatus
s@CanaryRunStatus' {} Maybe Text
a -> CanaryRunStatus
s {$sel:stateReason:CanaryRunStatus' :: Maybe Text
stateReason = Maybe Text
a} :: CanaryRunStatus)

-- | If this value is @CANARY_FAILURE@, an exception occurred in the canary
-- code. If this value is @EXECUTION_FAILURE@, an exception occurred in
-- CloudWatch Synthetics.
canaryRunStatus_stateReasonCode :: Lens.Lens' CanaryRunStatus (Prelude.Maybe CanaryRunStateReasonCode)
canaryRunStatus_stateReasonCode :: (Maybe CanaryRunStateReasonCode
 -> f (Maybe CanaryRunStateReasonCode))
-> CanaryRunStatus -> f CanaryRunStatus
canaryRunStatus_stateReasonCode = (CanaryRunStatus -> Maybe CanaryRunStateReasonCode)
-> (CanaryRunStatus
    -> Maybe CanaryRunStateReasonCode -> CanaryRunStatus)
-> Lens
     CanaryRunStatus
     CanaryRunStatus
     (Maybe CanaryRunStateReasonCode)
     (Maybe CanaryRunStateReasonCode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryRunStatus' {Maybe CanaryRunStateReasonCode
stateReasonCode :: Maybe CanaryRunStateReasonCode
$sel:stateReasonCode:CanaryRunStatus' :: CanaryRunStatus -> Maybe CanaryRunStateReasonCode
stateReasonCode} -> Maybe CanaryRunStateReasonCode
stateReasonCode) (\s :: CanaryRunStatus
s@CanaryRunStatus' {} Maybe CanaryRunStateReasonCode
a -> CanaryRunStatus
s {$sel:stateReasonCode:CanaryRunStatus' :: Maybe CanaryRunStateReasonCode
stateReasonCode = Maybe CanaryRunStateReasonCode
a} :: CanaryRunStatus)

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

instance Prelude.Hashable CanaryRunStatus

instance Prelude.NFData CanaryRunStatus