{-# 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.SQS.DeleteMessage
-- 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 the specified message from the specified queue. To select the
-- message to delete, use the @ReceiptHandle@ of the message (/not/ the
-- @MessageId@ which you receive when you send the message). Amazon SQS can
-- delete a message from a queue even if a visibility timeout setting
-- causes the message to be locked by another consumer. Amazon SQS
-- automatically deletes messages left in a queue longer than the retention
-- period configured for the queue.
--
-- The @ReceiptHandle@ is associated with a /specific instance/ of
-- receiving a message. If you receive a message more than once, the
-- @ReceiptHandle@ is different each time you receive a message. When you
-- use the @DeleteMessage@ action, you must provide the most recently
-- received @ReceiptHandle@ for the message (otherwise, the request
-- succeeds, but the message might not be deleted).
--
-- For standard queues, it is possible to receive a message even after you
-- delete it. This might happen on rare occasions if one of the servers
-- which stores a copy of the message is unavailable when you send the
-- request to delete the message. The copy remains on the server and might
-- be returned to you during a subsequent receive request. You should
-- ensure that your application is idempotent, so that receiving a message
-- more than once does not cause issues.
module Amazonka.SQS.DeleteMessage
  ( -- * Creating a Request
    DeleteMessage (..),
    newDeleteMessage,

    -- * Request Lenses
    deleteMessage_queueUrl,
    deleteMessage_receiptHandle,

    -- * Destructuring the Response
    DeleteMessageResponse (..),
    newDeleteMessageResponse,
  )
where

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
import Amazonka.SQS.Types

-- |
--
-- /See:/ 'newDeleteMessage' smart constructor.
data DeleteMessage = DeleteMessage'
  { -- | The URL of the Amazon SQS queue from which messages are deleted.
    --
    -- Queue URLs and names are case-sensitive.
    DeleteMessage -> Text
queueUrl :: Prelude.Text,
    -- | The receipt handle associated with the message to delete.
    DeleteMessage -> Text
receiptHandle :: Prelude.Text
  }
  deriving (DeleteMessage -> DeleteMessage -> Bool
(DeleteMessage -> DeleteMessage -> Bool)
-> (DeleteMessage -> DeleteMessage -> Bool) -> Eq DeleteMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteMessage -> DeleteMessage -> Bool
$c/= :: DeleteMessage -> DeleteMessage -> Bool
== :: DeleteMessage -> DeleteMessage -> Bool
$c== :: DeleteMessage -> DeleteMessage -> Bool
Prelude.Eq, ReadPrec [DeleteMessage]
ReadPrec DeleteMessage
Int -> ReadS DeleteMessage
ReadS [DeleteMessage]
(Int -> ReadS DeleteMessage)
-> ReadS [DeleteMessage]
-> ReadPrec DeleteMessage
-> ReadPrec [DeleteMessage]
-> Read DeleteMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteMessage]
$creadListPrec :: ReadPrec [DeleteMessage]
readPrec :: ReadPrec DeleteMessage
$creadPrec :: ReadPrec DeleteMessage
readList :: ReadS [DeleteMessage]
$creadList :: ReadS [DeleteMessage]
readsPrec :: Int -> ReadS DeleteMessage
$creadsPrec :: Int -> ReadS DeleteMessage
Prelude.Read, Int -> DeleteMessage -> ShowS
[DeleteMessage] -> ShowS
DeleteMessage -> String
(Int -> DeleteMessage -> ShowS)
-> (DeleteMessage -> String)
-> ([DeleteMessage] -> ShowS)
-> Show DeleteMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteMessage] -> ShowS
$cshowList :: [DeleteMessage] -> ShowS
show :: DeleteMessage -> String
$cshow :: DeleteMessage -> String
showsPrec :: Int -> DeleteMessage -> ShowS
$cshowsPrec :: Int -> DeleteMessage -> ShowS
Prelude.Show, (forall x. DeleteMessage -> Rep DeleteMessage x)
-> (forall x. Rep DeleteMessage x -> DeleteMessage)
-> Generic DeleteMessage
forall x. Rep DeleteMessage x -> DeleteMessage
forall x. DeleteMessage -> Rep DeleteMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteMessage x -> DeleteMessage
$cfrom :: forall x. DeleteMessage -> Rep DeleteMessage x
Prelude.Generic)

