{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.AttachToIndex
-- 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)
--
-- Attaches the specified object to the specified index.
module Amazonka.CloudDirectory.AttachToIndex
  ( -- * Creating a Request
    AttachToIndex (..),
    newAttachToIndex,

    -- * Request Lenses
    attachToIndex_directoryArn,
    attachToIndex_indexReference,
    attachToIndex_targetReference,

    -- * Destructuring the Response
    AttachToIndexResponse (..),
    newAttachToIndexResponse,

    -- * Response Lenses
    attachToIndexResponse_attachedObjectIdentifier,
    attachToIndexResponse_httpStatus,
  )
where

import Amazonka.CloudDirectory.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAttachToIndex' smart constructor.
data AttachToIndex = AttachToIndex'
  { -- | The Amazon Resource Name (ARN) of the directory where the object and
    -- index exist.
    AttachToIndex -> Text
directoryArn :: Prelude.Text,
    -- | A reference to the index that you are attaching the object to.
    AttachToIndex -> ObjectReference
indexReference :: ObjectReference,
    -- | A reference to the object that you are attaching to the index.
    AttachToIndex -> ObjectReference
targetReference :: ObjectReference
  }
  deriving (AttachToIndex -> AttachToIndex -> Bool
(AttachToIndex -> AttachToIndex -> Bool)
-> (AttachToIndex -> AttachToIndex -> Bool) -> Eq AttachToIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachToIndex -> AttachToIndex -> Bool
$c/= :: AttachToIndex -> AttachToIndex -> Bool
== :: AttachToIndex -> AttachToIndex -> Bool
$c== :: AttachToIndex -> AttachToIndex -> Bool
Prelude.Eq, ReadPrec [AttachToIndex]
ReadPrec AttachToIndex
Int -> ReadS AttachToIndex
ReadS [AttachToIndex]
(Int -> ReadS AttachToIndex)
-> ReadS [AttachToIndex]
-> ReadPrec AttachToIndex
-> ReadPrec [AttachToIndex]
-> Read AttachToIndex
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachToIndex]
$creadListPrec :: ReadPrec [AttachToIndex]
readPrec :: ReadPrec AttachToIndex
$creadPrec :: ReadPrec AttachToIndex
readList :: ReadS [AttachToIndex]
$creadList :: ReadS [AttachToIndex]
readsPrec :: Int -> ReadS AttachToIndex
$creadsPrec :: Int -> ReadS AttachToIndex
Prelude.Read, Int -> AttachToIndex -> ShowS
[AttachToIndex] -> ShowS
AttachToIndex -> String
(Int -> AttachToIndex -> ShowS)
-> (AttachToIndex -> String)
-> ([AttachToIndex] -> ShowS)
-> Show AttachToIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachToIndex] -> ShowS
$cshowList :: [AttachToIndex] -> ShowS
show :: AttachToIndex -> String
$cshow :: AttachToIndex -> String
showsPrec :: Int -> AttachToIndex -> ShowS
$cshowsPrec :: Int -> AttachToIndex -> ShowS
Prelude.Show, (forall x. AttachToIndex -> Rep AttachToIndex x)
-> (forall x. Rep AttachToIndex x -> AttachToIndex)
-> Generic AttachToIndex
forall x. Rep AttachToIndex x -> AttachToIndex
forall x. AttachToIndex -> Rep AttachToIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachToIndex x -> AttachToIndex
$cfrom :: forall x. AttachToIndex -> Rep AttachToIndex x
Prelude.Generic)

-- |
-- Create a value of 'AttachToIndex' 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:
--
-- 'directoryArn', 'attachToIndex_directoryArn' - The Amazon Resource Name (ARN) of the directory where the object and
-- index exist.
--
-- 'indexReference', 'attachToIndex_indexReference' - A reference to the index that you are attaching the object to.
--
-- 'targetReference', 'attachToIndex_targetReference' - A reference to the object that you are attaching to the index.
newAttachToIndex ::
  -- | 'directoryArn'
  Prelude.Text ->
  -- | 'indexReference'
  ObjectReference ->
  -- | 'targetReference'
  ObjectReference ->
  AttachToIndex
