{-# 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.IndexAttachment
-- 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.CloudDirectory.Types.IndexAttachment where

import Amazonka.CloudDirectory.Types.AttributeKeyAndValue
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 an index and an attached object.
--
-- /See:/ 'newIndexAttachment' smart constructor.
data IndexAttachment = IndexAttachment'
  { -- | The indexed attribute values.
    IndexAttachment -> Maybe [AttributeKeyAndValue]
indexedAttributes :: Prelude.Maybe [AttributeKeyAndValue],
    -- | In response to ListIndex, the @ObjectIdentifier@ of the object attached
    -- to the index. In response to ListAttachedIndices, the @ObjectIdentifier@
    -- of the index attached to the object. This field will always contain the
    -- @ObjectIdentifier@ of the object on the opposite side of the attachment
    -- specified in the query.
    IndexAttachment -> Maybe Text
objectIdentifier :: Prelude.Maybe Prelude.Text
  }
  deriving (IndexAttachment -> IndexAttachment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndexAttachment -> IndexAttachment -> Bool
$c/= :: IndexAttachment -> IndexAttachment -> Bool
== :: IndexAttachment -> IndexAttachment -> Bool
$c== :: IndexAttachment -> IndexAttachment -> Bool
Prelude.Eq, ReadPrec [IndexAttachment]
ReadPrec IndexAttachment
Int -> ReadS IndexAttachment
ReadS [IndexAttachment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IndexAttachment]
$creadListPrec :: ReadPrec [IndexAttachment]
readPrec :: ReadPrec IndexAttachment
$creadPrec :: ReadPrec IndexAttachment
readList :: ReadS [IndexAttachment]
$creadList :: ReadS [IndexAttachment]
readsPrec :: Int -> ReadS IndexAttachment
$creadsPrec :: Int -> ReadS IndexAttachment
Prelude.Read, Int -> IndexAttachment -> ShowS
[IndexAttachment] -> ShowS
IndexAttachment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IndexAttachment] -> ShowS
$cshowList :: [IndexAttachment] -> ShowS
show :: IndexAttachment -> String
$cshow :: IndexAttachment -> String
showsPrec :: Int -> IndexAttachment -> ShowS
$cshowsPrec :: Int -> IndexAttachment -> ShowS
Prelude.Show, forall x. Rep IndexAttachment x -> IndexAttachment
forall x. IndexAttachment -> Rep IndexAttachment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IndexAttachment x -> IndexAttachment
$cfrom :: forall x. IndexAttachment -> Rep IndexAttachment x
Prelude.Generic)

-- |
-- Create a value of 'IndexAttachment' 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:
--
-- 'indexedAttributes', 'indexAttachment_indexedAttributes' - The indexed attribute values.
--
-- 'objectIdentifier', 'indexAttachment_objectIdentifier' - In response to ListIndex, the @ObjectIdentifier@ of the object attached
-- to the index. In response to ListAttachedIndices, the @ObjectIdentifier@
-- of the index attached to the object. This field will always contain the
-- @ObjectIdentifier@ of the object on the opposite side of the attachment
-- specified in the query.
newIndexAttachment ::
  IndexAttachment
newIndexAttachment :: IndexAttachment
newIndexAttachment =
  IndexAttachment'
    { $sel:indexedAttributes:IndexAttachment' :: Maybe [AttributeKeyAndValue]
indexedAttributes =
        forall a. Maybe a
Prelude.Nothing,
      $sel:objectIdentifier:IndexAttachment' :: Maybe Text
objectIdentifier = forall a. Maybe a
Prelude.Nothing
    }

-- | The indexed attribute values.
indexAttachment_indexedAttributes :: Lens.Lens' IndexAttachment (Prelude.Maybe [AttributeKeyAndValue])
indexAttachment_indexedAttributes :: Lens' IndexAttachment (Maybe [AttributeKeyAndValue])
indexAttachment_indexedAttributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IndexAttachment' {Maybe [AttributeKeyAndValue]
indexedAttributes :: Maybe [AttributeKeyAndValue]
$sel:indexedAttributes:IndexAttachment' :: IndexAttachment -> Maybe [AttributeKeyAndValue]
indexedAttributes} -> Maybe [AttributeKeyAndValue]
indexedAttributes) (\s :: IndexAttachment
s@IndexAttachment' {} Maybe [AttributeKeyAndValue]
a -> IndexAttachment
s {$sel:indexedAttributes:IndexAttachment' :: Maybe [AttributeKeyAndValue]
indexedAttributes = Maybe [AttributeKeyAndValue]
a} :: IndexAttachment) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | In response to ListIndex, the @ObjectIdentifier@ of the object attached
-- to the index. In response to ListAttachedIndices, the @ObjectIdentifier@
-- of the index attached to the object. This field will always contain the
-- @ObjectIdentifier@ of the object on the opposite side of the attachment
-- specified in the query.
indexAttachment_objectIdentifier :: Lens.Lens' IndexAttachment (Prelude.Maybe Prelude.Text)
indexAttachment_objectIdentifier :: Lens' IndexAttachment (Maybe Text)
indexAttachment_objectIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IndexAttachment' {Maybe Text
objectIdentifier :: Maybe Text
$sel:objectIdentifier:IndexAttachment' :: IndexAttachment -> Maybe Text
objectIdentifier} -> Maybe Text
objectIdentifier) (\s :: IndexAttachment
s@IndexAttachment' {} Maybe Text
a -> IndexAttachment
s {$sel:objectIdentifier:IndexAttachment' :: Maybe Text
objectIdentifier = Maybe Text
a} :: IndexAttachment)

instance Data.FromJSON IndexAttachment where
  parseJSON :: Value -> Parser IndexAttachment
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IndexAttachment"
      ( \Object
x ->
          Maybe [AttributeKeyAndValue] -> Maybe Text -> IndexAttachment
IndexAttachment'
            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
"IndexedAttributes"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"ObjectIdentifier")
      )

instance Prelude.Hashable IndexAttachment where
  hashWithSalt :: Int -> IndexAttachment -> Int
hashWithSalt Int
_salt IndexAttachment' {Maybe [AttributeKeyAndValue]
Maybe Text
objectIdentifier :: Maybe Text
indexedAttributes :: Maybe [AttributeKeyAndValue]
$sel:objectIdentifier:IndexAttachment' :: IndexAttachment -> Maybe Text
$sel:indexedAttributes:IndexAttachment' :: IndexAttachment -> Maybe [AttributeKeyAndValue]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [AttributeKeyAndValue]
indexedAttributes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
objectIdentifier

instance Prelude.NFData IndexAttachment where
  rnf :: IndexAttachment -> ()
rnf IndexAttachment' {Maybe [AttributeKeyAndValue]
Maybe Text
objectIdentifier :: Maybe Text
indexedAttributes :: Maybe [AttributeKeyAndValue]
$sel:objectIdentifier:IndexAttachment' :: IndexAttachment -> Maybe Text
$sel:indexedAttributes:IndexAttachment' :: IndexAttachment -> Maybe [AttributeKeyAndValue]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [AttributeKeyAndValue]
indexedAttributes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
objectIdentifier