{-# 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.DetachFromIndex
-- 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)
--
-- Detaches the specified object from the specified index.
module Amazonka.CloudDirectory.DetachFromIndex
  ( -- * Creating a Request
    DetachFromIndex (..),
    newDetachFromIndex,

    -- * Request Lenses
    detachFromIndex_directoryArn,
    detachFromIndex_indexReference,
    detachFromIndex_targetReference,

    -- * Destructuring the Response
    DetachFromIndexResponse (..),
    newDetachFromIndexResponse,

    -- * Response Lenses
    detachFromIndexResponse_detachedObjectIdentifier,
    detachFromIndexResponse_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:/ 'newDetachFromIndex' smart constructor.
data DetachFromIndex = DetachFromIndex'
  { -- | The Amazon Resource Name (ARN) of the directory the index and object
    -- exist in.
    DetachFromIndex -> Text
directoryArn :: Prelude.Text,
    -- | A reference to the index object.
    DetachFromIndex -> ObjectReference
indexReference :: ObjectReference,
    -- | A reference to the object being detached from the index.
    DetachFromIndex -> ObjectReference
targetReference :: ObjectReference
  }
  deriving (DetachFromIndex -> DetachFromIndex -> Bool
(DetachFromIndex -> DetachFromIndex -> Bool)
-> (DetachFromIndex -> DetachFromIndex -> Bool)
-> Eq DetachFromIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachFromIndex -> DetachFromIndex -> Bool
$c/= :: DetachFromIndex -> DetachFromIndex -> Bool
== :: DetachFromIndex -> DetachFromIndex -> Bool
$c== :: DetachFromIndex -> DetachFromIndex -> Bool
Prelude.Eq, ReadPrec [DetachFromIndex]
ReadPrec DetachFromIndex
Int -> ReadS DetachFromIndex
ReadS [DetachFromIndex]
(Int -> ReadS DetachFromIndex)
-> ReadS [DetachFromIndex]
-> ReadPrec DetachFromIndex
-> ReadPrec [DetachFromIndex]
-> Read DetachFromIndex
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachFromIndex]
$creadListPrec :: ReadPrec [DetachFromIndex]
readPrec :: ReadPrec DetachFromIndex
$creadPrec :: ReadPrec DetachFromIndex
readList :: ReadS [DetachFromIndex]
$creadList :: ReadS [DetachFromIndex]
readsPrec :: Int -> ReadS DetachFromIndex
$creadsPrec :: Int -> ReadS DetachFromIndex
Prelude.Read, Int -> DetachFromIndex -> ShowS
[DetachFromIndex] -> ShowS
DetachFromIndex -> String
(Int -> DetachFromIndex -> ShowS)
-> (DetachFromIndex -> String)
-> ([DetachFromIndex] -> ShowS)
-> Show DetachFromIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachFromIndex] -> ShowS
$cshowList :: [DetachFromIndex] -> ShowS
show :: DetachFromIndex -> String
$cshow :: DetachFromIndex -> String
showsPrec :: Int -> DetachFromIndex -> ShowS
$cshowsPrec :: Int -> DetachFromIndex -> ShowS
Prelude.Show, (forall x. DetachFromIndex -> Rep DetachFromIndex x)
-> (forall x. Rep DetachFromIndex x -> DetachFromIndex)
-> Generic DetachFromIndex
forall x. Rep DetachFromIndex x -> DetachFromIndex
forall x. DetachFromIndex -> Rep DetachFromIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetachFromIndex x -> DetachFromIndex
$cfrom :: forall x. DetachFromIndex -> Rep DetachFromIndex x
Prelude.Generic)

-- |
-- Create a value of 'DetachFromIndex' 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', 'detachFromIndex_directoryArn' - The Amazon Resource Name (ARN) of the directory the index and object
-- exist in.
--
-- 'indexReference', 'detachFromIndex_indexReference' - A reference to the index object.
--
-- 'targetReference', 'detachFromIndex_targetReference' - A reference to the object being detached from the index.
newDetachFromIndex ::
  -- | 'directoryArn'
  Prelude.Text ->
  -- | 'indexReference'
  ObjectReference ->
  -- | 'targetReference'
  ObjectReference ->
  DetachFromIndex
newDetachFromIndex :: Text -> ObjectReference -> ObjectReference -> DetachFromIndex
newDetachFromIndex
  Text
pDirectoryArn_
  ObjectReference
pIndexReference_
  ObjectReference
pTargetReference_ =
    DetachFromIndex' :: Text -> ObjectReference -> ObjectReference -> DetachFromIndex
DetachFromIndex'
      { $sel:directoryArn:DetachFromIndex' :: Text
directoryArn = Text
pDirectoryArn_,
        $sel:indexReference:DetachFromIndex' :: ObjectReference
indexReference = ObjectReference
pIndexReference_,
        $sel:targetReference:DetachFromIndex' :: ObjectReference
targetReference = ObjectReference
pTargetReference_
      }

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

-- | A reference to the index object.
detachFromIndex_indexReference :: Lens.Lens' DetachFromIndex ObjectReference
detachFromIndex_indexReference :: (ObjectReference -> f ObjectReference)
-> DetachFromIndex -> f DetachFromIndex
detachFromIndex_indexReference = (DetachFromIndex -> ObjectReference)
-> (DetachFromIndex -> ObjectReference -> DetachFromIndex)
-> Lens
     DetachFromIndex DetachFromIndex ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachFromIndex' {ObjectReference