newAttachToIndex :: Text -> ObjectReference -> ObjectReference -> AttachToIndex
newAttachToIndex
  Text
pDirectoryArn_
  ObjectReference
pIndexReference_
  ObjectReference
pTargetReference_ =
    AttachToIndex' :: Text -> ObjectReference -> ObjectReference -> AttachToIndex
AttachToIndex'
      { $sel:directoryArn:AttachToIndex' :: Text
directoryArn = Text
pDirectoryArn_,
        $sel:indexReference:AttachToIndex' :: ObjectReference
indexReference = ObjectReference
pIndexReference_,
        $sel:targetReference:AttachToIndex' :: ObjectReference
targetReference = ObjectReference
pTargetReference_
      }

-- | The Amazon Resource Name (ARN) of the directory where the object and
-- index exist.
attachToIndex_directoryArn :: Lens.Lens' AttachToIndex Prelude.Text
attachToIndex_directoryArn :: (Text -> f Text) -> AttachToIndex -> f AttachToIndex
attachToIndex_directoryArn = (AttachToIndex -> Text)
-> (AttachToIndex -> Text -> AttachToIndex)
-> Lens AttachToIndex AttachToIndex Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachToIndex' {Text
directoryArn :: Text
$sel:directoryArn:AttachToIndex' :: AttachToIndex -> Text
directoryArn} -> Text
directoryArn) (\s :: AttachToIndex
s@AttachToIndex' {} Text
a -> AttachToIndex
s {$sel:directoryArn:AttachToIndex' :: Text
directoryArn = Text
a} :: AttachToIndex)

-- | A reference to the index that you are attaching the object to.
attachToIndex_indexReference :: Lens.Lens' AttachToIndex ObjectReference
attachToIndex_indexReference :: (ObjectReference -> f ObjectReference)
-> AttachToIndex -> f AttachToIndex
attachToIndex_indexReference = (AttachToIndex -> ObjectReference)
-> (AttachToIndex -> ObjectReference -> AttachToIndex)
-> Lens AttachToIndex AttachToIndex ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachToIndex' {ObjectReference
indexReference :: ObjectReference
$sel:indexReference:AttachToIndex' :: AttachToIndex -> ObjectReference
indexReference} -> ObjectReference
indexReference) (\s :: AttachToIndex
s@AttachToIndex' {} ObjectReference
a -> AttachToIndex
s {$sel:indexReference:AttachToIndex' :: ObjectReference
indexReference = ObjectReference
a} :: AttachToIndex)

-- | A reference to the object that you are attaching to the index.
attachToIndex_targetReference :: Lens.Lens' AttachToIndex ObjectReference
attachToIndex_targetReference :: (ObjectReference -> f ObjectReference)
-> AttachToIndex -> f AttachToIndex
attachToIndex_targetReference = (AttachToIndex -> ObjectReference)
-> (AttachToIndex -> ObjectReference -> AttachToIndex)
-> Lens AttachToIndex AttachToIndex ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachToIndex' {ObjectReference
targetReference :: ObjectReference
$sel:targetReference:AttachToIndex' :: AttachToIndex -> ObjectReference
targetReference} -> ObjectReference
targetReference) (\s :: AttachToIndex
s@AttachToIndex' {} ObjectReference
a -> AttachToIndex
s {$sel:targetReference:AttachToIndex' :: ObjectReference
targetReference = ObjectReference
a} :: AttachToIndex)

instance Core.AWSRequest AttachToIndex where
  type
    AWSResponse AttachToIndex =
      AttachToIndexResponse
  request :: AttachToIndex -> Request AttachToIndex
request = Service -> AttachToIndex -> Request AttachToIndex
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AttachToIndex
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachToIndex)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AttachToIndex))
-> Logger
-> Service
-> Proxy AttachToIndex
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachToIndex)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> AttachToIndexResponse
AttachToIndexResponse'
            (Maybe Text -> Int -> AttachToIndexResponse)
