{-# 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.AttributeNameAndValue
-- 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.AttributeNameAndValue where

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

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

-- |
-- Create a value of 'AttributeNameAndValue' 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:
--
-- 'attributeName', 'attributeNameAndValue_attributeName' - The attribute name of the typed link.
--
-- 'value', 'attributeNameAndValue_value' - The value for the typed link.
newAttributeNameAndValue ::
  -- | 'attributeName'
  Prelude.Text ->
  -- | 'value'
  TypedAttributeValue ->
  AttributeNameAndValue
newAttributeNameAndValue :: Text -> TypedAttributeValue -> AttributeNameAndValue
newAttributeNameAndValue Text
pAttributeName_ TypedAttributeValue
pValue_ =
  AttributeNameAndValue'
    { $sel:attributeName:AttributeNameAndValue' :: Text
attributeName =
        Text
pAttributeName_,
      $sel:value:AttributeNameAndValue' :: TypedAttributeValue
value = TypedAttributeValue
pValue_
    }

-- | The attribute name of the typed link.
attributeNameAndValue_attributeName :: Lens.Lens' AttributeNameAndValue Prelude.Text
attributeNameAndValue_attributeName :: Lens' AttributeNameAndValue Text
attributeNameAndValue_attributeName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeNameAndValue' {Text
attributeName :: Text
$sel:attributeName:AttributeNameAndValue' :: AttributeNameAndValue -> Text
attributeName} -> Text
attributeName) (\s :: AttributeNameAndValue
s@AttributeNameAndValue' {} Text
a -> AttributeNameAndValue
s {$sel:attributeName:AttributeNameAndValue' :: Text
attributeName = Text
a} :: AttributeNameAndValue)

-- | The value for the typed link.
attributeNameAndValue_value :: Lens.Lens' AttributeNameAndValue TypedAttributeValue
attributeNameAndValue_value :: Lens' AttributeNameAndValue TypedAttributeValue
attributeNameAndValue_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeNameAndValue' {TypedAttributeValue
value :: TypedAttributeValue
$sel:value:AttributeNameAndValue' :: AttributeNameAndValue -> TypedAttributeValue
value} -> TypedAttributeValue
value) (\s :: AttributeNameAndValue
s@AttributeNameAndValue' {} TypedAttributeValue
a -> AttributeNameAndValue
s {$sel:value:AttributeNameAndValue' :: TypedAttributeValue
value = TypedAttributeValue
a} :: AttributeNameAndValue)

instance Data.FromJSON AttributeNameAndValue where
  parseJSON :: Value -> Parser AttributeNameAndValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AttributeNameAndValue"
      ( \Object
x ->
          Text -> TypedAttributeValue -> AttributeNameAndValue
AttributeNameAndValue'
            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
"AttributeName")
            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 AttributeNameAndValue where
  hashWithSalt :: Int -> AttributeNameAndValue -> Int
hashWithSalt Int
_salt AttributeNameAndValue' {Text
TypedAttributeValue
value :: TypedAttributeValue
attributeName :: Text
$sel:value:AttributeNameAndValue' :: AttributeNameAndValue -> TypedAttributeValue
$sel:attributeName:AttributeNameAndValue' :: AttributeNameAndValue -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
attributeName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` TypedAttributeValue
value

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

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