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

-- | Represents a transformation and associated parameters that are used to
-- apply a change to a DataBrew dataset. For more information, see
-- <https://docs.aws.amazon.com/databrew/latest/dg/recipe-actions-reference.html Recipe actions reference>.
--
-- /See:/ 'newRecipeAction' smart constructor.
data RecipeAction = RecipeAction'
  { -- | Contextual parameters for the transformation.
    RecipeAction -> Maybe (HashMap Text Text)
parameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name of a valid DataBrew transformation to be performed on the data.
    RecipeAction -> Text
operation :: Prelude.Text
  }
  deriving (RecipeAction -> RecipeAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecipeAction -> RecipeAction -> Bool
$c/= :: RecipeAction -> RecipeAction -> Bool
== :: RecipeAction -> RecipeAction -> Bool
$c== :: RecipeAction -> RecipeAction -> Bool
Prelude.Eq, ReadPrec [RecipeAction]
ReadPrec RecipeAction
Int -> ReadS RecipeAction
ReadS [RecipeAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecipeAction]
$creadListPrec :: ReadPrec [RecipeAction]
readPrec :: ReadPrec RecipeAction
$creadPrec :: ReadPrec RecipeAction
readList :: ReadS [RecipeAction]
$creadList :: ReadS [RecipeAction]
readsPrec :: Int -> ReadS RecipeAction
$creadsPrec :: Int -> ReadS RecipeAction
Prelude.Read, Int -> RecipeAction -> ShowS
[RecipeAction] -> ShowS
RecipeAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecipeAction] -> ShowS
$cshowList :: [RecipeAction] -> ShowS
show :: RecipeAction -> String
$cshow :: RecipeAction -> String
showsPrec :: Int -> RecipeAction -> ShowS
$cshowsPrec :: Int -> RecipeAction -> ShowS
Prelude.Show, forall x. Rep RecipeAction x -> RecipeAction
forall x. RecipeAction -> Rep RecipeAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecipeAction x -> RecipeAction
$cfrom :: forall x. RecipeAction -> Rep RecipeAction x
Prelude.Generic)

-- |
-- Create a value of 'RecipeAction' 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:
--
-- 'parameters', 'recipeAction_parameters' - Contextual parameters for the transformation.
--
-- 'operation', 'recipeAction_operation' - The name of a valid DataBrew transformation to be performed on the data.
newRecipeAction ::
  -- | 'operation'
  Prelude.Text ->
  RecipeAction
newRecipeAction :: Text -> RecipeAction
newRecipeAction Text
pOperation_ =
  RecipeAction'
    { $sel:parameters:RecipeAction' :: Maybe (HashMap Text Text)
parameters = forall a. Maybe a
Prelude.Nothing,
      $sel:operation:RecipeAction' :: Text
operation = Text
pOperation_
    }

-- | Contextual parameters for the transformation.
recipeAction_parameters :: Lens.Lens' RecipeAction (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
recipeAction_parameters :: Lens' RecipeAction (Maybe (HashMap Text Text))
recipeAction_parameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecipeAction' {Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
$sel:parameters:RecipeAction' :: RecipeAction -> Maybe (HashMap Text Text)
parameters} -> Maybe (HashMap Text Text)
parameters) (\s :: RecipeAction
s@RecipeAction' {} Maybe (HashMap Text Text)
a -> RecipeAction
s {$sel:parameters:RecipeAction' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
a} :: RecipeAction) 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 a valid DataBrew transformation to be performed on the data.
recipeAction_operation :: Lens.Lens' RecipeAction Prelude.Text
recipeAction_operation :: Lens' RecipeAction Text
recipeAction_operation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecipeAction' {Text
operation :: Text
$sel:operation:RecipeAction' :: RecipeAction -> Text
operation} -> Text
operation) (\s :: RecipeAction
s@RecipeAction' {} Text
a -> RecipeAction
s {$sel:operation:RecipeAction' :: Text
operation = Text
a} :: RecipeAction)

instance Data.FromJSON RecipeAction where
  parseJSON :: Value -> Parser RecipeAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RecipeAction"
      ( \Object
x ->
          Maybe (HashMap Text Text) -> Text -> RecipeAction
RecipeAction'
            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
"Parameters" 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
"Operation")
      )

instance Prelude.Hashable RecipeAction where
  hashWithSalt :: Int -> RecipeAction -> Int
hashWithSalt Int
_salt RecipeAction' {Maybe (HashMap Text Text)
Text
operation :: Text
parameters :: Maybe (HashMap Text Text)
$sel:operation:RecipeAction' :: RecipeAction -> Text
$sel:parameters:RecipeAction' :: RecipeAction -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
parameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
operation

instance Prelude.NFData RecipeAction where
  rnf :: RecipeAction -> ()
rnf RecipeAction' {Maybe (HashMap Text Text)
Text
operation :: Text
parameters :: Maybe (HashMap Text Text)
$sel:operation:RecipeAction' :: RecipeAction -> Text
$sel:parameters:RecipeAction' :: RecipeAction -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
parameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
operation

instance Data.ToJSON RecipeAction where
  toJSON :: RecipeAction -> Value
toJSON RecipeAction' {Maybe (HashMap Text Text)
Text
operation :: Text
parameters :: Maybe (HashMap Text Text)
$sel:operation:RecipeAction' :: RecipeAction -> Text
$sel:parameters:RecipeAction' :: RecipeAction -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Parameters" 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 (HashMap Text Text)
parameters,
            forall a. a -> Maybe a
Prelude.Just (Key
"Operation" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
operation)
          ]
      )