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

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types.CodeGenNodeArg
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a node in a directed acyclic graph (DAG)
--
-- /See:/ 'newCodeGenNode' smart constructor.
data CodeGenNode = CodeGenNode'
  { -- | The line number of the node.
    CodeGenNode -> Maybe Int
lineNumber :: Prelude.Maybe Prelude.Int,
    -- | A node identifier that is unique within the node\'s graph.
    CodeGenNode -> Text
id :: Prelude.Text,
    -- | The type of node that this is.
    CodeGenNode -> Text
nodeType :: Prelude.Text,
    -- | Properties of the node, in the form of name-value pairs.
    CodeGenNode -> [CodeGenNodeArg]
args :: [CodeGenNodeArg]
  }
  deriving (CodeGenNode -> CodeGenNode -> Bool
(CodeGenNode -> CodeGenNode -> Bool)
-> (CodeGenNode -> CodeGenNode -> Bool) -> Eq CodeGenNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CodeGenNode -> CodeGenNode -> Bool
$c/= :: CodeGenNode -> CodeGenNode -> Bool
== :: CodeGenNode -> CodeGenNode -> Bool
$c== :: CodeGenNode -> CodeGenNode -> Bool
Prelude.Eq, ReadPrec [CodeGenNode]
ReadPrec CodeGenNode
Int -> ReadS CodeGenNode
ReadS [CodeGenNode]
(Int -> ReadS CodeGenNode)
-> ReadS [CodeGenNode]
-> ReadPrec CodeGenNode
-> ReadPrec [CodeGenNode]
-> Read CodeGenNode
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CodeGenNode]
$creadListPrec :: ReadPrec [CodeGenNode]
readPrec :: ReadPrec CodeGenNode
$creadPrec :: ReadPrec CodeGenNode
readList :: ReadS [CodeGenNode]
$creadList :: ReadS [CodeGenNode]
readsPrec :: Int -> ReadS CodeGenNode
$creadsPrec :: Int -> ReadS CodeGenNode
Prelude.Read, Int -> CodeGenNode -> ShowS
[CodeGenNode] -> ShowS
CodeGenNode -> String
(Int -> CodeGenNode -> ShowS)
-> (CodeGenNode -> String)
-> ([CodeGenNode] -> ShowS)
-> Show CodeGenNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CodeGenNode] -> ShowS
$cshowList :: [CodeGenNode] -> ShowS
show :: CodeGenNode -> String
$cshow :: CodeGenNode -> String
showsPrec :: Int -> CodeGenNode -> ShowS
$cshowsPrec :: Int -> CodeGenNode -> ShowS
Prelude.Show, (forall x. CodeGenNode -> Rep CodeGenNode x)
-> (forall x. Rep CodeGenNode x -> CodeGenNode)
-> Generic CodeGenNode
forall x. Rep CodeGenNode x -> CodeGenNode
forall x. CodeGenNode -> Rep CodeGenNode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CodeGenNode x -> CodeGenNode
$cfrom :: forall x. CodeGenNode -> Rep CodeGenNode x
Prelude.Generic)

-- |
-- Create a value of 'CodeGenNode' 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:
--
-- 'lineNumber', 'codeGenNode_lineNumber' - The line number of the node.
--
-- 'id', 'codeGenNode_id' - A node identifier that is unique within the node\'s graph.
--
-- 'nodeType', 'codeGenNode_nodeType' - The type of node that this is.
--
-- 'args', 'codeGenNode_args' - Properties of the node, in the form of name-value pairs.
newCodeGenNode ::
  -- | 'id'
  Prelude.Text ->
  -- | 'nodeType'
  Prelude.Text ->
  CodeGenNode
newCodeGenNode :: Text -> Text -> CodeGenNode
newCodeGenNode Text
pId_ Text
pNodeType_ =
  CodeGenNode' :: Maybe Int -> Text -> Text -> [CodeGenNodeArg] -> CodeGenNode
CodeGenNode'
    { $sel:lineNumber:CodeGenNode' :: Maybe Int
lineNumber = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:id:CodeGenNode' :: Text
id = Text
pId_,
      $sel:nodeType:CodeGenNode' :: Text
nodeType = Text
pNodeType_,
      $sel:args:CodeGenNode' :: [CodeGenNodeArg]
args = [CodeGenNodeArg]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The line number of the node.
codeGenNode_lineNumber :: Lens.Lens' CodeGenNode (Prelude.Maybe Prelude.Int)
codeGenNode_lineNumber :: (Maybe Int -> f (Maybe Int)) -> CodeGenNode -> f CodeGenNode
codeGenNode_lineNumber = (CodeGenNode -> Maybe Int)
-> (CodeGenNode -> Maybe Int -> CodeGenNode)
-> Lens CodeGenNode CodeGenNode (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeGenNode' {Maybe Int
lineNumber :: Maybe Int
$sel:lineNumber:CodeGenNode' :: CodeGenNode -> Maybe Int
lineNumber} -> Maybe Int
lineNumber) (\s :: CodeGenNode
s@CodeGenNode' {} Maybe Int
a -> CodeGenNode
s {$sel:lineNumber:CodeGenNode' :: Maybe Int
lineNumber = Maybe Int
a} :: CodeGenNode)

