{-# 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.Item
-- 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.SDB.Types.Item 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
import Amazonka.SDB.Types.Attribute

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

-- |
-- Create a value of 'Item' 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:
--
-- 'alternateNameEncoding', 'item_alternateNameEncoding' -
--
-- 'name', 'item_name' - The name of the item.
--
-- 'attributes', 'item_attributes' - A list of attributes.
newItem ::
  -- | 'name'
  Prelude.Text ->
  Item
newItem :: Text -> Item
newItem Text
pName_ =
  Item'
    { $sel:alternateNameEncoding:Item' :: Maybe Text
alternateNameEncoding = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Item' :: Text
name = Text
pName_,
      $sel:attributes:Item' :: [Attribute]
attributes = forall a. Monoid a => a
Prelude.mempty
    }

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

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

-- | A list of attributes.
item_attributes :: Lens.Lens' Item [Attribute]
item_attributes :: Lens' Item [Attribute]
item_attributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Item' {[Attribute]
attributes :: [Attribute]
$sel:attributes:Item' :: Item -> [Attribute]
attributes} -> [Attribute]
attributes) (\s :: Item
s@Item' {} [Attribute]
a -> Item
s {$sel:attributes:Item' :: [Attribute]
attributes = [Attribute]
a} :: Item) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

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

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