{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$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 :: Lens' AttributeKeyAndValue AttributeKey
attributeKeyAndValue_key = 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 :: Lens' AttributeKeyAndValue TypedAttributeValue
attributeKeyAndValue_value = 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 Data.FromJSON AttributeKeyAndValue where
  parseJSON :: Value -> Parser AttributeKeyAndValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AttributeKeyAndValue"
      ( \Object
x ->
          AttributeKey -> TypedAttributeValue -> AttributeKeyAndValue
AttributeKeyAndValue'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Key")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Value")
      )

instance Prelude.Hashable AttributeKeyAndValue where
  hashWithSalt :: Int -> AttributeKeyAndValue -> Int
hashWithSalt Int
_salt AttributeKeyAndValue' {AttributeKey
TypedAttributeValue
value :: TypedAttributeValue
key :: AttributeKey
$sel:value:AttributeKeyAndValue' :: AttributeKeyAndValue -> TypedAttributeValue
$sel:key:AttributeKeyAndValue' :: AttributeKeyAndValue -> AttributeKey
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AttributeKey
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` TypedAttributeValue
value

instance Prelude.NFData AttributeKeyAndValue where
  rnf :: AttributeKeyAndValue -> ()
rnf AttributeKeyAndValue' {AttributeKey
TypedAttributeValue
value :: TypedAttributeValue
key :: AttributeKey
$sel:value:AttributeKeyAndValue' :: AttributeKeyAndValue -> TypedAttributeValue
$sel:key:AttributeKeyAndValue' :: AttributeKeyAndValue -> AttributeKey
..} =
    forall a. NFData a => a -> ()
Prelude.rnf AttributeKey
key seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf TypedAttributeValue
value

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AttributeKey
key),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= TypedAttributeValue
value)
          ]
      )