{-# 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.Glue.Types.ApplyMapping
-- 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.Glue.Types.ApplyMapping where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Glue.Types.Mapping
import qualified Amazonka.Prelude as Prelude

-- | Specifies a transform that maps data property keys in the data source to
-- data property keys in the data target. You can rename keys, modify the
-- data types for keys, and choose which keys to drop from the dataset.
--
-- /See:/ 'newApplyMapping' smart constructor.
data ApplyMapping = ApplyMapping'
  { -- | The name of the transform node.
    ApplyMapping -> Text
name :: Prelude.Text,
    -- | The data inputs identified by their node names.
    ApplyMapping -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | Specifies the mapping of data property keys in the data source to data
    -- property keys in the data target.
    ApplyMapping -> [Mapping]
mapping :: [Mapping]
  }
  deriving (ApplyMapping -> ApplyMapping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApplyMapping -> ApplyMapping -> Bool
$c/= :: ApplyMapping -> ApplyMapping -> Bool
== :: ApplyMapping -> ApplyMapping -> Bool
$c== :: ApplyMapping -> ApplyMapping -> Bool
Prelude.Eq, ReadPrec [ApplyMapping]
ReadPrec ApplyMapping
Int -> ReadS ApplyMapping
ReadS [ApplyMapping]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ApplyMapping]
$creadListPrec :: ReadPrec [ApplyMapping]
readPrec :: ReadPrec ApplyMapping
$creadPrec :: ReadPrec ApplyMapping
readList :: ReadS [ApplyMapping]
$creadList :: ReadS [ApplyMapping]
readsPrec :: Int -> ReadS ApplyMapping
$creadsPrec :: Int -> ReadS ApplyMapping
Prelude.Read, Int -> ApplyMapping -> ShowS
[ApplyMapping] -> ShowS
ApplyMapping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApplyMapping] -> ShowS
$cshowList :: [ApplyMapping] -> ShowS
show :: ApplyMapping -> String
$cshow :: ApplyMapping -> String
showsPrec :: Int -> ApplyMapping -> ShowS
$cshowsPrec :: Int -> ApplyMapping -> ShowS
Prelude.Show, forall x. Rep ApplyMapping x -> ApplyMapping
forall x. ApplyMapping -> Rep ApplyMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApplyMapping x -> ApplyMapping
$cfrom :: forall x. ApplyMapping -> Rep ApplyMapping x
Prelude.Generic)

-- |
-- Create a value of 'ApplyMapping' 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:
--
-- 'name', 'applyMapping_name' - The name of the transform node.
--
-- 'inputs', 'applyMapping_inputs' - The data inputs identified by their node names.
--
-- 'mapping', 'applyMapping_mapping' - Specifies the mapping of data property keys in the data source to data
-- property keys in the data target.
newApplyMapping ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  ApplyMapping
newApplyMapping :: Text -> NonEmpty Text -> ApplyMapping
newApplyMapping Text
pName_ NonEmpty Text
pInputs_ =
  ApplyMapping'
    { $sel:name:ApplyMapping' :: Text
name = Text
pName_,
      $sel:inputs:ApplyMapping' :: NonEmpty Text
inputs = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pInputs_,
      $sel:mapping:ApplyMapping' :: [Mapping]
mapping = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the transform node.
applyMapping_name :: Lens.Lens' ApplyMapping Prelude.Text
applyMapping_name :: Lens' ApplyMapping Text
applyMapping_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplyMapping' {Text
name :: Text
$sel:name:ApplyMapping' :: ApplyMapping -> Text
name} -> Text
name) (\s :: ApplyMapping
s@ApplyMapping' {} Text
a -> ApplyMapping
s {$sel:name:ApplyMapping' :: Text
name = Text
a} :: ApplyMapping)

-- | The data inputs identified by their node names.
applyMapping_inputs :: Lens.Lens' ApplyMapping (Prelude.NonEmpty Prelude.Text)
applyMapping_inputs :: Lens' ApplyMapping (NonEmpty Text)
applyMapping_inputs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplyMapping' {NonEmpty Text
inputs :: NonEmpty Text
$sel:inputs:ApplyMapping' :: ApplyMapping -> NonEmpty Text
inputs} -> NonEmpty Text
inputs) (\s :: ApplyMapping
s@ApplyMapping' {} NonEmpty Text
a -> ApplyMapping
s {$sel:inputs:ApplyMapping' :: NonEmpty Text
inputs = NonEmpty Text
a} :: ApplyMapping) 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

-- | Specifies the mapping of data property keys in the data source to data
-- property keys in the data target.
applyMapping_mapping :: Lens.Lens' ApplyMapping [Mapping]
applyMapping_mapping :: Lens' ApplyMapping [Mapping]
applyMapping_mapping = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplyMapping' {[Mapping]
mapping :: [Mapping]
$sel:mapping:ApplyMapping' :: ApplyMapping -> [Mapping]
mapping} -> [Mapping]
mapping) (\s :: ApplyMapping
s@ApplyMapping' {} [Mapping]
a -> ApplyMapping
s {$sel:mapping:ApplyMapping' :: [Mapping]
mapping = [Mapping]
a} :: ApplyMapping) 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 ApplyMapping where
  parseJSON :: Value -> Parser ApplyMapping
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ApplyMapping"
      ( \Object
x ->
          Text -> NonEmpty Text -> [Mapping] -> ApplyMapping
ApplyMapping'
            forall (f :: * -> *) a b. Functor 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 a
Data..: Key
"Inputs")
            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
"Mapping" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ApplyMapping where
  hashWithSalt :: Int -> ApplyMapping -> Int
hashWithSalt Int
_salt ApplyMapping' {[Mapping]
NonEmpty Text
Text
mapping :: [Mapping]
inputs :: NonEmpty Text
name :: Text
$sel:mapping:ApplyMapping' :: ApplyMapping -> [Mapping]
$sel:inputs:ApplyMapping' :: ApplyMapping -> NonEmpty Text
$sel:name:ApplyMapping' :: ApplyMapping -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
inputs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Mapping]
mapping

instance Prelude.NFData ApplyMapping where
  rnf :: ApplyMapping -> ()
rnf ApplyMapping' {[Mapping]
NonEmpty Text
Text
mapping :: [Mapping]
inputs :: NonEmpty Text
name :: Text
$sel:mapping:ApplyMapping' :: ApplyMapping -> [Mapping]
$sel:inputs:ApplyMapping' :: ApplyMapping -> NonEmpty Text
$sel:name:ApplyMapping' :: ApplyMapping -> Text
..} =
    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 NonEmpty Text
inputs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Mapping]
mapping

instance Data.ToJSON ApplyMapping where
  toJSON :: ApplyMapping -> Value
toJSON ApplyMapping' {[Mapping]
NonEmpty Text
Text
mapping :: [Mapping]
inputs :: NonEmpty Text
name :: Text
$sel:mapping:ApplyMapping' :: ApplyMapping -> [Mapping]
$sel:inputs:ApplyMapping' :: ApplyMapping -> NonEmpty Text
$sel:name:ApplyMapping' :: ApplyMapping -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ 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
"Inputs" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
inputs),
            forall a. a -> Maybe a
Prelude.Just (Key
"Mapping" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Mapping]
mapping)
          ]
      )