-- | A node identifier that is unique within the node\'s graph.
codeGenNode_id :: Lens.Lens' CodeGenNode Prelude.Text
codeGenNode_id :: (Text -> f Text) -> CodeGenNode -> f CodeGenNode
codeGenNode_id = (CodeGenNode -> Text)
-> (CodeGenNode -> Text -> CodeGenNode)
-> Lens CodeGenNode CodeGenNode Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeGenNode' {Text
id :: Text
$sel:id:CodeGenNode' :: CodeGenNode -> Text
id} -> Text
id) (\s :: CodeGenNode
s@CodeGenNode' {} Text
a -> CodeGenNode
s {$sel:id:CodeGenNode' :: Text
id = Text
a} :: CodeGenNode)

-- | The type of node that this is.
codeGenNode_nodeType :: Lens.Lens' CodeGenNode Prelude.Text
codeGenNode_nodeType :: (Text -> f Text) -> CodeGenNode -> f CodeGenNode
codeGenNode_nodeType = (CodeGenNode -> Text)
-> (CodeGenNode -> Text -> CodeGenNode)
-> Lens CodeGenNode CodeGenNode Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeGenNode' {Text
nodeType :: Text
$sel:nodeType:CodeGenNode' :: CodeGenNode -> Text
nodeType} -> Text
nodeType) (\s :: CodeGenNode
s@CodeGenNode' {} Text
a -> CodeGenNode
s {$sel:nodeType:CodeGenNode' :: Text
nodeType = Text
a} :: CodeGenNode)

-- | Properties of the node, in the form of name-value pairs.
codeGenNode_args :: Lens.Lens' CodeGenNode [CodeGenNodeArg]
codeGenNode_args :: ([CodeGenNodeArg] -> f [CodeGenNodeArg])
-> CodeGenNode -> f CodeGenNode
codeGenNode_args = (CodeGenNode -> [CodeGenNodeArg])
-> (CodeGenNode -> [CodeGenNodeArg] -> CodeGenNode)
-> Lens CodeGenNode CodeGenNode [CodeGenNodeArg] [CodeGenNodeArg]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeGenNode' {[CodeGenNodeArg]
args :: [CodeGenNodeArg]
$sel:args:CodeGenNode' :: CodeGenNode -> [CodeGenNodeArg]
args} -> [CodeGenNodeArg]
args) (\s :: CodeGenNode
s@CodeGenNode' {} [CodeGenNodeArg]
a -> CodeGenNode
s {$sel:args:CodeGenNode' :: [CodeGenNodeArg]
args = [CodeGenNodeArg]
a} :: CodeGenNode) (([CodeGenNodeArg] -> f [CodeGenNodeArg])
 -> CodeGenNode -> f CodeGenNode)
-> (([CodeGenNodeArg] -> f [CodeGenNodeArg])
    -> [CodeGenNodeArg] -> f [CodeGenNodeArg])
-> ([CodeGenNodeArg] -> f [CodeGenNodeArg])
-> CodeGenNode
-> f CodeGenNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([CodeGenNodeArg] -> f [CodeGenNodeArg])
-> [CodeGenNodeArg] -> f [CodeGenNodeArg]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON CodeGenNode where
  parseJSON :: Value -> Parser CodeGenNode
parseJSON =
    String
-> (Object -> Parser CodeGenNode) -> Value -> Parser CodeGenNode
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CodeGenNode"
      ( \Object
x ->
          Maybe Int -> Text -> Text -> [CodeGenNodeArg] -> CodeGenNode
CodeGenNode'
            (Maybe Int -> Text -> Text -> [CodeGenNodeArg] -> CodeGenNode)
-> Parser (Maybe Int)
-> Parser (Text -> Text -> [CodeGenNodeArg] -> CodeGenNode)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LineNumber")
            Parser (Text -> Text -> [CodeGenNodeArg] -> CodeGenNode)
-> Parser Text -> Parser (Text -> [CodeGenNodeArg] -> CodeGenNode)
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
"Id")
            Parser (Text -> [CodeGenNodeArg] -> CodeGenNode)
-> Parser Text -> Parser ([CodeGenNodeArg] -> CodeGenNode)
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
"NodeType")
            Parser ([CodeGenNodeArg] -> CodeGenNode)
-> Parser [CodeGenNodeArg] -> Parser CodeGenNode
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [CodeGenNodeArg])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Args" Parser (Maybe [CodeGenNodeArg])
-> [CodeGenNodeArg] -> Parser [CodeGenNodeArg]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [CodeGenNodeArg]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable CodeGenNode

instance Prelude.NFData CodeGenNode

instance Core.ToJSON CodeGenNode where
  toJSON :: CodeGenNode -> Value
toJSON CodeGenNode' {[CodeGenNodeArg]
Maybe Int
Text
args :: [CodeGenNodeArg]
nodeType :: Text
id :: Text
lineNumber :: Maybe Int
$sel:args:CodeGenNode' :: CodeGenNode -> [CodeGenNodeArg]
$sel:nodeType:CodeGenNode' :: CodeGenNode -> Text
$sel:id:CodeGenNode' :: CodeGenNode -> Text
$sel:lineNumber:CodeGenNode' :: CodeGenNode -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"LineNumber" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
lineNumber,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"NodeType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
nodeType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Args" Text -> [CodeGenNodeArg] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [CodeGenNodeArg]
args)
          ]
      )