{-# 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.RenameField
-- 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.RenameField 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

-- | Specifies a transform that renames a single data property key.
--
-- /See:/ 'newRenameField' smart constructor.
data RenameField = RenameField'
  { -- | The name of the transform node.
    RenameField -> Text
name :: Prelude.Text,
    -- | The data inputs identified by their node names.
    RenameField -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | A JSON path to a variable in the data structure for the source data.
    RenameField -> [Text]
sourcePath :: [Prelude.Text],
    -- | A JSON path to a variable in the data structure for the target data.
    RenameField -> [Text]
targetPath :: [Prelude.Text]
  }
  deriving (RenameField -> RenameField -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RenameField -> RenameField -> Bool
$c/= :: RenameField -> RenameField -> Bool
== :: RenameField -> RenameField -> Bool
$c== :: RenameField -> RenameField -> Bool
Prelude.Eq, ReadPrec [RenameField]
ReadPrec RenameField
Int -> ReadS RenameField
ReadS [RenameField]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RenameField]
$creadListPrec :: ReadPrec [RenameField]
readPrec :: ReadPrec RenameField
$creadPrec :: ReadPrec RenameField
readList :: ReadS [RenameField]
$creadList :: ReadS [RenameField]
readsPrec :: Int -> ReadS RenameField
$creadsPrec :: Int -> ReadS RenameField
Prelude.Read, Int -> RenameField -> ShowS
[RenameField] -> ShowS
RenameField -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RenameField] -> ShowS
$cshowList :: [RenameField] -> ShowS
show :: RenameField -> String
$cshow :: RenameField -> String
showsPrec :: Int -> RenameField -> ShowS
$cshowsPrec :: Int -> RenameField -> ShowS
Prelude.Show, forall x. Rep RenameField x -> RenameField
forall x. RenameField -> Rep RenameField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RenameField x -> RenameField
$cfrom :: forall x. RenameField -> Rep RenameField x
Prelude.Generic)

-- |
-- Create a value of 'RenameField' 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', 'renameField_name' - The name of the transform node.
--
-- 'inputs', 'renameField_inputs' - The data inputs identified by their node names.
--
-- 'sourcePath', 'renameField_sourcePath' - A JSON path to a variable in the data structure for the source data.
--
-- 'targetPath', 'renameField_targetPath' - A JSON path to a variable in the data structure for the target data.
newRenameField ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  RenameField
newRenameField :: Text -> NonEmpty Text -> RenameField
newRenameField Text
pName_ NonEmpty Text
pInputs_ =
  RenameField'
    { $sel:name:RenameField' :: Text
name = Text
pName_,
      $sel:inputs:RenameField' :: 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:sourcePath:RenameField' :: [Text]
sourcePath = forall a. Monoid a => a
Prelude.mempty,
      $sel:targetPath:RenameField' :: [Text]
targetPath = forall a. Monoid a => a
Prelude.mempty
    }

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

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

-- | A JSON path to a variable in the data structure for the source data.
renameField_sourcePath :: Lens.Lens' RenameField [Prelude.Text]
renameField_sourcePath :: Lens' RenameField [Text]
renameField_sourcePath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RenameField' {[Text]
sourcePath :: [Text]
$sel:sourcePath:RenameField' :: RenameField -> [Text]
sourcePath} -> [Text]
sourcePath) (\s :: RenameField
s@RenameField' {} [Text]
a -> RenameField
s {$sel:sourcePath:RenameField' :: [Text]
sourcePath = [Text]
a} :: RenameField) 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

-- | A JSON path to a variable in the data structure for the target data.
renameField_targetPath :: Lens.Lens' RenameField [Prelude.Text]
renameField_targetPath :: Lens' RenameField [Text]
renameField_targetPath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RenameField' {[Text]
targetPath :: [Text]
$sel:targetPath:RenameField' :: RenameField -> [Text]
targetPath} -> [Text]
targetPath) (\s :: RenameField
s@RenameField' {} [Text]
a -> RenameField
s {$sel:targetPath:RenameField' :: [Text]
targetPath = [Text]
a} :: RenameField) 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 RenameField where
  parseJSON :: Value -> Parser RenameField
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RenameField"
      ( \Object
x ->
          Text -> NonEmpty Text -> [Text] -> [Text] -> RenameField
RenameField'
            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
"SourcePath" 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 (Maybe a)
Data..:? Key
"TargetPath" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable RenameField where
  hashWithSalt :: Int -> RenameField -> Int
hashWithSalt Int
_salt RenameField' {[Text]
NonEmpty Text
Text
targetPath :: [Text]
sourcePath :: [Text]
inputs :: NonEmpty Text
name :: Text
$sel:targetPath:RenameField' :: RenameField -> [Text]
$sel:sourcePath:RenameField' :: RenameField -> [Text]
$sel:inputs:RenameField' :: RenameField -> NonEmpty Text
$sel:name:RenameField' :: RenameField -> 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` [Text]
sourcePath
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
targetPath

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

instance Data.ToJSON RenameField where
  toJSON :: RenameField -> Value
toJSON RenameField' {[Text]
NonEmpty Text
Text
targetPath :: [Text]
sourcePath :: [Text]
inputs :: NonEmpty Text
name :: Text
$sel:targetPath:RenameField' :: RenameField -> [Text]
$sel:sourcePath:RenameField' :: RenameField -> [Text]
$sel:inputs:RenameField' :: RenameField -> NonEmpty Text
$sel:name:RenameField' :: RenameField -> 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
"SourcePath" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
sourcePath),
            forall a. a -> Maybe a
Prelude.Just (Key
"TargetPath" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
targetPath)
          ]
      )