{-# 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.DataPipeline.Types.Field
-- 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.DataPipeline.Types.Field 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

-- | A key-value pair that describes a property of a pipeline object. The
-- value is specified as either a string value (@StringValue@) or a
-- reference to another object (@RefValue@) but not as both.
--
-- /See:/ 'newField' smart constructor.
data Field = Field'
  { -- | The field value, expressed as the identifier of another object.
    Field -> Maybe Text
refValue :: Prelude.Maybe Prelude.Text,
    -- | The field value, expressed as a String.
    Field -> Maybe Text
stringValue :: Prelude.Maybe Prelude.Text,
    -- | The field identifier.
    Field -> Text
key :: Prelude.Text
  }
  deriving (Field -> Field -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Field -> Field -> Bool
$c/= :: Field -> Field -> Bool
== :: Field -> Field -> Bool
$c== :: Field -> Field -> Bool
Prelude.Eq, ReadPrec [Field]
ReadPrec Field
Int -> ReadS Field
ReadS [Field]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Field]
$creadListPrec :: ReadPrec [Field]
readPrec :: ReadPrec Field
$creadPrec :: ReadPrec Field
readList :: ReadS [Field]
$creadList :: ReadS [Field]
readsPrec :: Int -> ReadS Field
$creadsPrec :: Int -> ReadS Field
Prelude.Read, Int -> Field -> ShowS
[Field] -> ShowS
Field -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Field] -> ShowS
$cshowList :: [Field] -> ShowS
show :: Field -> String
$cshow :: Field -> String
showsPrec :: Int -> Field -> ShowS
$cshowsPrec :: Int -> Field -> ShowS
Prelude.Show, forall x. Rep Field x -> Field
forall x. Field -> Rep Field x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Field x -> Field
$cfrom :: forall x. Field -> Rep Field x
Prelude.Generic)

-- |
-- Create a value of 'Field' 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:
--
-- 'refValue', 'field_refValue' - The field value, expressed as the identifier of another object.
--
-- 'stringValue', 'field_stringValue' - The field value, expressed as a String.
--
-- 'key', 'field_key' - The field identifier.
newField ::
  -- | 'key'
  Prelude.Text ->
  Field
newField :: Text -> Field
newField Text
pKey_ =
  Field'
    { $sel:refValue:Field' :: Maybe Text
refValue = forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:Field' :: Maybe Text
stringValue = forall a. Maybe a
Prelude.Nothing,
      $sel:key:Field' :: Text
key = Text
pKey_
    }

-- | The field value, expressed as the identifier of another object.
field_refValue :: Lens.Lens' Field (Prelude.Maybe Prelude.Text)
field_refValue :: Lens' Field (Maybe Text)
field_refValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe Text
refValue :: Maybe Text
$sel:refValue:Field' :: Field -> Maybe Text
refValue} -> Maybe Text
refValue) (\s :: Field
s@Field' {} Maybe Text
a -> Field
s {$sel:refValue:Field' :: Maybe Text
refValue = Maybe Text
a} :: Field)

-- | The field value, expressed as a String.
field_stringValue :: Lens.Lens' Field (Prelude.Maybe Prelude.Text)
field_stringValue :: Lens' Field (Maybe Text)
field_stringValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe Text
stringValue :: Maybe Text
$sel:stringValue:Field' :: Field -> Maybe Text
stringValue} -> Maybe Text
stringValue) (\s :: Field
s@Field' {} Maybe Text
a -> Field
s {$sel:stringValue:Field' :: Maybe Text
stringValue = Maybe Text
a} :: Field)

-- | The field identifier.
field_key :: Lens.Lens' Field Prelude.Text
field_key :: Lens' Field Text
field_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Text
key :: Text
$sel:key:Field' :: Field -> Text
key} -> Text
key) (\s :: Field
s@Field' {} Text
a -> Field
s {$sel:key:Field' :: Text
key = Text
a} :: Field)

instance Data.FromJSON Field where
  parseJSON :: Value -> Parser Field
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Field"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> Field
Field'
            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
"refValue")
            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
"stringValue")
            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
"key")
      )

instance Prelude.Hashable Field where
  hashWithSalt :: Int -> Field -> Int
hashWithSalt Int
_salt Field' {Maybe Text
Text
key :: Text
stringValue :: Maybe Text
refValue :: Maybe Text
$sel:key:Field' :: Field -> Text
$sel:stringValue:Field' :: Field -> Maybe Text
$sel:refValue:Field' :: Field -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
refValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
stringValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key

instance Prelude.NFData Field where
  rnf :: Field -> ()
rnf Field' {Maybe Text
Text
key :: Text
stringValue :: Maybe Text
refValue :: Maybe Text
$sel:key:Field' :: Field -> Text
$sel:stringValue:Field' :: Field -> Maybe Text
$sel:refValue:Field' :: Field -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
refValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
stringValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
key

instance Data.ToJSON Field where
  toJSON :: Field -> Value
toJSON Field' {Maybe Text
Text
key :: Text
stringValue :: Maybe Text
refValue :: Maybe Text
$sel:key:Field' :: Field -> Text
$sel:stringValue:Field' :: Field -> Maybe Text
$sel:refValue:Field' :: Field -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"refValue" 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
refValue,
            (Key
"stringValue" 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
stringValue,
            forall a. a -> Maybe a
Prelude.Just (Key
"key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key)
          ]
      )