{-# 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.EMR.Types.KeyValue
-- 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.EMR.Types.KeyValue where

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

-- | A key-value pair.
--
-- /See:/ 'newKeyValue' smart constructor.
data KeyValue = KeyValue'
  { -- | The value part of the identified key.
    KeyValue -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier of a key-value pair.
    KeyValue -> Maybe Text
key :: Prelude.Maybe Prelude.Text
  }
  deriving (KeyValue -> KeyValue -> Bool
(KeyValue -> KeyValue -> Bool)
-> (KeyValue -> KeyValue -> Bool) -> Eq KeyValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeyValue -> KeyValue -> Bool
$c/= :: KeyValue -> KeyValue -> Bool
== :: KeyValue -> KeyValue -> Bool
$c== :: KeyValue -> KeyValue -> Bool
Prelude.Eq, ReadPrec [KeyValue]
ReadPrec KeyValue
Int -> ReadS KeyValue
ReadS [KeyValue]
(Int -> ReadS KeyValue)
-> ReadS [KeyValue]
-> ReadPrec KeyValue
-> ReadPrec [KeyValue]
-> Read KeyValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KeyValue]
$creadListPrec :: ReadPrec [KeyValue]
readPrec :: ReadPrec KeyValue
$creadPrec :: ReadPrec KeyValue
readList :: ReadS [KeyValue]
$creadList :: ReadS [KeyValue]
readsPrec :: Int -> ReadS KeyValue
$creadsPrec :: Int -> ReadS KeyValue
Prelude.Read, Int -> KeyValue -> ShowS
[KeyValue] -> ShowS
KeyValue -> String
(Int -> KeyValue -> ShowS)
-> (KeyValue -> String) -> ([KeyValue] -> ShowS) -> Show KeyValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeyValue] -> ShowS
$cshowList :: [KeyValue] -> ShowS
show :: KeyValue -> String
$cshow :: KeyValue -> String
showsPrec :: Int -> KeyValue -> ShowS
$cshowsPrec :: Int -> KeyValue -> ShowS
Prelude.Show, (forall x. KeyValue -> Rep KeyValue x)
-> (forall x. Rep KeyValue x -> KeyValue) -> Generic KeyValue
forall x. Rep KeyValue x -> KeyValue
forall x. KeyValue -> Rep KeyValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KeyValue x -> KeyValue
$cfrom :: forall x. KeyValue -> Rep KeyValue x
Prelude.Generic)

-- |
-- Create a value of 'KeyValue' 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', 'keyValue_value' - The value part of the identified key.
--
-- 'key', 'keyValue_key' - The unique identifier of a key-value pair.
newKeyValue ::
  KeyValue
newKeyValue :: KeyValue
newKeyValue =
  KeyValue' :: Maybe Text -> Maybe Text -> KeyValue
KeyValue'
    { $sel:value:KeyValue' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:key:KeyValue' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The value part of the identified key.
keyValue_value :: Lens.Lens' KeyValue (Prelude.Maybe Prelude.Text)
keyValue_value :: (Maybe Text -> f (Maybe Text)) -> KeyValue -> f KeyValue
keyValue_value = (KeyValue -> Maybe Text)
-> (KeyValue -> Maybe Text -> KeyValue)
-> Lens KeyValue KeyValue (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyValue' {Maybe Text
value :: Maybe Text
$sel:value:KeyValue' :: KeyValue -> Maybe Text
value} -> Maybe Text
value) (\s :: KeyValue
s@KeyValue' {} Maybe Text
a -> KeyValue
s {$sel:value:KeyValue' :: Maybe Text
value = Maybe Text
a} :: KeyValue)

-- | The unique identifier of a key-value pair.
keyValue_key :: Lens.Lens' KeyValue (Prelude.Maybe Prelude.Text)
keyValue_key :: (Maybe Text -> f (Maybe Text)) -> KeyValue -> f KeyValue
keyValue_key = (KeyValue -> Maybe Text)
-> (KeyValue -> Maybe Text -> KeyValue)
-> Lens KeyValue KeyValue (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyValue' {Maybe Text
key :: Maybe Text
$sel:key:KeyValue' :: KeyValue -> Maybe Text
key} -> Maybe Text
key) (\s :: KeyValue
s@KeyValue' {} Maybe Text
a -> KeyValue
s {$sel:key:KeyValue' :: Maybe Text
key = Maybe Text
a} :: KeyValue)

instance Prelude.Hashable KeyValue

instance Prelude.NFData KeyValue

instance Core.ToJSON KeyValue where
  toJSON :: KeyValue -> Value
toJSON KeyValue' {Maybe Text
key :: Maybe Text
value :: Maybe Text
$sel:key:KeyValue' :: KeyValue -> Maybe Text
$sel:value:KeyValue' :: KeyValue -> 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
"Key" 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
key
          ]
      )