indexReference :: ObjectReference
$sel:indexReference:DetachFromIndex' :: DetachFromIndex -> ObjectReference
indexReference} -> ObjectReference
indexReference) (\s :: DetachFromIndex
s@DetachFromIndex' {} ObjectReference
a -> DetachFromIndex
s {$sel:indexReference:DetachFromIndex' :: ObjectReference
indexReference = ObjectReference
a} :: DetachFromIndex)

-- | A reference to the object being detached from the index.
detachFromIndex_targetReference :: Lens.Lens' DetachFromIndex ObjectReference
detachFromIndex_targetReference :: (ObjectReference -> f ObjectReference)
-> DetachFromIndex -> f DetachFromIndex
detachFromIndex_targetReference = (DetachFromIndex -> ObjectReference)
-> (DetachFromIndex -> ObjectReference -> DetachFromIndex)
-> Lens
     DetachFromIndex DetachFromIndex ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachFromIndex' {ObjectReference
targetReference :: ObjectReference
$sel:targetReference:DetachFromIndex' :: DetachFromIndex -> ObjectReference
targetReference} -> ObjectReference
targetReference) (\s :: DetachFromIndex
s@DetachFromIndex' {} ObjectReference
a -> DetachFromIndex
s {$sel:targetReference:DetachFromIndex' :: ObjectReference
targetReference = ObjectReference
a} :: DetachFromIndex)

instance Core.AWSRequest DetachFromIndex where
  type
    AWSResponse DetachFromIndex =
      DetachFromIndexResponse
  request :: DetachFromIndex -> Request DetachFromIndex
request = Service -> DetachFromIndex -> Request DetachFromIndex
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DetachFromIndex
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachFromIndex)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DetachFromIndex))
-> Logger
-> Service
-> Proxy DetachFromIndex
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachFromIndex)))
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 -> DetachFromIndexResponse
DetachFromIndexResponse'
            (Maybe Text -> Int -> DetachFromIndexResponse)
-> Either String (Maybe Text)
-> Either String (Int -> DetachFromIndexResponse)
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
"DetachedObjectIdentifier")
            Either String (Int -> DetachFromIndexResponse)
-> Either String Int -> Either String DetachFromIndexResponse
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 DetachFromIndex

instance Prelude.NFData DetachFromIndex

instance Core.ToHeaders DetachFromIndex where
  toHeaders :: DetachFromIndex -> ResponseHeaders
toHeaders DetachFromIndex' {Text
ObjectReference
targetReference :: ObjectReference
indexReference :: ObjectReference
directoryArn :: Text
$sel:targetReference:DetachFromIndex' :: DetachFromIndex -> ObjectReference
$sel:indexReference:DetachFromIndex' :: DetachFromIndex -> ObjectReference
$sel:directoryArn:DetachFromIndex' :: DetachFromIndex -> 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 DetachFromIndex where
  toJSON :: DetachFromIndex -> Value
toJSON DetachFromIndex' {Text
ObjectReference
targetReference :: ObjectReference
indexReference :: ObjectReference
directoryArn :: Text
$sel:targetReference:DetachFromIndex' :: DetachFromIndex -> ObjectReference
$sel:indexReference:DetachFromIndex' :: DetachFromIndex -> ObjectReference
$sel:directoryArn:DetachFromIndex' :: DetachFromIndex -> 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 DetachFromIndex where
  toPath :: DetachFromIndex -> ByteString
toPath =
    ByteString -> DetachFromIndex -> ByteString
forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/index/detach"

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

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

-- |
-- Create a value of 'DetachFromIndexResponse' 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:
--
-- 'detachedObjectIdentifier', 'detachFromIndexResponse_detachedObjectIdentifier' - The @ObjectIdentifier@ of the object that was detached from the index.
--
-- 'httpStatus', 'detachFromIndexResponse_httpStatus' - The response's http status code.
newDetachFromIndexResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetachFromIndexResponse
newDetachFromIndexResponse :: Int -> DetachFromIndexResponse
newDetachFromIndexResponse Int
pHttpStatus_ =
  DetachFromIndexResponse' :: Maybe Text -> Int -> DetachFromIndexResponse
DetachFromIndexResponse'
    { $sel:detachedObjectIdentifier:DetachFromIndexResponse' :: Maybe Text
detachedObjectIdentifier =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetachFromIndexResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @ObjectIdentifier@ of the object that was detached from the index.
detachFromIndexResponse_detachedObjectIdentifier :: Lens.Lens' DetachFromIndexResponse (Prelude.Maybe Prelude.Text)
detachFromIndexResponse_detachedObjectIdentifier :: (Maybe Text -> f (Maybe Text))
-> DetachFromIndexResponse -> f DetachFromIndexResponse
detachFromIndexResponse_detachedObjectIdentifier = (DetachFromIndexResponse -> Maybe Text)
-> (DetachFromIndexResponse
    -> Maybe Text -> DetachFromIndexResponse)
-> Lens
     DetachFromIndexResponse
     DetachFromIndexResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachFromIndexResponse' {Maybe Text
detachedObjectIdentifier :: Maybe Text
$sel:detachedObjectIdentifier:DetachFromIndexResponse' :: DetachFromIndexResponse -> Maybe Text
detachedObjectIdentifier} -> Maybe Text
detachedObjectIdentifier) (\s :: DetachFromIndexResponse
s@DetachFromIndexResponse' {} Maybe Text
a -> DetachFromIndexResponse
s {$sel:detachedObjectIdentifier:DetachFromIndexResponse' :: Maybe Text
detachedObjectIdentifier = Maybe Text
a} :: DetachFromIndexResponse)

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

instance Prelude.NFData DetachFromIndexResponse