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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(RecipeAction -> RecipeAction -> Bool)
-> (RecipeAction -> RecipeAction -> Bool) -> Eq RecipeAction
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]
(Int -> ReadS RecipeAction)
-> ReadS [RecipeAction]
-> ReadPrec RecipeAction
-> ReadPrec [RecipeAction]
-> Read 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
(Int -> RecipeAction -> ShowS)
-> (RecipeAction -> String)
-> ([RecipeAction] -> ShowS)
-> Show RecipeAction
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. RecipeAction -> Rep RecipeAction x)
-> (forall x. Rep RecipeAction x -> RecipeAction)
-> Generic RecipeAction
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' :: Maybe (HashMap Text Text) -> Text -> RecipeAction
RecipeAction'
    { $sel:parameters:RecipeAction' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
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 :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> RecipeAction -> f RecipeAction
recipeAction_parameters = (RecipeAction -> Maybe (HashMap Text Text))
-> (RecipeAction -> Maybe (HashMap Text Text) -> RecipeAction)
-> Lens
     RecipeAction
     RecipeAction
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> RecipeAction -> f RecipeAction)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> RecipeAction
-> f RecipeAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
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 :: (Text -> f Text) -> RecipeAction -> f RecipeAction
recipeAction_operation = (RecipeAction -> Text)
-> (RecipeAction -> Text -> RecipeAction)
-> Lens RecipeAction RecipeAction Text Text
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 Core.FromJSON RecipeAction where
  parseJSON :: Value -> Parser RecipeAction
parseJSON =
    String
-> (Object -> Parser RecipeAction) -> Value -> Parser RecipeAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RecipeAction"
      ( \Object
x ->
          Maybe (HashMap Text Text) -> Text -> RecipeAction
RecipeAction'
            (Maybe (HashMap Text Text) -> Text -> RecipeAction)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Text -> RecipeAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Parameters" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> RecipeAction) -> Parser Text -> Parser RecipeAction
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
"Operation")
      )

instance Prelude.Hashable RecipeAction

instance Prelude.NFData RecipeAction

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Parameters" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
parameters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Operation" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
operation)
          ]
      )