{-# 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.Mapping
-- 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.Mapping 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 the mapping of data property keys.
--
-- /See:/ 'newMapping' smart constructor.
data Mapping = Mapping'
  { -- | Only applicable to nested data structures. If you want to change the
    -- parent structure, but also one of its children, you can fill out this
    -- data strucutre. It is also @Mapping@, but its @FromPath@ will be the
    -- parent\'s @FromPath@ plus the @FromPath@ from this structure.
    --
    -- For the children part, suppose you have the structure:
    --
    -- @{ \"FromPath\": \"OuterStructure\", \"ToKey\": \"OuterStructure\", \"ToType\": \"Struct\", \"Dropped\": false, \"Chidlren\": [{ \"FromPath\": \"inner\", \"ToKey\": \"inner\", \"ToType\": \"Double\", \"Dropped\": false, }] }@
    --
    -- You can specify a @Mapping@ that looks like:
    --
    -- @{ \"FromPath\": \"OuterStructure\", \"ToKey\": \"OuterStructure\", \"ToType\": \"Struct\", \"Dropped\": false, \"Chidlren\": [{ \"FromPath\": \"inner\", \"ToKey\": \"inner\", \"ToType\": \"Double\", \"Dropped\": false, }] }@
    Mapping -> Maybe [Mapping]
children :: Prelude.Maybe [Mapping],
    -- | If true, then the column is removed.
    Mapping -> Maybe Bool
dropped :: Prelude.Maybe Prelude.Bool,
    -- | The table or column to be modified.
    Mapping -> Maybe [Text]
fromPath :: Prelude.Maybe [Prelude.Text],
    -- | The type of the data to be modified.
    Mapping -> Maybe Text
fromType :: Prelude.Maybe Prelude.Text,
    -- | After the apply mapping, what the name of the column should be. Can be
    -- the same as @FromPath@.
    Mapping -> Maybe Text
toKey :: Prelude.Maybe Prelude.Text,
    -- | The data type that the data is to be modified to.
    Mapping -> Maybe Text
toType :: Prelude.Maybe Prelude.Text
  }
  deriving (Mapping -> Mapping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Mapping -> Mapping -> Bool
$c/= :: Mapping -> Mapping -> Bool
== :: Mapping -> Mapping -> Bool
$c== :: Mapping -> Mapping -> Bool
Prelude.Eq, ReadPrec [Mapping]
ReadPrec Mapping
Int -> ReadS Mapping
ReadS [Mapping]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Mapping]
$creadListPrec :: ReadPrec [Mapping]
readPrec :: ReadPrec Mapping
$creadPrec :: ReadPrec Mapping
readList :: ReadS [Mapping]
$creadList :: ReadS [Mapping]
readsPrec :: Int -> ReadS Mapping
$creadsPrec :: Int -> ReadS Mapping
Prelude.Read, Int -> Mapping -> ShowS
[Mapping] -> ShowS
Mapping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Mapping] -> ShowS
$cshowList :: [Mapping] -> ShowS
show :: Mapping -> String
$cshow :: Mapping -> String
showsPrec :: Int -> Mapping -> ShowS
$cshowsPrec :: Int -> Mapping -> ShowS
Prelude.Show, forall x. Rep Mapping x -> Mapping
forall x. Mapping -> Rep Mapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Mapping x -> Mapping
$cfrom :: forall x. Mapping -> Rep Mapping x
Prelude.Generic)

-- |
-- Create a value of 'Mapping' 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:
--
-- 'children', 'mapping_children' - Only applicable to nested data structures. If you want to change the
-- parent structure, but also one of its children, you can fill out this
-- data strucutre. It is also @Mapping@, but its @FromPath@ will be the
-- parent\'s @FromPath@ plus the @FromPath@ from this structure.
--
-- For the children part, suppose you have the structure:
--
-- @{ \"FromPath\": \"OuterStructure\", \"ToKey\": \"OuterStructure\", \"ToType\": \"Struct\", \"Dropped\": false, \"Chidlren\": [{ \"FromPath\": \"inner\", \"ToKey\": \"inner\", \"ToType\": \"Double\", \"Dropped\": false, }] }@
--
-- You can specify a @Mapping@ that looks like:
--
-- @{ \"FromPath\": \"OuterStructure\", \"ToKey\": \"OuterStructure\", \"ToType\": \"Struct\", \"Dropped\": false, \"Chidlren\": [{ \"FromPath\": \"inner\", \"ToKey\": \"inner\", \"ToType\": \"Double\", \"Dropped\": false, }] }@
--
-- 'dropped', 'mapping_dropped' - If true, then the column is removed.
--
-- 'fromPath', 'mapping_fromPath' - The table or column to be modified.
--
-- 'fromType', 'mapping_fromType' - The type of the data to be modified.
--
-- 'toKey', 'mapping_toKey' - After the apply mapping, what the name of the column should be. Can be
-- the same as @FromPath@.
--
-- 'toType', 'mapping_toType' - The data type that the data is to be modified to.
newMapping ::
  Mapping
newMapping :: Mapping
newMapping =
  Mapping'
    { $sel:children:Mapping' :: Maybe [Mapping]
children = forall a. Maybe a
Prelude.Nothing,
      $sel:dropped:Mapping' :: Maybe Bool
dropped = forall a. Maybe a
Prelude.Nothing,
      $sel:fromPath:Mapping' :: Maybe [Text]
fromPath = forall a. Maybe a
Prelude.Nothing,
      $sel:fromType:Mapping' :: Maybe Text
fromType = forall a. Maybe a
Prelude.Nothing,
      $sel:toKey:Mapping' :: Maybe Text
toKey = forall a. Maybe a
Prelude.Nothing,
      $sel:toType:Mapping' :: Maybe Text
toType = forall a. Maybe a
Prelude.Nothing
    }

-- | Only applicable to nested data structures. If you want to change the
-- parent structure, but also one of its children, you can fill out this
-- data strucutre. It is also @Mapping@, but its @FromPath@ will be the
-- parent\'s @FromPath@ plus the @FromPath@ from this structure.
--
-- For the children part, suppose you have the structure:
--
-- @{ \"FromPath\": \"OuterStructure\", \"ToKey\": \"OuterStructure\", \"ToType\": \"Struct\", \"Dropped\": false, \"Chidlren\": [{ \"FromPath\": \"inner\", \"ToKey\": \"inner\", \"ToType\": \"Double\", \"Dropped\": false, }] }@
--
-- You can specify a @Mapping@ that looks like:
--
-- @{ \"FromPath\": \"OuterStructure\", \"ToKey\": \"OuterStructure\", \"ToType\": \"Struct\", \"Dropped\": false, \"Chidlren\": [{ \"FromPath\": \"inner\", \"ToKey\": \"inner\", \"ToType\": \"Double\", \"Dropped\": false, }] }@
mapping_children :: Lens.Lens' Mapping (Prelude.Maybe [Mapping])
mapping_children :: Lens' Mapping (Maybe [Mapping])
mapping_children = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Mapping' {Maybe [Mapping]
children :: Maybe [Mapping]
$sel:children:Mapping' :: Mapping -> Maybe [Mapping]
children} -> Maybe [Mapping]
children) (\s :: Mapping
s@Mapping' {} Maybe [Mapping]
a -> Mapping
s {$sel:children:Mapping' :: Maybe [Mapping]
children = Maybe [Mapping]
a} :: Mapping) 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

-- | If true, then the column is removed.
mapping_dropped :: Lens.Lens' Mapping (Prelude.Maybe Prelude.Bool)
mapping_dropped :: Lens' Mapping (Maybe Bool)
mapping_dropped = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Mapping' {Maybe Bool
dropped :: Maybe Bool
$sel:dropped:Mapping' :: Mapping -> Maybe Bool
dropped} -> Maybe Bool
dropped) (\s :: Mapping
s@Mapping' {} Maybe Bool
a -> Mapping
s {$sel:dropped:Mapping' :: Maybe Bool
dropped = Maybe Bool
a} :: Mapping)

-- | The table or column to be modified.
mapping_fromPath :: Lens.Lens' Mapping (Prelude.Maybe [Prelude.Text])
mapping_fromPath :: Lens' Mapping (Maybe [Text])
mapping_fromPath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Mapping' {Maybe [Text]
fromPath :: Maybe [Text]
$sel:fromPath:Mapping' :: Mapping -> Maybe [Text]
fromPath} -> Maybe [Text]
fromPath) (\s :: Mapping
s@Mapping' {} Maybe [Text]
a -> Mapping
s {$sel:fromPath:Mapping' :: Maybe [Text]
fromPath = Maybe [Text]
a} :: Mapping) 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 type of the data to be modified.
mapping_fromType :: Lens.Lens' Mapping (Prelude.Maybe Prelude.Text)
mapping_fromType :: Lens' Mapping (Maybe Text)
mapping_fromType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Mapping' {Maybe Text
fromType :: Maybe Text
$sel:fromType:Mapping' :: Mapping -> Maybe Text
fromType} -> Maybe Text
fromType) (\s :: Mapping
s@Mapping' {} Maybe Text
a -> Mapping
s {$sel:fromType:Mapping' :: Maybe Text
fromType = Maybe Text
a} :: Mapping)

