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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Field -> Field -> Bool) -> (Field -> Field -> Bool) -> Eq Field
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]
(Int -> ReadS Field)
-> ReadS [Field]
-> ReadPrec Field
-> ReadPrec [Field]
-> Read 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
(Int -> Field -> ShowS)
-> (Field -> String) -> ([Field] -> ShowS) -> Show Field
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. Field -> Rep Field x)
-> (forall x. Rep Field x -> Field) -> Generic Field
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' :: Maybe Text -> Maybe Text -> Text -> Field
Field'
    { $sel:refValue:Field' :: Maybe Text
refValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:Field' :: Maybe Text
stringValue = Maybe Text
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 :: (Maybe Text -> f (Maybe Text)) -> Field -> f Field
field_refValue = (Field -> Maybe Text)
-> (Field -> Maybe Text -> Field)
-> Lens Field Field (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> Field -> f Field
field_stringValue = (Field -> Maybe Text)
-> (Field -> Maybe Text -> Field)
-> Lens Field Field (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> Field -> f Field
field_key = (Field -> Text)
-> (Field -> Text -> Field) -> Lens Field Field Text Text
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 Core.FromJSON Field where
  parseJSON :: Value -> Parser Field
parseJSON =
    String -> (Object -> Parser Field) -> Value -> Parser Field
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Field"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> Field
Field'
            (Maybe Text -> Maybe Text -> Text -> Field)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Text -> Field)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"refValue")
            Parser (Maybe Text -> Text -> Field)
-> Parser (Maybe Text) -> Parser (Text -> Field)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"stringValue")
            Parser (Text -> Field) -> Parser Text -> Parser Field
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
"key")
      )

instance Prelude.Hashable Field

instance Prelude.NFData Field

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"refValue" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
refValue,
            (Text
"stringValue" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
stringValue,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key)
          ]
      )