{-# 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.DeleteObject
-- 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)
--
-- Deletes an object and its associated attributes. Only objects with no
-- children and no parents can be deleted. The maximum number of attributes
-- that can be deleted during an object deletion is 30. For more
-- information, see
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/limits.html Amazon Cloud Directory Limits>.
module Amazonka.CloudDirectory.DeleteObject
  ( -- * Creating a Request
    DeleteObject (..),
    newDeleteObject,

    -- * Request Lenses
    deleteObject_directoryArn,
    deleteObject_objectReference,

    -- * Destructuring the Response
    DeleteObjectResponse (..),
    newDeleteObjectResponse,

    -- * Response Lenses
    deleteObjectResponse_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:/ 'newDeleteObject' smart constructor.
data DeleteObject = DeleteObject'
  { -- | The Amazon Resource Name (ARN) that is associated with the Directory
    -- where the object resides. For more information, see arns.
    DeleteObject -> Text
directoryArn :: Prelude.Text,
    -- | A reference that identifies the object.
    DeleteObject -> ObjectReference
objectReference :: ObjectReference
  }
  deriving (DeleteObject -> DeleteObject -> Bool
(DeleteObject -> DeleteObject -> Bool)
-> (DeleteObject -> DeleteObject -> Bool) -> Eq DeleteObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteObject -> DeleteObject -> Bool
$c/= :: DeleteObject -> DeleteObject -> Bool
== :: DeleteObject -> DeleteObject -> Bool
$c== :: DeleteObject -> DeleteObject -> Bool
Prelude.Eq, ReadPrec [DeleteObject]
ReadPrec DeleteObject
Int -> ReadS DeleteObject
ReadS [DeleteObject]
(Int -> ReadS DeleteObject)
-> ReadS [DeleteObject]
-> ReadPrec DeleteObject
-> ReadPrec [DeleteObject]
-> Read DeleteObject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteObject]
$creadListPrec :: ReadPrec [DeleteObject]
readPrec :: ReadPrec DeleteObject
$creadPrec :: ReadPrec DeleteObject
readList :: ReadS [DeleteObject]
$creadList :: ReadS [DeleteObject]
readsPrec :: Int -> ReadS DeleteObject
$creadsPrec :: Int -> ReadS DeleteObject
Prelude.Read, Int -> DeleteObject -> ShowS
[DeleteObject] -> ShowS
DeleteObject -> String
(Int -> DeleteObject -> ShowS)
-> (DeleteObject -> String)
-> ([DeleteObject] -> ShowS)
-> Show DeleteObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteObject] -> ShowS
$cshowList :: [DeleteObject] -> ShowS
show :: DeleteObject -> String
$cshow :: DeleteObject -> String
showsPrec :: Int -> DeleteObject -> ShowS
$cshowsPrec :: Int -> DeleteObject -> ShowS
Prelude.Show, (forall x. DeleteObject -> Rep DeleteObject x)
-> (forall x. Rep DeleteObject x -> DeleteObject)
-> Generic DeleteObject
forall x. Rep DeleteObject x -> DeleteObject
forall x. DeleteObject -> Rep DeleteObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteObject x -> DeleteObject
$cfrom :: forall x. DeleteObject -> Rep DeleteObject x
Prelude.Generic)

-- |
-- Create a value of 'DeleteObject' 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', 'deleteObject_directoryArn' - The Amazon Resource Name (ARN) that is associated with the Directory
-- where the object resides. For more information, see arns.
--
-- 'objectReference', 'deleteObject_objectReference' - A reference that identifies the object.
newDeleteObject ::
  -- | 'directoryArn'
  Prelude.Text ->
  -- | 'objectReference'
  ObjectReference ->
  DeleteObject
newDeleteObject :: Text -> ObjectReference -> DeleteObject
newDeleteObject Text
pDirectoryArn_ ObjectReference
pObjectReference_ =
  DeleteObject' :: Text -> ObjectReference -> DeleteObject
DeleteObject'
    { $sel:directoryArn:DeleteObject' :: Text
directoryArn = Text
pDirectoryArn_,
      $sel:objectReference:DeleteObject' :: ObjectReference
objectReference = ObjectReference
pObjectReference_
    }

-- | The Amazon Resource Name (ARN) that is associated with the Directory
-- where the object resides. For more information, see arns.
deleteObject_directoryArn :: Lens.Lens' DeleteObject Prelude.Text
deleteObject_directoryArn :: (Text -> f Text) -> DeleteObject -> f DeleteObject
deleteObject_directoryArn = (DeleteObject -> Text)
-> (DeleteObject -> Text -> DeleteObject)
-> Lens DeleteObject DeleteObject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteObject' {Text
directoryArn :: Text
$sel:directoryArn:DeleteObject' :: DeleteObject -> Text
directoryArn} -> Text
directoryArn) (\s :: DeleteObject
s@DeleteObject' {} Text
a -> DeleteObject
s {$sel:directoryArn:DeleteObject' :: Text
directoryArn = Text
a} :: DeleteObject)