-- | After the apply mapping, what the name of the column should be. Can be
-- the same as @FromPath@.
mapping_toKey :: Lens.Lens' Mapping (Prelude.Maybe Prelude.Text)
mapping_toKey :: Lens' Mapping (Maybe Text)
mapping_toKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Mapping' {Maybe Text
toKey :: Maybe Text
$sel:toKey:Mapping' :: Mapping -> Maybe Text
toKey} -> Maybe Text
toKey) (\s :: Mapping
s@Mapping' {} Maybe Text
a -> Mapping
s {$sel:toKey:Mapping' :: Maybe Text
toKey = Maybe Text
a} :: Mapping)

-- | The data type that the data is to be modified to.
mapping_toType :: Lens.Lens' Mapping (Prelude.Maybe Prelude.Text)
mapping_toType :: Lens' Mapping (Maybe Text)
mapping_toType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Mapping' {Maybe Text
toType :: Maybe Text
$sel:toType:Mapping' :: Mapping -> Maybe Text
toType} -> Maybe Text
toType) (\s :: Mapping
s@Mapping' {} Maybe Text
a -> Mapping
s {$sel:toType:Mapping' :: Maybe Text
toType = Maybe Text
a} :: Mapping)

instance Data.FromJSON Mapping where
  parseJSON :: Value -> Parser Mapping
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Mapping"
      ( \Object
x ->
          Maybe [Mapping]
-> Maybe Bool
-> Maybe [Text]
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Mapping
Mapping'
            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
"Children" 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
"Dropped")
            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
