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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Item -> Item -> Bool) -> (Item -> Item -> Bool) -> Eq Item
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]
(Int -> ReadS Item)
-> ReadS [Item] -> ReadPrec Item -> ReadPrec [Item] -> Read 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
(Int -> Item -> ShowS)
-> (Item -> String) -> ([Item] -> ShowS) -> Show Item
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. Item -> Rep Item x)
-> (forall x. Rep Item x -> Item) -> Generic Item
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' :: Maybe Text -> Text -> [Attribute] -> Item
Item'
    { $sel:alternateNameEncoding:Item' :: Maybe Text
alternateNameEncoding = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Item' :: Text
name = Text
pName_,
      $sel:attributes:Item' :: [Attribute]
attributes = [Attribute]
forall a. Monoid a => a
Prelude.mempty
    }

-- |
item_alternateNameEncoding :: Lens.Lens' Item (Prelude.Maybe Prelude.Text)
item_alternateNameEncoding :: (Maybe Text -> f (Maybe Text)) -> Item -> f Item
item_alternateNameEncoding = (Item -> Maybe Text)
-> (Item -> Maybe Text -> Item)
-> Lens Item Item (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> Item -> f Item
item_name = (Item -> Text)
-> (Item -> Text -> Item) -> Lens Item Item Text Text
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 :: ([Attribute] -> f [Attribute]) -> Item -> f Item
item_attributes = (Item -> [Attribute])
-> (Item -> [Attribute] -> Item)
-> Lens Item Item [Attribute] [Attribute]
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) (([Attribute] -> f [Attribute]) -> Item -> f Item)
-> (([Attribute] -> f [Attribute]) -> [Attribute] -> f [Attribute])
-> ([Attribute] -> f [Attribute])
-> Item
-> f Item
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Attribute] -> f [Attribute]) -> [Attribute] -> f [Attribute]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML Item where
  parseXML :: [Node] -> Either String Item
parseXML [Node]
x =
    Maybe Text -> Text -> [Attribute] -> Item
Item'
      (Maybe Text -> Text -> [Attribute] -> Item)
-> Either String (Maybe Text)
-> Either String (Text -> [Attribute] -> Item)
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
"AlternateNameEncoding")
      Either String (Text -> [Attribute] -> Item)
-> Either String Text -> Either String ([Attribute] -> Item)
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 ([Attribute] -> Item)
-> Either String [Attribute] -> Either String Item
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Text -> [Node] -> Either String [Attribute]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Attribute" [Node]
x)

instance Prelude.Hashable Item

instance Prelude.NFData Item