{-# 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.DataBrew.Types.RecipeStep
-- 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.DataBrew.Types.RecipeStep where

import qualified Amazonka.Core as Core
import Amazonka.DataBrew.Types.ConditionExpression
import Amazonka.DataBrew.Types.RecipeAction
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a single step from a DataBrew recipe to be performed.
--
-- /See:/ 'newRecipeStep' smart constructor.
data RecipeStep = RecipeStep'
  { -- | One or more conditions that must be met for the recipe step to succeed.
    --
    -- All of the conditions in the array must be met. In other words, all of
    -- the conditions must be combined using a logical AND operation.
    RecipeStep -> Maybe [ConditionExpression]
conditionExpressions :: Prelude.Maybe [ConditionExpression],
    -- | The particular action to be performed in the recipe step.
    RecipeStep -> RecipeAction
action :: RecipeAction
  }
  deriving (RecipeStep -> RecipeStep -> Bool
(RecipeStep -> RecipeStep -> Bool)
-> (RecipeStep -> RecipeStep -> Bool) -> Eq RecipeStep
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecipeStep -> RecipeStep -> Bool
$c/= :: RecipeStep -> RecipeStep -> Bool
== :: RecipeStep -> RecipeStep -> Bool
$c== :: RecipeStep -> RecipeStep -> Bool
Prelude.Eq, ReadPrec [RecipeStep]
ReadPrec RecipeStep
Int -> ReadS RecipeStep
ReadS [RecipeStep]
(Int -> ReadS RecipeStep)
-> ReadS [RecipeStep]
-> ReadPrec RecipeStep
-> ReadPrec [RecipeStep]
-> Read RecipeStep
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecipeStep]
$creadListPrec :: ReadPrec [RecipeStep]
readPrec :: ReadPrec RecipeStep
$creadPrec :: ReadPrec RecipeStep
readList :: ReadS [RecipeStep]
$creadList :: ReadS [RecipeStep]
readsPrec :: Int -> ReadS RecipeStep
$creadsPrec :: Int -> ReadS RecipeStep
Prelude.Read, Int -> RecipeStep -> ShowS
[RecipeStep] -> ShowS
RecipeStep -> String
(Int -> RecipeStep -> ShowS)
-> (RecipeStep -> String)
-> ([RecipeStep] -> ShowS)
-> Show RecipeStep
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecipeStep] -> ShowS
$cshowList :: [RecipeStep] -> ShowS
show :: RecipeStep -> String
$cshow :: RecipeStep -> String
showsPrec :: Int -> RecipeStep -> ShowS
$cshowsPrec :: Int -> RecipeStep -> ShowS
Prelude.Show, (forall x. RecipeStep -> Rep RecipeStep x)
-> (forall x. Rep RecipeStep x -> RecipeStep) -> Generic RecipeStep
forall x. Rep RecipeStep x -> RecipeStep
forall x. RecipeStep -> Rep RecipeStep x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecipeStep x -> RecipeStep
$cfrom :: forall x. RecipeStep -> Rep RecipeStep x
Prelude.Generic)

-- |
-- Create a value of 'RecipeStep' 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:
--
-- 'conditionExpressions', 'recipeStep_conditionExpressions' - One or more conditions that must be met for the recipe step to succeed.
--
-- All of the conditions in the array must be met. In other words, all of
-- the conditions must be combined using a logical AND operation.
--
-- 'action', 'recipeStep_action' - The particular action to be performed in the recipe step.
newRecipeStep ::
  -- | 'action'
  RecipeAction ->
  RecipeStep
newRecipeStep :: RecipeAction -> RecipeStep
newRecipeStep RecipeAction
pAction_ =
  RecipeStep' :: Maybe [ConditionExpression] -> RecipeAction -> RecipeStep
RecipeStep'
    { $sel:conditionExpressions:RecipeStep' :: Maybe [ConditionExpression]
conditionExpressions = Maybe [ConditionExpression]
forall a. Maybe a
Prelude.Nothing,
      $sel:action:RecipeStep' :: RecipeAction
action = RecipeAction
pAction_
    }

