{-# 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.CloudDirectory.Types.AttributeKeyAndValue
-- 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.CloudDirectory.Types.AttributeKeyAndValue where

import Amazonka.CloudDirectory.Types.AttributeKey
import Amazonka.CloudDirectory.Types.TypedAttributeValue
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The combination of an attribute key and an attribute value.
--
-- /See:/ 'newAttributeKeyAndValue' smart constructor.
data AttributeKeyAndValue = AttributeKeyAndValue'
  { -- | The key of the attribute.
    AttributeKeyAndValue -> AttributeKey
key :: AttributeKey,
    -- | The value of the attribute.
    AttributeKeyAndValue -> TypedAttributeValue
value :: TypedAttributeValue
  }
  deriving (AttributeKeyAndValue -> AttributeKeyAndValue -> Bool
(AttributeKeyAndValue -> AttributeKeyAndValue -> Bool)
-> (AttributeKeyAndValue -> AttributeKeyAndValue -> Bool)
-> Eq AttributeKeyAndValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeKeyAndValue -> AttributeKeyAndValue -> Bool
$c/= :: AttributeKeyAndValue -> AttributeKeyAndValue -> Bool
== :: AttributeKeyAndValue -> AttributeKeyAndValue -> Bool
$c== :: AttributeKeyAndValue -> AttributeKeyAndValue -> Bool
Prelude.Eq, ReadPrec [AttributeKeyAndValue]
ReadPrec AttributeKeyAndValue
Int -> ReadS AttributeKeyAndValue
ReadS [AttributeKeyAndValue]
(Int -> ReadS AttributeKeyAndValue)
-> ReadS [AttributeKeyAndValue]
-> ReadPrec AttributeKeyAndValue
-> ReadPrec [AttributeKeyAndValue]
-> Read AttributeKeyAndValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttributeKeyAndValue]
$creadListPrec :: ReadPrec [AttributeKeyAndValue]
readPrec :: ReadPrec AttributeKeyAndValue
$creadPrec :: ReadPrec AttributeKeyAndValue
readList :: ReadS [AttributeKeyAndValue]
$creadList :: ReadS [AttributeKeyAndValue]
readsPrec :: Int -> ReadS AttributeKeyAndValue
$creadsPrec :: Int -> ReadS AttributeKeyAndValue
Prelude.Read, Int -> AttributeKeyAndValue -> ShowS
[AttributeKeyAndValue] -> ShowS
AttributeKeyAndValue -> String
(Int -> AttributeKeyAndValue -> ShowS)
-> (AttributeKeyAndValue -> String)
-> ([AttributeKeyAndValue] -> ShowS)
-> Show AttributeKeyAndValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttributeKeyAndValue] -> ShowS
$cshowList :: [AttributeKeyAndValue] -> ShowS
show :: AttributeKeyAndValue -> String
$cshow :: AttributeKeyAndValue -> String
showsPrec :: Int -> AttributeKeyAndValue -> ShowS
$cshowsPrec :: Int -> AttributeKeyAndValue -> ShowS
Prelude.Show, (forall x. AttributeKeyAndValue -> Rep AttributeKeyAndValue x)
-> (forall x. Rep AttributeKeyAndValue x -> AttributeKeyAndValue)
-> Generic AttributeKeyAndValue
forall x. Rep AttributeKeyAndValue x -> AttributeKeyAndValue
forall x. AttributeKeyAndValue -> Rep AttributeKeyAndValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeKeyAndValue x -> AttributeKeyAndValue
$cfrom :: forall x. AttributeKeyAndValue -> Rep AttributeKeyAndValue x
Prelude.Generic)

-- |
-- Create a value of 'AttributeKeyAndValue' 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:
--
-- 'key', 'attributeKeyAndValue_key' - The key of the attribute.
--
-- 'value', 'attributeKeyAndValue_value' - The value of the attribute.
newAttributeKeyAndValue ::
  -- | 'key'
  AttributeKey ->
  -- | 'value'
  TypedAttributeValue ->
  AttributeKeyAndValue
newAttributeKeyAndValue :: AttributeKey -> TypedAttributeValue -> AttributeKeyAndValue
newAttributeKeyAndValue AttributeKey
pKey_ TypedAttributeValue
pValue_ =
  AttributeKeyAndValue' :: AttributeKey -> TypedAttributeValue -> AttributeKeyAndValue