-- | A reference that identifies the object.
deleteObject_objectReference :: Lens.Lens' DeleteObject ObjectReference
deleteObject_objectReference :: (ObjectReference -> f ObjectReference)
-> DeleteObject -> f DeleteObject
deleteObject_objectReference = (DeleteObject -> ObjectReference)
-> (DeleteObject -> ObjectReference -> DeleteObject)
-> Lens DeleteObject DeleteObject ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteObject' {ObjectReference
objectReference :: ObjectReference
$sel:objectReference:DeleteObject' :: DeleteObject -> ObjectReference
objectReference} -> ObjectReference
objectReference) (\s :: DeleteObject
s@DeleteObject' {} ObjectReference
a -> DeleteObject
s {$sel:objectReference:DeleteObject' :: ObjectReference
objectReference = ObjectReference
a} :: DeleteObject)

instance Core.AWSRequest DeleteObject where
  type AWSResponse DeleteObject = DeleteObjectResponse
  request :: DeleteObject -> Request DeleteObject
request = Service -> DeleteObject -> Request DeleteObject
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteObject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteObject)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse DeleteObject))
-> Logger
-> Service
-> Proxy DeleteObject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteObject)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> DeleteObjectResponse
DeleteObjectResponse'
            (Int -> DeleteObjectResponse)
-> Either String Int -> Either String DeleteObjectResponse
forall (f :: * -> *) a b. Functor 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 DeleteObject

instance Prelude.NFData DeleteObject

instance Core.ToHeaders DeleteObject where
  toHeaders :: DeleteObject -> ResponseHeaders
toHeaders DeleteObject' {Text
ObjectReference
objectReference :: ObjectReference
directoryArn :: Text
$sel:objectReference:DeleteObject' :: DeleteObject -> ObjectReference
$sel:directoryArn:DeleteObject' :: DeleteObject -> 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 DeleteObject where
  toJSON :: DeleteObject -> Value
toJSON DeleteObject' {Text
ObjectReference
objectReference :: ObjectReference
directoryArn :: Text
$sel:objectReference:DeleteObject' :: DeleteObject -> ObjectReference
$sel:directoryArn:DeleteObject' :: DeleteObject -> 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
"ObjectReference" Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
objectReference)
          ]
      )

instance Core.ToPath DeleteObject where
  toPath :: DeleteObject -> ByteString
toPath =
    ByteString -> DeleteObject -> ByteString
forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/object/delete"

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

-- | /See:/ 'newDeleteObjectResponse' smart constructor.
data DeleteObjectResponse = DeleteObjectResponse'
  { -- | The response's http status code.
    DeleteObjectResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteObjectResponse -> DeleteObjectResponse -> Bool
(DeleteObjectResponse -> DeleteObjectResponse -> Bool)
-> (DeleteObjectResponse -> DeleteObjectResponse -> Bool)
-> Eq DeleteObjectResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteObjectResponse -> DeleteObjectResponse -> Bool
$c/= :: DeleteObjectResponse -> DeleteObjectResponse -> Bool
== :: DeleteObjectResponse -> DeleteObjectResponse -> Bool
$c== :: DeleteObjectResponse -> DeleteObjectResponse -> Bool
Prelude.Eq, ReadPrec [DeleteObjectResponse]
ReadPrec DeleteObjectResponse
Int -> ReadS DeleteObjectResponse
ReadS [DeleteObjectResponse]
(Int -> ReadS DeleteObjectResponse)
-> ReadS [DeleteObjectResponse]
-> ReadPrec DeleteObjectResponse
-> ReadPrec [DeleteObjectResponse]
-> Read DeleteObjectResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteObjectResponse]
$creadListPrec :: ReadPrec [DeleteObjectResponse]
readPrec :: ReadPrec DeleteObjectResponse
$creadPrec :: ReadPrec DeleteObjectResponse
readList :: ReadS [DeleteObjectResponse]
$creadList :: ReadS [DeleteObjectResponse]
readsPrec :: Int -> ReadS DeleteObjectResponse
$creadsPrec :: Int -> ReadS DeleteObjectResponse
Prelude.Read, Int -> DeleteObjectResponse -> ShowS
[DeleteObjectResponse] -> ShowS
DeleteObjectResponse -> String
(Int -> DeleteObjectResponse -> ShowS)
-> (DeleteObjectResponse -> String)
-> ([DeleteObjectResponse] -> ShowS)
-> Show DeleteObjectResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteObjectResponse] -> ShowS
$cshowList :: [DeleteObjectResponse] -> ShowS
show :: DeleteObjectResponse -> String
$cshow :: DeleteObjectResponse -> String
showsPrec :: Int -> DeleteObjectResponse -> ShowS
$cshowsPrec :: Int -> DeleteObjectResponse -> ShowS
Prelude.Show, (forall x. DeleteObjectResponse -> Rep DeleteObjectResponse x)
-> (forall x. Rep DeleteObjectResponse x -> DeleteObjectResponse)
-> Generic DeleteObjectResponse
forall x. Rep DeleteObjectResponse x -> DeleteObjectResponse
forall x. DeleteObjectResponse -> Rep DeleteObjectResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteObjectResponse x -> DeleteObjectResponse
$cfrom :: forall x. DeleteObjectResponse -> Rep DeleteObjectResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteObjectResponse' 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:
--
-- 'httpStatus', 'deleteObjectResponse_httpStatus' - The response's http status code.
newDeleteObjectResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteObjectResponse
newDeleteObjectResponse :: Int -> DeleteObjectResponse
newDeleteObjectResponse Int
pHttpStatus_ =
  DeleteObjectResponse' :: Int -> DeleteObjectResponse
DeleteObjectResponse' {$sel:httpStatus:DeleteObjectResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData DeleteObjectResponse