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

import Amazonka.CloudDirectory.Types.TypedAttributeValue
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(AttributeNameAndValue -> AttributeNameAndValue -> Bool)
-> (AttributeNameAndValue -> AttributeNameAndValue -> Bool)
-> Eq AttributeNameAndValue
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]
(Int -> ReadS AttributeNameAndValue)
-> ReadS [AttributeNameAndValue]
-> ReadPrec AttributeNameAndValue
-> ReadPrec [AttributeNameAndValue]
-> Read 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
(Int -> AttributeNameAndValue -> ShowS)
-> (AttributeNameAndValue -> String)
-> ([AttributeNameAndValue] -> ShowS)
-> Show AttributeNameAndValue
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. AttributeNameAndValue -> Rep AttributeNameAndValue x)
-> (forall x. Rep AttributeNameAndValue x -> AttributeNameAndValue)
-> Generic AttributeNameAndValue
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' :: Text -> TypedAttributeValue -> AttributeNameAndValue
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 :: (Text -> f Text)
-> AttributeNameAndValue -> f AttributeNameAndValue
attributeNameAndValue_attributeName = (AttributeNameAndValue -> Text)
-> (AttributeNameAndValue -> Text -> AttributeNameAndValue)
-> Lens AttributeNameAndValue AttributeNameAndValue Text Text
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 :: (TypedAttributeValue -> f TypedAttributeValue)
-> AttributeNameAndValue -> f AttributeNameAndValue
attributeNameAndValue_value = (AttributeNameAndValue -> TypedAttributeValue)
-> (AttributeNameAndValue
    -> TypedAttributeValue -> AttributeNameAndValue)
-> Lens
     AttributeNameAndValue
     AttributeNameAndValue
     TypedAttributeValue
     TypedAttributeValue
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 Core.FromJSON AttributeNameAndValue where
  parseJSON :: Value -> Parser AttributeNameAndValue
parseJSON =
    String
-> (Object -> Parser AttributeNameAndValue)
-> Value
-> Parser AttributeNameAndValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AttributeNameAndValue"
      ( \Object
x ->
          Text -> TypedAttributeValue -> AttributeNameAndValue
AttributeNameAndValue'
            (Text -> TypedAttributeValue -> AttributeNameAndValue)
-> Parser Text
-> Parser (TypedAttributeValue -> AttributeNameAndValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AttributeName")
            Parser (TypedAttributeValue -> AttributeNameAndValue)
-> Parser TypedAttributeValue -> Parser AttributeNameAndValue
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 AttributeNameAndValue

instance Prelude.NFData AttributeNameAndValue

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AttributeName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attributeName),
            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)
          ]
      )