"FromPath" 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
"FromType")
            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
"ToKey")
            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
"ToType")
      )

instance Prelude.Hashable Mapping where
  hashWithSalt :: Int -> Mapping -> Int
hashWithSalt Int
_salt Mapping' {Maybe Bool
Maybe [Text]
Maybe [Mapping]
Maybe Text
toType :: Maybe Text
toKey :: Maybe Text
fromType :: Maybe Text
fromPath :: Maybe [Text]
dropped :: Maybe Bool
children :: Maybe [Mapping]
$sel:toType:Mapping' :: Mapping -> Maybe Text
$sel:toKey:Mapping' :: Mapping -> Maybe Text
$sel:fromType:Mapping' :: Mapping -> Maybe Text
$sel:fromPath:Mapping' :: Mapping -> Maybe [Text]
$sel:dropped:Mapping' :: Mapping -> Maybe Bool
$sel:children:Mapping' :: Mapping -> Maybe [Mapping]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Mapping]
children
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
dropped
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
fromPath
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
fromType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
toKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
toType

instance Prelude.NFData Mapping where
  rnf :: Mapping -> ()
rnf Mapping' {Maybe Bool
Maybe [Text]
Maybe [Mapping]
Maybe Text
toType :: Maybe Text
toKey :: Maybe Text
fromType :: Maybe Text
fromPath :: Maybe [Text]
dropped :: Maybe Bool
children :: Maybe [Mapping]
$sel:toType:Mapping' :: Mapping -> Maybe Text
$sel:toKey:Mapping' :: Mapping -> Maybe Text
$sel:fromType:Mapping' :: Mapping -> Maybe Text
$sel:fromPath:Mapping' :: Mapping -> Maybe [Text]
$sel:dropped:Mapping' :: Mapping -> Maybe Bool
$sel:children:Mapping' :: Mapping -> Maybe [Mapping]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Mapping]
children
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
dropped
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
fromPath
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
fromType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
toKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
toType

instance Data.ToJSON Mapping where
  toJSON :: Mapping -> Value
toJSON Mapping' {Maybe Bool
Maybe [Text]
Maybe [Mapping]
Maybe Text
toType :: Maybe Text
toKey :: Maybe Text
fromType :: Maybe Text
fromPath :: Maybe [Text]
dropped :: Maybe Bool
children :: Maybe [Mapping]
$sel:toType:Mapping' :: Mapping -> Maybe Text
$sel:toKey:Mapping' :: Mapping -> Maybe Text
$sel:fromType:Mapping' :: Mapping -> Maybe Text
$sel:fromPath:Mapping' :: Mapping -> Maybe [Text]
$sel:dropped:Mapping' :: Mapping -> Maybe Bool
$sel:children:Mapping' :: Mapping -> Maybe [Mapping]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Children" 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 [Mapping]
children,
            (Key
"Dropped" 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 Bool
dropped,
            (Key
"FromPath" 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 [Text]
fromPath,
            (Key
"FromType" 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 Text
fromType,
            (Key
"ToKey" 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 Text
toKey,
            (Key
"ToType" 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 Text
toType
          ]
      )