{-# 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.CodePipeline.Types.StageDeclaration
-- 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.CodePipeline.Types.StageDeclaration where

import Amazonka.CodePipeline.Types.ActionDeclaration
import Amazonka.CodePipeline.Types.BlockerDeclaration
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents information about a stage and its definition.
--
-- /See:/ 'newStageDeclaration' smart constructor.
data StageDeclaration = StageDeclaration'
  { -- | Reserved for future use.
    StageDeclaration -> Maybe [BlockerDeclaration]
blockers :: Prelude.Maybe [BlockerDeclaration],
    -- | The name of the stage.
    StageDeclaration -> Text
name :: Prelude.Text,
    -- | The actions included in a stage.
    StageDeclaration -> [ActionDeclaration]
actions :: [ActionDeclaration]
  }
  deriving (StageDeclaration -> StageDeclaration -> Bool
(StageDeclaration -> StageDeclaration -> Bool)
-> (StageDeclaration -> StageDeclaration -> Bool)
-> Eq StageDeclaration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StageDeclaration -> StageDeclaration -> Bool
$c/= :: StageDeclaration -> StageDeclaration -> Bool
== :: StageDeclaration -> StageDeclaration -> Bool
$c== :: StageDeclaration -> StageDeclaration -> Bool
Prelude.Eq, ReadPrec [StageDeclaration]
ReadPrec StageDeclaration
Int -> ReadS StageDeclaration
ReadS [StageDeclaration]
(Int -> ReadS StageDeclaration)
-> ReadS [StageDeclaration]
-> ReadPrec StageDeclaration
-> ReadPrec [StageDeclaration]
-> Read StageDeclaration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StageDeclaration]
$creadListPrec :: ReadPrec [StageDeclaration]
readPrec :: ReadPrec StageDeclaration
$creadPrec :: ReadPrec StageDeclaration
readList :: ReadS [StageDeclaration]
$creadList :: ReadS [StageDeclaration]
readsPrec :: Int -> ReadS StageDeclaration
$creadsPrec :: Int -> ReadS StageDeclaration
Prelude.Read, Int -> StageDeclaration -> ShowS
[StageDeclaration] -> ShowS
StageDeclaration -> String
(Int -> StageDeclaration -> ShowS)
-> (StageDeclaration -> String)
-> ([StageDeclaration] -> ShowS)
-> Show StageDeclaration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StageDeclaration] -> ShowS
$cshowList :: [StageDeclaration] -> ShowS
show :: StageDeclaration -> String
$cshow :: StageDeclaration -> String
showsPrec :: Int -> StageDeclaration -> ShowS
$cshowsPrec :: Int -> StageDeclaration -> ShowS
Prelude.Show, (forall x. StageDeclaration -> Rep StageDeclaration x)
-> (forall x. Rep StageDeclaration x -> StageDeclaration)
-> Generic StageDeclaration
forall x. Rep StageDeclaration x -> StageDeclaration
forall x. StageDeclaration -> Rep StageDeclaration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StageDeclaration x -> StageDeclaration
$cfrom :: forall x. StageDeclaration -> Rep StageDeclaration x
Prelude.Generic)

-- |
-- Create a value of 'StageDeclaration' 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:
--
-- 'blockers', 'stageDeclaration_blockers' - Reserved for future use.
--
-- 'name', 'stageDeclaration_name' - The name of the stage.
--
-- 'actions', 'stageDeclaration_actions' - The actions included in a stage.
newStageDeclaration ::
  -- | 'name'
  Prelude.Text ->
  StageDeclaration
newStageDeclaration :: Text -> StageDeclaration
newStageDeclaration Text
pName_ =
  StageDeclaration' :: Maybe [BlockerDeclaration]
-> Text -> [ActionDeclaration] -> StageDeclaration
StageDeclaration'
    { $sel:blockers:StageDeclaration' :: Maybe [BlockerDeclaration]
blockers = Maybe [BlockerDeclaration]
forall a. Maybe a
Prelude.Nothing,
      $sel:name:StageDeclaration' :: Text
name = Text
pName_,
      $sel:actions:StageDeclaration' :: [ActionDeclaration]
actions = [ActionDeclaration]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Reserved for future use.
stageDeclaration_blockers :: Lens.Lens' StageDeclaration (Prelude.Maybe [BlockerDeclaration])
stageDeclaration_blockers :: (Maybe [BlockerDeclaration] -> f (Maybe [BlockerDeclaration]))
-> StageDeclaration -> f StageDeclaration
stageDeclaration_blockers = (StageDeclaration -> Maybe [BlockerDeclaration])
-> (StageDeclaration
    -> Maybe [BlockerDeclaration] -> StageDeclaration)
-> Lens
     StageDeclaration
     StageDeclaration
     (Maybe [BlockerDeclaration])
     (Maybe [BlockerDeclaration])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StageDeclaration' {Maybe [BlockerDeclaration]
blockers :: Maybe [BlockerDeclaration]
$sel:blockers:StageDeclaration' :: StageDeclaration -> Maybe [BlockerDeclaration]
blockers} -> Maybe [BlockerDeclaration]
blockers) (\s :: StageDeclaration
s@StageDeclaration' {} Maybe [BlockerDeclaration]
a -> StageDeclaration
s {$sel:blockers:StageDeclaration' :: Maybe [BlockerDeclaration]
blockers = Maybe [BlockerDeclaration]
a} :: StageDeclaration) ((Maybe [BlockerDeclaration] -> f (Maybe [BlockerDeclaration]))
 -> StageDeclaration -> f StageDeclaration)
