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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- |
--
-- /See:/ 'newAttribute' smart constructor.
data Attribute = Attribute'
  { Attribute -> Maybe Text
alternateValueEncoding :: Prelude.Maybe Prelude.Text,
    Attribute -> Maybe Text
alternateNameEncoding :: Prelude.Maybe Prelude.Text,
    -- | The name of the attribute.
    Attribute -> Text
name :: Prelude.Text,
    -- | The value of the attribute.
    Attribute -> Text
value :: Prelude.Text
  }
  deriving (Attribute -> Attribute -> Bool
(Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Bool) -> Eq Attribute
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]
(Int -> ReadS Attribute)
-> ReadS [Attribute]
-> ReadPrec Attribute
-> ReadPrec [Attribute]
-> Read 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
(Int -> Attribute -> ShowS)
-> (Attribute -> String)
-> ([Attribute] -> ShowS)
-> Show Attribute
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. Attribute -> Rep Attribute x)
-> (forall x. Rep Attribute x -> Attribute) -> Generic Attribute
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:
--
-- 'alternateValueEncoding', 'attribute_alternateValueEncoding' -
--
-- 'alternateNameEncoding', 'attribute_alternateNameEncoding' -
--
-- 'name', 'attribute_name' - The name of the attribute.
--
-- 'value', 'attribute_value' - The value of the attribute.
newAttribute ::
  -- | 'name'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  Attribute
newAttribute :: Text -> Text -> Attribute
newAttribute Text
pName_ Text
pValue_ =
  Attribute' :: Maybe Text -> Maybe Text -> Text -> Text -> Attribute
Attribute'
    { $sel:alternateValueEncoding:Attribute' :: Maybe Text
alternateValueEncoding =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:alternateNameEncoding:Attribute' :: Maybe Text
alternateNameEncoding = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Attribute' :: Text
name = Text
pName_,
      $sel:value:Attribute' :: Text
value = Text
pValue_
    }

-- |
attribute_alternateValueEncoding :: Lens.Lens' Attribute (Prelude.Maybe Prelude.Text)
attribute_alternateValueEncoding :: (Maybe Text -> f (Maybe Text)) -> Attribute -> f Attribute
attribute_alternateValueEncoding = (Attribute -> Maybe Text)
-> (Attribute -> Maybe Text -> Attribute)
-> Lens Attribute Attribute (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Maybe Text
alternateValueEncoding :: Maybe Text
$sel:alternateValueEncoding:Attribute' :: Attribute -> Maybe Text
alternateValueEncoding} -> Maybe Text
alternateValueEncoding) (\s :: Attribute
s@Attribute' {} Maybe Text
a -> Attribute
s {$sel:alternateValueEncoding:Attribute' :: Maybe Text
alternateValueEncoding = Maybe Text
a} :: Attribute)

-- |
attribute_alternateNameEncoding :: Lens.Lens' Attribute (Prelude.Maybe Prelude.Text)
attribute_alternateNameEncoding :: (Maybe Text -> f (Maybe Text)) -> Attribute -> f Attribute
attribute_alternateNameEncoding = (Attribute -> Maybe Text)
-> (Attribute -> Maybe Text -> Attribute)
-> Lens Attribute Attribute (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Maybe Text
alternateNameEncoding :: Maybe Text
$sel:alternateNameEncoding:Attribute' :: Attribute -> Maybe Text
alternateNameEncoding} -> Maybe Text
alternateNameEncoding) (\s :: Attribute
s@Attribute' {} Maybe Text
a -> Attribute
s {$sel:alternateNameEncoding:Attribute' :: Maybe Text
alternateNameEncoding = Maybe Text
a} :: Attribute)

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

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

instance Core.FromXML Attribute where
  parseXML :: [Node] -> Either String Attribute
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Text -> Text -> Attribute
Attribute'
      (Maybe Text -> Maybe Text -> Text -> Text -> Attribute)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Text -> Text -> Attribute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"AlternateValueEncoding")
      Either String (Maybe Text -> Text -> Text -> Attribute)
-> Either String (Maybe Text)
-> Either String (Text -> Text -> Attribute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"AlternateNameEncoding")
      Either String (Text -> Text -> Attribute)
-> Either String Text -> Either String (Text -> Attribute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name")
      Either String (Text -> Attribute)
-> Either String Text -> Either String Attribute
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Value")

instance Prelude.Hashable Attribute

instance Prelude.NFData Attribute

instance Core.ToQuery Attribute where
  toQuery :: Attribute -> QueryString
toQuery Attribute' {Maybe Text
Text
value :: Text
name :: Text
alternateNameEncoding :: Maybe Text
alternateValueEncoding :: Maybe Text
$sel:value:Attribute' :: Attribute -> Text
$sel:name:Attribute' :: Attribute -> Text
$sel:alternateNameEncoding:Attribute' :: Attribute -> Maybe Text
$sel:alternateValueEncoding:Attribute' :: Attribute -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"AlternateValueEncoding"
          ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
alternateValueEncoding,
        ByteString
"AlternateNameEncoding"
          ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
alternateNameEncoding,
        ByteString
"Name" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
name,
        ByteString
"Value" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
value
      ]