-> Either String (Maybe Text)
-> Either String (Int -> AttachToIndexResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"AttachedObjectIdentifier")
            Either String (Int -> AttachToIndexResponse)
-> Either String Int -> Either String AttachToIndexResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AttachToIndex

instance Prelude.NFData AttachToIndex

instance Core.ToHeaders AttachToIndex where
  toHeaders :: AttachToIndex -> ResponseHeaders
toHeaders AttachToIndex' {Text
ObjectReference
targetReference :: ObjectReference
indexReference :: ObjectReference
directoryArn :: Text
$sel:targetReference:AttachToIndex' :: AttachToIndex -> ObjectReference
$sel:indexReference:AttachToIndex' :: AttachToIndex -> ObjectReference
$sel:directoryArn:AttachToIndex' :: AttachToIndex -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-data-partition" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
directoryArn]

instance Core.ToJSON AttachToIndex where
  toJSON :: AttachToIndex -> Value
toJSON AttachToIndex' {Text
ObjectReference
targetReference :: ObjectReference
indexReference :: ObjectReference
directoryArn :: Text
$sel:targetReference:AttachToIndex' :: AttachToIndex -> ObjectReference
$sel:indexReference:AttachToIndex' :: AttachToIndex -> ObjectReference
$sel:directoryArn:AttachToIndex' :: AttachToIndex -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"IndexReference" Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
indexReference),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"TargetReference" Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
targetReference)
          ]
      )

instance Core.ToPath AttachToIndex where
  toPath :: AttachToIndex -> ByteString
toPath =
    ByteString -> AttachToIndex -> ByteString
forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/index/attach"

instance Core.ToQuery AttachToIndex where
  toQuery :: AttachToIndex -> QueryString
toQuery = QueryString -> AttachToIndex -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newAttachToIndexResponse' smart constructor.
data AttachToIndexResponse = AttachToIndexResponse'
  { -- | The @ObjectIdentifier@ of the object that was attached to the index.
    AttachToIndexResponse -> Maybe Text
attachedObjectIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    AttachToIndexResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AttachToIndexResponse -> AttachToIndexResponse -> Bool
(AttachToIndexResponse -> AttachToIndexResponse -> Bool)
-> (AttachToIndexResponse -> AttachToIndexResponse -> Bool)
-> Eq AttachToIndexResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachToIndexResponse -> AttachToIndexResponse -> Bool
$c/= :: AttachToIndexResponse -> AttachToIndexResponse -> Bool
== :: AttachToIndexResponse -> AttachToIndexResponse -> Bool
$c== :: AttachToIndexResponse -> AttachToIndexResponse -> Bool
Prelude.Eq, ReadPrec [AttachToIndexResponse]
ReadPrec AttachToIndexResponse
Int -> ReadS AttachToIndexResponse
ReadS [AttachToIndexResponse]
(Int -> ReadS AttachToIndexResponse)
-> ReadS [AttachToIndexResponse]
-> ReadPrec AttachToIndexResponse
-> ReadPrec [AttachToIndexResponse]
-> Read AttachToIndexResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachToIndexResponse]
$creadListPrec :: ReadPrec [AttachToIndexResponse]
readPrec :: ReadPrec AttachToIndexResponse
$creadPrec :: ReadPrec AttachToIndexResponse
readList :: ReadS [AttachToIndexResponse]
$creadList :: ReadS [AttachToIndexResponse]
readsPrec :: Int -> ReadS AttachToIndexResponse
$creadsPrec :: Int -> ReadS AttachToIndexResponse
Prelude.Read, Int -> AttachToIndexResponse -> ShowS
[AttachToIndexResponse] -> ShowS
AttachToIndexResponse -> String
(Int -> AttachToIndexResponse -> ShowS)
-> (AttachToIndexResponse -> String)
-> ([AttachToIndexResponse] -> ShowS)
-> Show AttachToIndexResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachToIndexResponse] -> ShowS
$cshowList :: [AttachToIndexResponse] -> ShowS
show :: AttachToIndexResponse -> String
$cshow :: AttachToIndexResponse -> String
showsPrec :: Int -> AttachToIndexResponse -> ShowS
$cshowsPrec :: Int -> AttachToIndexResponse -> ShowS
Prelude.Show, (forall x. AttachToIndexResponse -> Rep AttachToIndexResponse x)
-> (forall x. Rep AttachToIndexResponse x -> AttachToIndexResponse)
-> Generic AttachToIndexResponse
forall x. Rep AttachToIndexResponse x -> AttachToIndexResponse
forall x. AttachToIndexResponse -> Rep AttachToIndexResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachToIndexResponse x -> AttachToIndexResponse
$cfrom :: forall x. AttachToIndexResponse -> Rep AttachToIndexResponse x
Prelude.Generic)

