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

import Amazonka.CloudDirectory.Types.AttributeKeyAndValue
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(IndexAttachment -> IndexAttachment -> Bool)
-> (IndexAttachment -> IndexAttachment -> Bool)
-> Eq IndexAttachment
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]
(Int -> ReadS IndexAttachment)
-> ReadS [IndexAttachment]
-> ReadPrec IndexAttachment
-> ReadPrec [IndexAttachment]
-> Read 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
(Int -> IndexAttachment -> ShowS)
-> (IndexAttachment -> String)
-> ([IndexAttachment] -> ShowS)
-> Show IndexAttachment
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. IndexAttachment -> Rep IndexAttachment x)
-> (forall x. Rep IndexAttachment x -> IndexAttachment)
-> Generic IndexAttachment
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' :: Maybe [AttributeKeyAndValue] -> Maybe Text -> IndexAttachment
IndexAttachment'
    { $sel:indexedAttributes:IndexAttachment' :: Maybe [AttributeKeyAndValue]
indexedAttributes =
        Maybe [AttributeKeyAndValue]
forall a. Maybe a
Prelude.Nothing,
      $sel:objectIdentifier:IndexAttachment' :: Maybe Text
objectIdentifier = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The indexed attribute values.
indexAttachment_indexedAttributes :: Lens.Lens' IndexAttachment (Prelude.Maybe [AttributeKeyAndValue])
indexAttachment_indexedAttributes :: (Maybe [AttributeKeyAndValue] -> f (Maybe [AttributeKeyAndValue]))
-> IndexAttachment -> f IndexAttachment
indexAttachment_indexedAttributes = (IndexAttachment -> Maybe [AttributeKeyAndValue])
-> (IndexAttachment
    -> Maybe [AttributeKeyAndValue] -> IndexAttachment)
-> Lens
     IndexAttachment
     IndexAttachment
     (Maybe [AttributeKeyAndValue])
     (Maybe [AttributeKeyAndValue])
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) ((Maybe [AttributeKeyAndValue] -> f (Maybe [AttributeKeyAndValue]))
 -> IndexAttachment -> f IndexAttachment)
-> ((Maybe [AttributeKeyAndValue]
     -> f (Maybe [AttributeKeyAndValue]))
    -> Maybe [AttributeKeyAndValue]
    -> f (Maybe [AttributeKeyAndValue]))
-> (Maybe [AttributeKeyAndValue]
    -> f (Maybe [AttributeKeyAndValue]))
-> IndexAttachment
-> f IndexAttachment
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [AttributeKeyAndValue]
  [AttributeKeyAndValue]
  [AttributeKeyAndValue]
  [AttributeKeyAndValue]
-> Iso
     (Maybe [AttributeKeyAndValue])
     (Maybe [AttributeKeyAndValue])
     (Maybe [AttributeKeyAndValue])
     (Maybe [AttributeKeyAndValue])
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 AnIso
  [AttributeKeyAndValue]
  [AttributeKeyAndValue]
  [AttributeKeyAndValue]
  [AttributeKeyAndValue]
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 :: (Maybe Text -> f (Maybe Text))
-> IndexAttachment -> f IndexAttachment
indexAttachment_objectIdentifier = (IndexAttachment -> Maybe Text)
-> (IndexAttachment -> Maybe Text -> IndexAttachment)
-> Lens IndexAttachment IndexAttachment (Maybe Text) (Maybe Text)
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 Core.FromJSON IndexAttachment where
  parseJSON :: Value -> Parser IndexAttachment
parseJSON =
    String
-> (Object -> Parser IndexAttachment)
-> Value
-> Parser IndexAttachment
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IndexAttachment"
      ( \Object
x ->
          Maybe [AttributeKeyAndValue] -> Maybe Text -> IndexAttachment
IndexAttachment'
            (Maybe [AttributeKeyAndValue] -> Maybe Text -> IndexAttachment)
-> Parser (Maybe [AttributeKeyAndValue])
-> Parser (Maybe Text -> IndexAttachment)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [AttributeKeyAndValue]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IndexedAttributes"
                            Parser (Maybe (Maybe [AttributeKeyAndValue]))
-> Maybe [AttributeKeyAndValue]
-> Parser (Maybe [AttributeKeyAndValue])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [AttributeKeyAndValue]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Text -> IndexAttachment)
-> Parser (Maybe Text) -> Parser IndexAttachment
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ObjectIdentifier")
      )

instance Prelude.Hashable IndexAttachment

instance Prelude.NFData IndexAttachment