{-# 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.ECS.Types.KeyValuePair
-- 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.ECS.Types.KeyValuePair 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 object.
--
-- /See:/ 'newKeyValuePair' smart constructor.
data KeyValuePair = KeyValuePair'
  { -- | 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,
    -- | 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
  }
  deriving (KeyValuePair -> KeyValuePair -> Bool
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]
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
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. 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:
--
-- 'name', 'keyValuePair_name' - The name of the key-value pair. For environment variables, this is the
-- name of the environment variable.
--
-- 'value', 'keyValuePair_value' - The value of the key-value pair. For environment variables, this is the
-- value of the environment variable.
newKeyValuePair ::
  KeyValuePair
newKeyValuePair :: KeyValuePair
newKeyValuePair =
  KeyValuePair'
    { $sel:name:KeyValuePair' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:value:KeyValuePair' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' KeyValuePair (Maybe Text)
keyValuePair_name = 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)

-- | 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 :: Lens' KeyValuePair (Maybe Text)
keyValuePair_value = 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)

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

instance Prelude.Hashable KeyValuePair where
  hashWithSalt :: Int -> KeyValuePair -> Int
hashWithSalt Int
_salt KeyValuePair' {Maybe Text
value :: Maybe Text
name :: Maybe Text
$sel:value:KeyValuePair' :: KeyValuePair -> Maybe Text
$sel:name:KeyValuePair' :: KeyValuePair -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData KeyValuePair where
  rnf :: KeyValuePair -> ()
rnf KeyValuePair' {Maybe Text
value :: Maybe Text
name :: Maybe Text
$sel:value:KeyValuePair' :: KeyValuePair -> Maybe Text
$sel:name:KeyValuePair' :: KeyValuePair -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value

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