{-# 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.Batch.Types.KeyValuePair
-- 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.Batch.Types.KeyValuePair where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A key-value pair object.
--
-- /See:/ 'newKeyValuePair' smart constructor.
data KeyValuePair = KeyValuePair'
  { -- | The value of the key-value pair. For environment variables, this is the
    -- value of the environment variable.
    KeyValuePair -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The name of the key-value pair. For environment variables, this is the
    -- name of the environment variable.
    KeyValuePair -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (KeyValuePair -> KeyValuePair -> Bool
(KeyValuePair -> KeyValuePair -> Bool)
-> (KeyValuePair -> KeyValuePair -> Bool) -> Eq KeyValuePair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeyValuePair -> KeyValuePair -> Bool
$c/= :: KeyValuePair -> KeyValuePair -> Bool
== :: KeyValuePair -> KeyValuePair -> Bool
$c== :: KeyValuePair -> KeyValuePair -> Bool
Prelude.Eq, ReadPrec [KeyValuePair]
ReadPrec KeyValuePair
Int -> ReadS KeyValuePair
ReadS [KeyValuePair]
(Int -> ReadS KeyValuePair)
-> ReadS [KeyValuePair]
-> ReadPrec KeyValuePair
-> ReadPrec [KeyValuePair]
-> Read KeyValuePair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KeyValuePair]
$creadListPrec :: ReadPrec [KeyValuePair]
readPrec :: ReadPrec KeyValuePair
$creadPrec :: ReadPrec KeyValuePair
readList :: ReadS [KeyValuePair]
$creadList :: ReadS [KeyValuePair]
readsPrec :: Int -> ReadS KeyValuePair
$creadsPrec :: Int -> ReadS KeyValuePair
Prelude.Read, Int -> KeyValuePair -> ShowS
[KeyValuePair] -> ShowS
KeyValuePair -> String
(Int -> KeyValuePair -> ShowS)
-> (KeyValuePair -> String)
-> ([KeyValuePair] -> ShowS)
-> Show KeyValuePair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeyValuePair] -> ShowS
$cshowList :: [KeyValuePair] -> ShowS
show :: KeyValuePair -> String
$cshow :: KeyValuePair -> String
showsPrec :: Int -> KeyValuePair -> ShowS
$cshowsPrec :: Int -> KeyValuePair -> ShowS
Prelude.Show, (forall x. KeyValuePair -> Rep KeyValuePair x)
-> (forall x. Rep KeyValuePair x -> KeyValuePair)
-> Generic KeyValuePair
forall x. Rep KeyValuePair x -> KeyValuePair
forall x. KeyValuePair -> Rep KeyValuePair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KeyValuePair x -> KeyValuePair
$cfrom :: forall x. KeyValuePair -> Rep KeyValuePair x
Prelude.Generic)

-- |
-- Create a value of 'KeyValuePair' 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:
--
-- 'value', 'keyValuePair_value' - The value of the key-value pair. For environment variables, this is the
-- value of the environment variable.
--
-- 'name', 'keyValuePair_name' - The name of the key-value pair. For environment variables, this is the
-- name of the environment variable.
newKeyValuePair ::
  KeyValuePair
newKeyValuePair :: KeyValuePair
newKeyValuePair =
  KeyValuePair' :: Maybe Text -> Maybe Text -> KeyValuePair
KeyValuePair'
    { $sel:value:KeyValuePair' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:KeyValuePair' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The value of the key-value pair. For environment variables, this is the
-- value of the environment variable.
keyValuePair_value :: Lens.Lens' KeyValuePair (Prelude.Maybe Prelude.Text)
keyValuePair_value :: (Maybe Text -> f (Maybe Text)) -> KeyValuePair -> f KeyValuePair
keyValuePair_value = (KeyValuePair -> Maybe Text)
-> (KeyValuePair -> Maybe Text -> KeyValuePair)
-> Lens KeyValuePair KeyValuePair (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyValuePair' {Maybe Text
value :: Maybe Text
$sel:value:KeyValuePair' :: KeyValuePair -> Maybe Text
value} -> Maybe Text
value) (\s :: KeyValuePair
s@KeyValuePair' {} Maybe Text
a -> KeyValuePair
s {$sel:value:KeyValuePair' :: Maybe Text
value = Maybe Text
a} :: KeyValuePair)

-- | The name of the key-value pair. For environment variables, this is the
-- name of the environment variable.
keyValuePair_name :: Lens.Lens' KeyValuePair (Prelude.Maybe Prelude.Text)
keyValuePair_name :: (Maybe Text -> f (Maybe Text)) -> KeyValuePair -> f KeyValuePair
keyValuePair_name = (KeyValuePair -> Maybe Text)
-> (KeyValuePair -> Maybe Text -> KeyValuePair)
-> Lens KeyValuePair KeyValuePair (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyValuePair' {Maybe Text
name :: Maybe Text
$sel:name:KeyValuePair' :: KeyValuePair -> Maybe Text
name} -> Maybe Text
name) (\s :: KeyValuePair
s@KeyValuePair' {} Maybe Text
a -> KeyValuePair
s {$sel:name:KeyValuePair' :: Maybe Text
name = Maybe Text
a} :: KeyValuePair)

instance Core.FromJSON KeyValuePair where
  parseJSON :: Value -> Parser KeyValuePair
parseJSON =
    String
-> (Object -> Parser KeyValuePair) -> Value -> Parser KeyValuePair
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KeyValuePair"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> KeyValuePair
KeyValuePair'
            (Maybe Text -> Maybe Text -> KeyValuePair)
-> Parser (Maybe Text) -> Parser (Maybe Text -> KeyValuePair)
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
"value") Parser (Maybe Text -> KeyValuePair)
-> Parser (Maybe Text) -> Parser KeyValuePair
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
"name")
      )

instance Prelude.Hashable KeyValuePair

instance Prelude.NFData KeyValuePair

instance Core.ToJSON KeyValuePair where
  toJSON :: KeyValuePair -> Value
toJSON KeyValuePair' {Maybe Text
name :: Maybe Text
value :: Maybe Text
$sel:name:KeyValuePair' :: KeyValuePair -> Maybe Text
$sel:value:KeyValuePair' :: KeyValuePair -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"value" 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
value,
            (Text
"name" 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
name
          ]
      )