-> ((Maybe [BlockerDeclaration] -> f (Maybe [BlockerDeclaration]))
    -> Maybe [BlockerDeclaration] -> f (Maybe [BlockerDeclaration]))
-> (Maybe [BlockerDeclaration] -> f (Maybe [BlockerDeclaration]))
-> StageDeclaration
-> f StageDeclaration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [BlockerDeclaration]
  [BlockerDeclaration]
  [BlockerDeclaration]
  [BlockerDeclaration]
-> Iso
     (Maybe [BlockerDeclaration])
     (Maybe [BlockerDeclaration])
     (Maybe [BlockerDeclaration])
     (Maybe [BlockerDeclaration])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [BlockerDeclaration]
  [BlockerDeclaration]
  [BlockerDeclaration]
  [BlockerDeclaration]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the stage.
stageDeclaration_name :: Lens.Lens' StageDeclaration Prelude.Text
stageDeclaration_name :: (Text -> f Text) -> StageDeclaration -> f StageDeclaration
stageDeclaration_name = (StageDeclaration -> Text)
-> (StageDeclaration -> Text -> StageDeclaration)
-> Lens StageDeclaration StageDeclaration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StageDeclaration' {Text
name :: Text
$sel:name:StageDeclaration' :: StageDeclaration -> Text
name} -> Text
name) (\s :: StageDeclaration
s@StageDeclaration' {} Text
a -> StageDeclaration
s {$sel:name:StageDeclaration' :: Text
name = Text
a} :: StageDeclaration)

-- | The actions included in a stage.
stageDeclaration_actions :: Lens.Lens' StageDeclaration [ActionDeclaration]
stageDeclaration_actions :: ([ActionDeclaration] -> f [ActionDeclaration])
-> StageDeclaration -> f StageDeclaration
stageDeclaration_actions = (StageDeclaration -> [ActionDeclaration])
-> (StageDeclaration -> [ActionDeclaration] -> StageDeclaration)
-> Lens
     StageDeclaration
     StageDeclaration
     [ActionDeclaration]
     [ActionDeclaration]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StageDeclaration' {[ActionDeclaration]
actions :: [ActionDeclaration]
$sel:actions:StageDeclaration' :: StageDeclaration -> [ActionDeclaration]
actions} -> [ActionDeclaration]
actions) (\s :: StageDeclaration
s@StageDeclaration' {} [ActionDeclaration]
a -> StageDeclaration
s {$sel:actions:StageDeclaration' :: [ActionDeclaration]
actions = [ActionDeclaration]
a} :: StageDeclaration) (([ActionDeclaration] -> f [ActionDeclaration])
 -> StageDeclaration -> f StageDeclaration)
-> (([ActionDeclaration] -> f [ActionDeclaration])
    -> [ActionDeclaration] -> f [ActionDeclaration])
-> ([ActionDeclaration] -> f [ActionDeclaration])
-> StageDeclaration
-> f StageDeclaration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ActionDeclaration] -> f [ActionDeclaration])
-> [ActionDeclaration] -> f [ActionDeclaration]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON StageDeclaration where
  parseJSON :: Value -> Parser StageDeclaration
parseJSON =
    String
-> (Object -> Parser StageDeclaration)
-> Value
-> Parser StageDeclaration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"StageDeclaration"
      ( \Object
x ->
          Maybe [BlockerDeclaration]
-> Text -> [ActionDeclaration] -> StageDeclaration
StageDeclaration'
            (Maybe [BlockerDeclaration]
 -> Text -> [ActionDeclaration] -> StageDeclaration)
-> Parser (Maybe [BlockerDeclaration])
-> Parser (Text -> [ActionDeclaration] -> StageDeclaration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [BlockerDeclaration]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"blockers" Parser (Maybe (Maybe [BlockerDeclaration]))
-> Maybe [BlockerDeclaration]
-> Parser (Maybe [BlockerDeclaration])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [BlockerDeclaration]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> [ActionDeclaration] -> StageDeclaration)
-> Parser Text -> Parser ([ActionDeclaration] -> StageDeclaration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
            Parser ([ActionDeclaration] -> StageDeclaration)
-> Parser [ActionDeclaration] -> Parser StageDeclaration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [ActionDeclaration])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"actions" Parser (Maybe [ActionDeclaration])
-> [ActionDeclaration] -> Parser [ActionDeclaration]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [ActionDeclaration]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable StageDeclaration

instance Prelude.NFData StageDeclaration

instance Core.ToJSON StageDeclaration where
  toJSON :: StageDeclaration -> Value
toJSON StageDeclaration' {[ActionDeclaration]
Maybe [BlockerDeclaration]
Text
actions :: [ActionDeclaration]
name :: Text
blockers :: Maybe [BlockerDeclaration]
$sel:actions:StageDeclaration' :: StageDeclaration -> [ActionDeclaration]
$sel:name:StageDeclaration' :: StageDeclaration -> Text
$sel:blockers:StageDeclaration' :: StageDeclaration -> Maybe [BlockerDeclaration]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"blockers" Text -> [BlockerDeclaration] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([BlockerDeclaration] -> Pair)
-> Maybe [BlockerDeclaration] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [BlockerDeclaration]
blockers,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"actions" Text -> [ActionDeclaration] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [ActionDeclaration]
actions)
          ]
      )