{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SSMContacts.Types.Stage where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:durationInMinutes:Stage' :: Natural
durationInMinutes = Natural
pDurationInMinutes_,
      $sel:targets:Stage' :: [Target]
targets = 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 :: Lens' Stage Natural
stage_durationInMinutes = 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 :: Lens' Stage [Target]
stage_targets = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON Stage where
  parseJSON :: Value -> Parser Stage
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Stage"
      ( \Object
x ->
          Natural -> [Target] -> Stage
Stage'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"DurationInMinutes")
            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
"Targets" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Stage where
  hashWithSalt :: Int -> Stage -> Int
hashWithSalt Int
_salt Stage' {Natural
[Target]
targets :: [Target]
durationInMinutes :: Natural
$sel:targets:Stage' :: Stage -> [Target]
$sel:durationInMinutes:Stage' :: Stage -> Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
durationInMinutes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Target]
targets

instance Prelude.NFData Stage where
  rnf :: Stage -> ()
rnf Stage' {Natural
[Target]
targets :: [Target]
durationInMinutes :: Natural
$sel:targets:Stage' :: Stage -> [Target]
$sel:durationInMinutes:Stage' :: Stage -> Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Natural
durationInMinutes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Target]
targets

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"DurationInMinutes" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
durationInMinutes),
            forall a. a -> Maybe a
Prelude.Just (Key
"Targets" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Target]
targets)
          ]
      )