{-# 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.DirectoryService.Types.Attribute
-- 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.DirectoryService.Types.Attribute where

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

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

-- |
-- Create a value of 'Attribute' 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:
--
-- 'name', 'attribute_name' - The name of the attribute.
--
-- 'value', 'attribute_value' - The value of the attribute.
newAttribute ::
  Attribute
newAttribute :: Attribute
newAttribute =
  Attribute'
    { $sel:name:Attribute' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:value:Attribute' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the attribute.
attribute_name :: Lens.Lens' Attribute (Prelude.Maybe Prelude.Text)
attribute_name :: Lens' Attribute (Maybe Text)
attribute_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Maybe Text
name :: Maybe Text
$sel:name:Attribute' :: Attribute -> Maybe Text
name} -> Maybe Text
name) (\s :: Attribute
s@Attribute' {} Maybe Text
a -> Attribute
s {$sel:name:Attribute' :: Maybe Text
name = Maybe Text
a} :: Attribute)

-- | The value of the attribute.
attribute_value :: Lens.Lens' Attribute (Prelude.Maybe Prelude.Text)
attribute_value :: Lens' Attribute (Maybe Text)
attribute_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Maybe Text
value :: Maybe Text
$sel:value:Attribute' :: Attribute -> Maybe Text
value} -> Maybe Text
value) (\s :: Attribute
s@Attribute' {} Maybe Text
a -> Attribute
s {$sel:value:Attribute' :: Maybe Text
value = Maybe Text
a} :: Attribute)

instance Data.FromJSON Attribute where
  parseJSON :: Value -> Parser Attribute
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Attribute"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Attribute
Attribute'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Value")
      )

instance Prelude.Hashable Attribute where
  hashWithSalt :: Int -> Attribute -> Int
hashWithSalt Int
_salt Attribute' {Maybe Text
value :: Maybe Text
name :: Maybe Text
$sel:value:Attribute' :: Attribute -> Maybe Text
$sel:name:Attribute' :: Attribute -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

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

instance Data.ToJSON Attribute where
  toJSON :: Attribute -> Value
toJSON Attribute' {Maybe Text
value :: Maybe Text
name :: Maybe Text
$sel:value:Attribute' :: Attribute -> Maybe Text
$sel:name:Attribute' :: Attribute -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value
          ]
      )