-- |
-- Create a value of 'DeleteMessage' 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:
--
-- 'queueUrl', 'deleteMessage_queueUrl' - The URL of the Amazon SQS queue from which messages are deleted.
--
-- Queue URLs and names are case-sensitive.
--
-- 'receiptHandle', 'deleteMessage_receiptHandle' - The receipt handle associated with the message to delete.
newDeleteMessage ::
  -- | 'queueUrl'
  Prelude.Text ->
  -- | 'receiptHandle'
  Prelude.Text ->
  DeleteMessage
newDeleteMessage :: Text -> Text -> DeleteMessage
newDeleteMessage Text
pQueueUrl_ Text
pReceiptHandle_ =
  DeleteMessage' :: Text -> Text -> DeleteMessage
DeleteMessage'
    { $sel:queueUrl:DeleteMessage' :: Text
queueUrl = Text
pQueueUrl_,
      $sel:receiptHandle:DeleteMessage' :: Text
receiptHandle = Text
pReceiptHandle_
    }

-- | The URL of the Amazon SQS queue from which messages are deleted.
--
-- Queue URLs and names are case-sensitive.
deleteMessage_queueUrl :: Lens.Lens' DeleteMessage Prelude.Text
deleteMessage_queueUrl :: (Text -> f Text) -> DeleteMessage -> f DeleteMessage
deleteMessage_queueUrl = (DeleteMessage -> Text)
-> (DeleteMessage -> Text -> DeleteMessage)
-> Lens DeleteMessage DeleteMessage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteMessage' {Text
queueUrl :: Text
$sel:queueUrl:DeleteMessage' :: DeleteMessage -> Text
queueUrl} -> Text
queueUrl) (\s :: DeleteMessage
s@DeleteMessage' {} Text
a -> DeleteMessage
s {$sel:queueUrl:DeleteMessage' :: Text
queueUrl = Text
a} :: DeleteMessage)

-- | The receipt handle associated with the message to delete.
deleteMessage_receiptHandle :: Lens.Lens' DeleteMessage Prelude.Text
deleteMessage_receiptHandle :: (Text -> f Text) -> DeleteMessage -> f DeleteMessage
deleteMessage_receiptHandle = (DeleteMessage -> Text)
-> (DeleteMessage -> Text -> DeleteMessage)
-> Lens DeleteMessage DeleteMessage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteMessage' {Text
receiptHandle :: Text
$sel:receiptHandle:DeleteMessage' :: DeleteMessage -> Text
receiptHandle} -> Text
receiptHandle) (\s :: DeleteMessage
s@DeleteMessage' {} Text
a -> DeleteMessage
s {$sel:receiptHandle:DeleteMessage' :: Text
receiptHandle = Text
a} :: DeleteMessage)

instance Core.AWSRequest DeleteMessage where
  type
    AWSResponse DeleteMessage =
      DeleteMessageResponse
  request :: DeleteMessage -> Request DeleteMessage
request = Service -> DeleteMessage -> Request DeleteMessage
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteMessage
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteMessage)))
response =
    AWSResponse DeleteMessage
-> Logger
-> Service
-> Proxy DeleteMessage
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteMessage)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse DeleteMessage
DeleteMessageResponse
DeleteMessageResponse'

instance Prelude.Hashable DeleteMessage

instance Prelude.NFData DeleteMessage

instance Core.ToHeaders DeleteMessage where
  toHeaders :: DeleteMessage -> [Header]
toHeaders = [Header] -> DeleteMessage -> [Header]
forall a b. a -> b -> a
Prelude.const [Header]
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath DeleteMessage where
  toPath :: DeleteMessage -> ByteString
toPath = ByteString -> DeleteMessage -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DeleteMessage where
  toQuery :: DeleteMessage -> QueryString
toQuery DeleteMessage' {Text
receiptHandle :: Text
queueUrl :: Text
$sel:receiptHandle:DeleteMessage' :: DeleteMessage -> Text
$sel:queueUrl:DeleteMessage' :: DeleteMessage -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"DeleteMessage" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2012-11-05" :: Prelude.ByteString),
        ByteString
"QueueUrl" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
queueUrl,
        ByteString
"ReceiptHandle" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
receiptHandle
      ]

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

-- |
-- Create a value of 'DeleteMessageResponse' 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.
newDeleteMessageResponse ::
  DeleteMessageResponse
newDeleteMessageResponse :: DeleteMessageResponse
newDeleteMessageResponse = DeleteMessageResponse
DeleteMessageResponse'

instance Prelude.NFData DeleteMessageResponse