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

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

-- | The stages that an escalation plan or engagement plan engages contacts
-- and contact methods in.
--
-- /See:/ 'newPlan' smart constructor.
data Plan = Plan'
  { -- | A list of stages that the escalation plan or engagement plan uses to
    -- engage contacts and contact methods.
    Plan -> [Stage]
stages :: [Stage]
  }
  deriving (Plan -> Plan -> Bool
(Plan -> Plan -> Bool) -> (Plan -> Plan -> Bool) -> Eq Plan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Plan -> Plan -> Bool
$c/= :: Plan -> Plan -> Bool
== :: Plan -> Plan -> Bool
$c== :: Plan -> Plan -> Bool
Prelude.Eq, ReadPrec [Plan]
ReadPrec Plan
Int -> ReadS Plan
ReadS [Plan]
(Int -> ReadS Plan)
-> ReadS [Plan] -> ReadPrec Plan -> ReadPrec [Plan] -> Read Plan
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Plan]
$creadListPrec :: ReadPrec [Plan]
readPrec :: ReadPrec Plan
$creadPrec :: ReadPrec Plan
readList :: ReadS [Plan]
$creadList :: ReadS [Plan]
readsPrec :: Int -> ReadS Plan
$creadsPrec :: Int -> ReadS Plan
Prelude.Read, Int -> Plan -> ShowS
[Plan] -> ShowS
Plan -> String
(Int -> Plan -> ShowS)
-> (Plan -> String) -> ([Plan] -> ShowS) -> Show Plan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Plan] -> ShowS
$cshowList :: [Plan] -> ShowS
show :: Plan -> String
$cshow :: Plan -> String
showsPrec :: Int -> Plan -> ShowS
$cshowsPrec :: Int -> Plan -> ShowS
Prelude.Show, (forall x. Plan -> Rep Plan x)
-> (forall x. Rep Plan x -> Plan) -> Generic Plan
forall x. Rep Plan x -> Plan
forall x. Plan -> Rep Plan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Plan x -> Plan
$cfrom :: forall x. Plan -> Rep Plan x
Prelude.Generic)

-- |
-- Create a value of 'Plan' 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:
--
-- 'stages', 'plan_stages' - A list of stages that the escalation plan or engagement plan uses to
-- engage contacts and contact methods.
newPlan ::
  Plan
newPlan :: Plan
newPlan = Plan' :: [Stage] -> Plan
Plan' {$sel:stages:Plan' :: [Stage]
stages = [Stage]
forall a. Monoid a => a
Prelude.mempty}

-- | A list of stages that the escalation plan or engagement plan uses to
-- engage contacts and contact methods.
plan_stages :: Lens.Lens' Plan [Stage]
plan_stages :: ([Stage] -> f [Stage]) -> Plan -> f Plan
plan_stages = (Plan -> [Stage])
-> (Plan -> [Stage] -> Plan) -> Lens Plan Plan [Stage] [Stage]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Plan' {[Stage]
stages :: [Stage]
$sel:stages:Plan' :: Plan -> [Stage]
stages} -> [Stage]
stages) (\s :: Plan
s@Plan' {} [Stage]
a -> Plan
s {$sel:stages:Plan' :: [Stage]
stages = [Stage]
a} :: Plan) (([Stage] -> f [Stage]) -> Plan -> f Plan)
-> (([Stage] -> f [Stage]) -> [Stage] -> f [Stage])
-> ([Stage] -> f [Stage])
-> Plan
-> f Plan
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Stage] -> f [Stage]) -> [Stage] -> f [Stage]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Plan

instance Prelude.NFData Plan

instance Core.ToJSON Plan where
  toJSON :: Plan -> Value
toJSON Plan' {[Stage]
stages :: [Stage]
$sel:stages:Plan' :: Plan -> [Stage]
..} =
    [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
"Stages" Text -> [Stage] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Stage]
stages)]
      )