-- |
-- Create a value of 'AttachToIndexResponse' 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:
--
-- 'attachedObjectIdentifier', 'attachToIndexResponse_attachedObjectIdentifier' - The @ObjectIdentifier@ of the object that was attached to the index.
--
-- 'httpStatus', 'attachToIndexResponse_httpStatus' - The response's http status code.
newAttachToIndexResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AttachToIndexResponse
newAttachToIndexResponse :: Int -> AttachToIndexResponse
newAttachToIndexResponse Int
pHttpStatus_ =
  AttachToIndexResponse' :: Maybe Text -> Int -> AttachToIndexResponse
AttachToIndexResponse'
    { $sel:attachedObjectIdentifier:AttachToIndexResponse' :: Maybe Text
attachedObjectIdentifier =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AttachToIndexResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @ObjectIdentifier@ of the object that was attached to the index.
attachToIndexResponse_attachedObjectIdentifier :: Lens.Lens' AttachToIndexResponse (Prelude.Maybe Prelude.Text)
attachToIndexResponse_attachedObjectIdentifier :: (Maybe Text -> f (Maybe Text))
-> AttachToIndexResponse -> f AttachToIndexResponse
attachToIndexResponse_attachedObjectIdentifier = (AttachToIndexResponse -> Maybe Text)
-> (AttachToIndexResponse -> Maybe Text -> AttachToIndexResponse)
-> Lens
     AttachToIndexResponse
     AttachToIndexResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachToIndexResponse' {Maybe Text
attachedObjectIdentifier :: Maybe Text
$sel:attachedObjectIdentifier:AttachToIndexResponse' :: AttachToIndexResponse -> Maybe Text
attachedObjectIdentifier} -> Maybe Text
attachedObjectIdentifier) (\s :: AttachToIndexResponse
s@AttachToIndexResponse' {} Maybe Text
a -> AttachToIndexResponse
s {$sel:attachedObjectIdentifier:AttachToIndexResponse' :: Maybe Text
attachedObjectIdentifier = Maybe Text
a} :: AttachToIndexResponse)

-- | The response's http status code.
attachToIndexResponse_httpStatus :: Lens.Lens' AttachToIndexResponse Prelude.Int
attachToIndexResponse_httpStatus :: (Int -> f Int) -> AttachToIndexResponse -> f AttachToIndexResponse
attachToIndexResponse_httpStatus = (AttachToIndexResponse -> Int)
-> (AttachToIndexResponse -> Int -> AttachToIndexResponse)
-> Lens AttachToIndexResponse AttachToIndexResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachToIndexResponse' {Int
httpStatus :: Int
$sel:httpStatus:AttachToIndexResponse' :: AttachToIndexResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AttachToIndexResponse
s@AttachToIndexResponse' {} Int
a -> AttachToIndexResponse
s {$sel:httpStatus:AttachToIndexResponse' :: Int
httpStatus = Int
a} :: AttachToIndexResponse)

instance Prelude.NFData AttachToIndexResponse