AttributeKeyAndValue' {$sel:key:AttributeKeyAndValue' :: AttributeKey
key = AttributeKey
pKey_, $sel:value:AttributeKeyAndValue' :: TypedAttributeValue
value = TypedAttributeValue
pValue_}

-- | The key of the attribute.
attributeKeyAndValue_key :: Lens.Lens' AttributeKeyAndValue AttributeKey
attributeKeyAndValue_key :: (AttributeKey -> f AttributeKey)
-> AttributeKeyAndValue -> f AttributeKeyAndValue
attributeKeyAndValue_key = (AttributeKeyAndValue -> AttributeKey)
-> (AttributeKeyAndValue -> AttributeKey -> AttributeKeyAndValue)
-> Lens
     AttributeKeyAndValue AttributeKeyAndValue AttributeKey AttributeKey
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeKeyAndValue' {AttributeKey
key :: AttributeKey
$sel:key:AttributeKeyAndValue' :: AttributeKeyAndValue -> AttributeKey
key} -> AttributeKey
key) (\s :: AttributeKeyAndValue
s@AttributeKeyAndValue' {} AttributeKey
a -> AttributeKeyAndValue
s {$sel:key:AttributeKeyAndValue' :: AttributeKey
key = AttributeKey
a} :: AttributeKeyAndValue)

-- | The value of the attribute.
attributeKeyAndValue_value :: Lens.Lens' AttributeKeyAndValue TypedAttributeValue
attributeKeyAndValue_value :: (TypedAttributeValue -> f TypedAttributeValue)
-> AttributeKeyAndValue -> f AttributeKeyAndValue
attributeKeyAndValue_value = (AttributeKeyAndValue -> TypedAttributeValue)
-> (AttributeKeyAndValue
    -> TypedAttributeValue -> AttributeKeyAndValue)
-> Lens
     AttributeKeyAndValue
     AttributeKeyAndValue
     TypedAttributeValue
     TypedAttributeValue
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeKeyAndValue' {TypedAttributeValue
value :: TypedAttributeValue
$sel:value:AttributeKeyAndValue' :: AttributeKeyAndValue -> TypedAttributeValue
value} -> TypedAttributeValue
value) (\s :: AttributeKeyAndValue
s@AttributeKeyAndValue' {} TypedAttributeValue
a -> AttributeKeyAndValue
s {$sel:value:AttributeKeyAndValue' :: TypedAttributeValue
value = TypedAttributeValue
a} :: AttributeKeyAndValue)

instance Core.FromJSON AttributeKeyAndValue where
  parseJSON :: Value -> Parser AttributeKeyAndValue
parseJSON =
    String
-> (Object -> Parser AttributeKeyAndValue)
-> Value
-> Parser AttributeKeyAndValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AttributeKeyAndValue"
      ( \Object
x ->
          AttributeKey -> TypedAttributeValue -> AttributeKeyAndValue
AttributeKeyAndValue'
            (AttributeKey -> TypedAttributeValue -> AttributeKeyAndValue)
-> Parser AttributeKey
-> Parser (TypedAttributeValue -> AttributeKeyAndValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser AttributeKey
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Key") Parser (TypedAttributeValue -> AttributeKeyAndValue)
-> Parser TypedAttributeValue -> Parser AttributeKeyAndValue
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser TypedAttributeValue
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Value")
      )

instance Prelude.Hashable AttributeKeyAndValue

instance Prelude.NFData AttributeKeyAndValue

instance Core.ToJSON AttributeKeyAndValue where
  toJSON :: AttributeKeyAndValue -> Value
toJSON AttributeKeyAndValue' {AttributeKey
TypedAttributeValue
value :: TypedAttributeValue
key :: AttributeKey
$sel:value:AttributeKeyAndValue' :: AttributeKeyAndValue -> TypedAttributeValue
$sel:key:AttributeKeyAndValue' :: AttributeKeyAndValue -> AttributeKey
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Key" Text -> AttributeKey -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AttributeKey
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> TypedAttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TypedAttributeValue
value)
          ]
      )