{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:blockers:StageDeclaration' :: Maybe [BlockerDeclaration]
blockers = forall a. Maybe a
Prelude.Nothing,
      $sel:name:StageDeclaration' :: Text
name = Text
pName_,
      $sel:actions:StageDeclaration' :: [ActionDeclaration]
actions = forall a. Monoid a => a
Prelude.mempty
    }

-- | Reserved for future use.
stageDeclaration_blockers :: Lens.Lens' StageDeclaration (Prelude.Maybe [BlockerDeclaration])
stageDeclaration_blockers :: Lens' StageDeclaration (Maybe [BlockerDeclaration])
stageDeclaration_blockers = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' StageDeclaration Text
stageDeclaration_name = 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 :: Lens' StageDeclaration [ActionDeclaration]
stageDeclaration_actions = 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) 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 StageDeclaration where
  parseJSON :: Value -> Parser StageDeclaration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"StageDeclaration"
      ( \Object
x ->
          Maybe [BlockerDeclaration]
-> Text -> [ActionDeclaration] -> StageDeclaration
StageDeclaration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"blockers" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"name")
            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
"actions" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable StageDeclaration where
  hashWithSalt :: Int -> StageDeclaration -> Int
hashWithSalt Int
_salt 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]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [BlockerDeclaration]
blockers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ActionDeclaration]
actions

instance Prelude.NFData StageDeclaration where
  rnf :: StageDeclaration -> ()
rnf 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]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [BlockerDeclaration]
blockers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [ActionDeclaration]
actions

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"blockers" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [BlockerDeclaration]
blockers,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"actions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [ActionDeclaration]
actions)
          ]
      )