-- | One or more conditions that must be met for the recipe step to succeed.
--
-- All of the conditions in the array must be met. In other words, all of
-- the conditions must be combined using a logical AND operation.
recipeStep_conditionExpressions :: Lens.Lens' RecipeStep (Prelude.Maybe [ConditionExpression])
recipeStep_conditionExpressions :: (Maybe [ConditionExpression] -> f (Maybe [ConditionExpression]))
-> RecipeStep -> f RecipeStep
recipeStep_conditionExpressions = (RecipeStep -> Maybe [ConditionExpression])
-> (RecipeStep -> Maybe [ConditionExpression] -> RecipeStep)
-> Lens
     RecipeStep
     RecipeStep
     (Maybe [ConditionExpression])
     (Maybe [ConditionExpression])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecipeStep' {Maybe [ConditionExpression]
conditionExpressions :: Maybe [ConditionExpression]
$sel:conditionExpressions:RecipeStep' :: RecipeStep -> Maybe [ConditionExpression]
conditionExpressions} -> Maybe [ConditionExpression]
conditionExpressions) (\s :: RecipeStep
s@RecipeStep' {} Maybe [ConditionExpression]
a -> RecipeStep
s {$sel:conditionExpressions:RecipeStep' :: Maybe [ConditionExpression]
conditionExpressions = Maybe [ConditionExpression]
a} :: RecipeStep) ((Maybe [ConditionExpression] -> f (Maybe [ConditionExpression]))
 -> RecipeStep -> f RecipeStep)
-> ((Maybe [ConditionExpression]
     -> f (Maybe [ConditionExpression]))
    -> Maybe [ConditionExpression] -> f (Maybe [ConditionExpression]))
-> (Maybe [ConditionExpression] -> f (Maybe [ConditionExpression]))
-> RecipeStep
-> f RecipeStep
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [ConditionExpression]
  [ConditionExpression]
  [ConditionExpression]
  [ConditionExpression]
-> Iso
     (Maybe [ConditionExpression])
     (Maybe [ConditionExpression])
     (Maybe [ConditionExpression])
     (Maybe [ConditionExpression])
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
  [ConditionExpression]
  [ConditionExpression]
  [ConditionExpression]
  [ConditionExpression]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The particular action to be performed in the recipe step.
recipeStep_action :: Lens.Lens' RecipeStep RecipeAction
recipeStep_action :: (RecipeAction -> f RecipeAction) -> RecipeStep -> f RecipeStep
recipeStep_action = (RecipeStep -> RecipeAction)
-> (RecipeStep -> RecipeAction -> RecipeStep)
-> Lens RecipeStep RecipeStep RecipeAction RecipeAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecipeStep' {RecipeAction
action :: RecipeAction
$sel:action:RecipeStep' :: RecipeStep -> RecipeAction
action} -> RecipeAction
action) (\s :: RecipeStep
s@RecipeStep' {} RecipeAction
a -> RecipeStep
s {$sel:action:RecipeStep' :: RecipeAction
action = RecipeAction
a} :: RecipeStep)

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

instance Prelude.Hashable RecipeStep

instance Prelude.NFData RecipeStep

instance Core.ToJSON RecipeStep where
  toJSON :: RecipeStep -> Value
toJSON RecipeStep' {Maybe [ConditionExpression]
RecipeAction
action :: RecipeAction
conditionExpressions :: Maybe [ConditionExpression]
$sel:action:RecipeStep' :: RecipeStep -> RecipeAction
$sel:conditionExpressions:RecipeStep' :: RecipeStep -> Maybe [ConditionExpression]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ConditionExpressions" Text -> [ConditionExpression] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([ConditionExpression] -> Pair)
-> Maybe [ConditionExpression] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [ConditionExpression]
conditionExpressions,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Action" Text -> RecipeAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RecipeAction
action)
          ]
      )