{-# 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.SSMContacts.Types.Stage
-- 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.SSMContacts.Types.Stage where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSMContacts.Types.Target

-- | A set amount of time that an escalation plan or engagement plan engages
-- the specified contacts or contact methods.
--
-- /See:/ 'newStage' smart constructor.
data Stage = Stage'
  { -- | The time to wait until beginning the next stage. The duration can only
    -- be set to 0 if a target is specified.
    Stage -> Natural
durationInMinutes :: Prelude.Natural,
    -- | The contacts or contact methods that the escalation plan or engagement
    -- plan is engaging.
    Stage -> [Target]
targets :: [Target]
  }
  deriving (Stage -> Stage -> Bool
(Stage -> Stage -> Bool) -> (Stage -> Stage -> Bool) -> Eq Stage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Stage -> Stage -> Bool
$c/= :: Stage -> Stage -> Bool
== :: Stage -> Stage -> Bool
$c== :: Stage -> Stage -> Bool
Prelude.Eq, ReadPrec [Stage]
ReadPrec Stage
Int -> ReadS Stage
ReadS [Stage]
(Int -> ReadS Stage)
-> ReadS [Stage]
-> ReadPrec Stage
-> ReadPrec [Stage]
-> Read Stage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Stage]
$creadListPrec :: ReadPrec [Stage]
readPrec :: ReadPrec Stage
$creadPrec :: ReadPrec Stage
readList :: ReadS [Stage]
$creadList :: ReadS [Stage]
readsPrec :: Int -> ReadS Stage
$creadsPrec :: Int -> ReadS Stage
Prelude.Read, Int -> Stage -> ShowS
[Stage] -> ShowS
Stage -> String
(Int -> Stage -> ShowS)
-> (Stage -> String) -> ([Stage] -> ShowS) -> Show Stage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Stage] -> ShowS
$cshowList :: [Stage] -> ShowS
show :: Stage -> String
$cshow :: Stage -> String
showsPrec :: Int -> Stage -> ShowS
$cshowsPrec :: Int -> Stage -> ShowS
Prelude.Show, (forall x. Stage -> Rep Stage x)
-> (forall x. Rep Stage x -> Stage) -> Generic Stage
forall x. Rep Stage x -> Stage
forall x. Stage -> Rep Stage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Stage x -> Stage
$cfrom :: forall x. Stage -> Rep Stage x
Prelude.Generic)

-- |
-- Create a value of 'Stage' 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:
--
-- 'durationInMinutes', 'stage_durationInMinutes' - The time to wait until beginning the next stage. The duration can only
-- be set to 0 if a target is specified.
--
-- 'targets', 'stage_targets' - The contacts or contact methods that the escalation plan or engagement
-- plan is engaging.
newStage ::
  -- | 'durationInMinutes'
  Prelude.Natural ->
  Stage
newStage :: Natural -> Stage
newStage Natural
pDurationInMinutes_ =
  Stage' :: Natural -> [Target] -> Stage
Stage'
    { $sel:durationInMinutes:Stage' :: Natural
durationInMinutes = Natural
pDurationInMinutes_,
      $sel:targets:Stage' :: [Target]
targets = [Target]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The time to wait until beginning the next stage. The duration can only
-- be set to 0 if a target is specified.
stage_durationInMinutes :: Lens.Lens' Stage Prelude.Natural
stage_durationInMinutes :: (Natural -> f Natural) -> Stage -> f Stage
stage_durationInMinutes = (Stage -> Natural)
-> (Stage -> Natural -> Stage) -> Lens Stage Stage Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stage' {Natural
durationInMinutes :: Natural
$sel:durationInMinutes:Stage' :: Stage -> Natural
durationInMinutes} -> Natural
durationInMinutes) (\s :: Stage
s@Stage' {} Natural
a -> Stage
s {$sel:durationInMinutes:Stage' :: Natural
durationInMinutes = Natural
a} :: Stage)

-- | The contacts or contact methods that the escalation plan or engagement
-- plan is engaging.
stage_targets :: Lens.Lens' Stage [Target]
stage_targets :: ([Target] -> f [Target]) -> Stage -> f Stage
stage_targets = (Stage -> [Target])
-> (Stage -> [Target] -> Stage)
-> Lens Stage Stage [Target] [Target]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stage' {[Target]
targets :: [Target]
$sel:targets:Stage' :: Stage -> [Target]
targets} -> [Target]
targets) (\s :: Stage
s@Stage' {} [Target]
a -> Stage
s {$sel:targets:Stage' :: [Target]
targets = [Target]
a} :: Stage) (([Target] -> f [Target]) -> Stage -> f Stage)
-> (([Target] -> f [Target]) -> [Target] -> f [Target])
-> ([Target] -> f [Target])
-> Stage
-> f Stage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Target] -> f [Target]) -> [Target] -> f [Target]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Stage where
  parseJSON :: Value -> Parser Stage
parseJSON =
    String -> (Object -> Parser Stage) -> Value -> Parser Stage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Stage"
      ( \Object
x ->
          Natural -> [Target] -> Stage
Stage'
            (Natural -> [Target] -> Stage)
-> Parser Natural -> Parser ([Target] -> Stage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DurationInMinutes")
            Parser ([Target] -> Stage) -> Parser [Target] -> Parser Stage
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Target])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Targets" Parser (Maybe [Target]) -> [Target] -> Parser [Target]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Target]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Stage

instance Prelude.NFData Stage

instance Core.ToJSON Stage where
  toJSON :: Stage -> Value
toJSON Stage' {Natural
[Target]
targets :: [Target]
durationInMinutes :: Natural
$sel:targets:Stage' :: Stage -> [Target]
$sel:durationInMinutes:Stage' :: Stage -> Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"DurationInMinutes" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
durationInMinutes),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Targets" Text -> [Target] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Target]
targets)
          ]
      )