{-# 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.ChangeMessageVisibility
-- 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)
--
-- Changes the visibility timeout of a specified message in a queue to a
-- new value. The default visibility timeout for a message is 30 seconds.
-- The minimum is 0 seconds. The maximum is 12 hours. For more information,
-- see
-- <https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html Visibility Timeout>
-- in the /Amazon SQS Developer Guide/.
--
-- For example, you have a message with a visibility timeout of 5 minutes.
-- After 3 minutes, you call @ChangeMessageVisibility@ with a timeout of 10
-- minutes. You can continue to call @ChangeMessageVisibility@ to extend
-- the visibility timeout to the maximum allowed time. If you try to extend
-- the visibility timeout beyond the maximum, your request is rejected.
--
-- An Amazon SQS message has three basic states:
--
-- 1.  Sent to a queue by a producer.
--
-- 2.  Received from the queue by a consumer.
--
-- 3.  Deleted from the queue.
--
-- A message is considered to be /stored/ after it is sent to a queue by a
-- producer, but not yet received from the queue by a consumer (that is,
-- between states 1 and 2). There is no limit to the number of stored
-- messages. A message is considered to be /in flight/ after it is received
-- from a queue by a consumer, but not yet deleted from the queue (that is,
-- between states 2 and 3). There is a limit to the number of inflight
-- messages.
--
-- Limits that apply to inflight messages are unrelated to the /unlimited/
-- number of stored messages.
--
-- For most standard queues (depending on queue traffic and message
-- backlog), there can be a maximum of approximately 120,000 inflight
-- messages (received from a queue by a consumer, but not yet deleted from
-- the queue). If you reach this limit, Amazon SQS returns the @OverLimit@
-- error message. To avoid reaching the limit, you should delete messages
-- from the queue after they\'re processed. You can also increase the
-- number of queues you use to process your messages. To request a limit
-- increase,
-- <https://console.aws.amazon.com/support/home#/case/create?issueType=service-limit-increase&limitType=service-code-sqs file a support request>.
--
-- For FIFO queues, there can be a maximum of 20,000 inflight messages
-- (received from a queue by a consumer, but not yet deleted from the
-- queue). If you reach this limit, Amazon SQS returns no error messages.
--
-- If you attempt to set the @VisibilityTimeout@ to a value greater than
-- the maximum time left, Amazon SQS returns an error. Amazon SQS doesn\'t
-- automatically recalculate and increase the timeout to the maximum
-- remaining time.
--
-- Unlike with a queue, when you change the visibility timeout for a
-- specific message the timeout value is applied immediately but isn\'t
-- saved in memory for that message. If you don\'t delete a message after
-- it is received, the visibility timeout for the message reverts to the
-- original timeout value (not to the value you set using the
-- @ChangeMessageVisibility@ action) the next time the message is received.
module Amazonka.SQS.ChangeMessageVisibility
  ( -- * Creating a Request
    ChangeMessageVisibility (..),
    newChangeMessageVisibility,

    -- * Request Lenses
    changeMessageVisibility_queueUrl,
    changeMessageVisibility_receiptHandle,
    changeMessageVisibility_visibilityTimeout,

    -- * Destructuring the Response
    ChangeMessageVisibilityResponse (..),
    newChangeMessageVisibilityResponse,
  )
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:/ 'newChangeMessageVisibility' smart constructor.
data ChangeMessageVisibility = ChangeMessageVisibility'
  { -- | The URL of the Amazon SQS queue whose message\'s visibility is changed.
    --
    -- Queue URLs and names are case-sensitive.
    ChangeMessageVisibility -> Text
queueUrl :: Prelude.Text,
    -- | The receipt handle associated with the message whose visibility timeout
    -- is changed. This parameter is returned by the @ ReceiveMessage @ action.
    ChangeMessageVisibility -> Text
receiptHandle :: Prelude.Text,
    -- | The new value for the message\'s visibility timeout (in seconds). Values
    -- range: @0@ to @43200@. Maximum: 12 hours.
    ChangeMessageVisibility -> Int
visibilityTimeout :: Prelude.Int
  }
  deriving (ChangeMessageVisibility -> ChangeMessageVisibility -> Bool
(ChangeMessageVisibility -> ChangeMessageVisibility -> Bool)
-> (ChangeMessageVisibility -> ChangeMessageVisibility -> Bool)
-> Eq ChangeMessageVisibility
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChangeMessageVisibility -> ChangeMessageVisibility -> Bool
$c/= :: ChangeMessageVisibility -> ChangeMessageVisibility -> Bool
== :: ChangeMessageVisibility -> ChangeMessageVisibility -> Bool
$c== :: ChangeMessageVisibility -> ChangeMessageVisibility -> Bool
Prelude.Eq, ReadPrec [ChangeMessageVisibility]
ReadPrec ChangeMessageVisibility
Int -> ReadS ChangeMessageVisibility
ReadS [ChangeMessageVisibility]
(Int -> ReadS ChangeMessageVisibility)
-> ReadS [ChangeMessageVisibility]
-> ReadPrec ChangeMessageVisibility
-> ReadPrec [ChangeMessageVisibility]
-> Read ChangeMessageVisibility
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ChangeMessageVisibility]
$creadListPrec :: ReadPrec [ChangeMessageVisibility]
readPrec :: ReadPrec ChangeMessageVisibility
$creadPrec :: ReadPrec ChangeMessageVisibility
readList :: ReadS [ChangeMessageVisibility]
$creadList :: ReadS [ChangeMessageVisibility]
readsPrec :: Int -> ReadS ChangeMessageVisibility
$creadsPrec :: Int -> ReadS ChangeMessageVisibility
Prelude.Read, Int -> ChangeMessageVisibility -> ShowS
[ChangeMessageVisibility] -> ShowS
ChangeMessageVisibility -> String
(Int -> ChangeMessageVisibility -> ShowS)
-> (ChangeMessageVisibility -> String)
-> ([ChangeMessageVisibility] -> ShowS)
-> Show ChangeMessageVisibility
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChangeMessageVisibility] -> ShowS
$cshowList :: [ChangeMessageVisibility] -> ShowS
show :: ChangeMessageVisibility -> String
$cshow :: ChangeMessageVisibility -> String
showsPrec :: Int -> ChangeMessageVisibility -> ShowS
$cshowsPrec :: Int -> ChangeMessageVisibility -> ShowS
Prelude.Show, (forall x.
 ChangeMessageVisibility -> Rep ChangeMessageVisibility x)
-> (forall x.
    Rep ChangeMessageVisibility x -> ChangeMessageVisibility)
-> Generic ChangeMessageVisibility
forall x. Rep ChangeMessageVisibility x -> ChangeMessageVisibility
forall x. ChangeMessageVisibility -> Rep ChangeMessageVisibility x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChangeMessageVisibility x -> ChangeMessageVisibility
$cfrom :: forall x. ChangeMessageVisibility -> Rep ChangeMessageVisibility x
Prelude.Generic)

-- |
-- Create a value of 'ChangeMessageVisibility' 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', 'changeMessageVisibility_queueUrl' - The URL of the Amazon SQS queue whose message\'s visibility is changed.
--
-- Queue URLs and names are case-sensitive.
--
-- 'receiptHandle', 'changeMessageVisibility_receiptHandle' - The receipt handle associated with the message whose visibility timeout
-- is changed. This parameter is returned by the @ ReceiveMessage @ action.
--
-- 'visibilityTimeout', 'changeMessageVisibility_visibilityTimeout' - The new value for the message\'s visibility timeout (in seconds). Values
-- range: @0@ to @43200@. Maximum: 12 hours.
newChangeMessageVisibility ::
  -- | 'queueUrl'
  Prelude.Text ->
  -- | 'receiptHandle'
  Prelude.Text ->
  -- | 'visibilityTimeout'
  Prelude.Int ->
  ChangeMessageVisibility
newChangeMessageVisibility :: Text -> Text -> Int -> ChangeMessageVisibility
newChangeMessageVisibility
  Text
pQueueUrl_
  Text
pReceiptHandle_
  Int
pVisibilityTimeout_ =
    ChangeMessageVisibility' :: Text -> Text -> Int -> ChangeMessageVisibility
ChangeMessageVisibility'
      { $sel:queueUrl:ChangeMessageVisibility' :: Text
queueUrl = Text
pQueueUrl_,
        $sel:receiptHandle:ChangeMessageVisibility' :: Text
receiptHandle = Text
pReceiptHandle_,
        $sel:visibilityTimeout:ChangeMessageVisibility' :: Int
visibilityTimeout = Int
pVisibilityTimeout_
      }

-- | The URL of the Amazon SQS queue whose message\'s visibility is changed.
--
-- Queue URLs and names are case-sensitive.
changeMessageVisibility_queueUrl :: Lens.Lens' ChangeMessageVisibility Prelude.Text
changeMessageVisibility_queueUrl :: (Text -> f Text)
-> ChangeMessageVisibility -> f ChangeMessageVisibility
changeMessageVisibility_queueUrl = (ChangeMessageVisibility -> Text)
-> (ChangeMessageVisibility -> Text -> ChangeMessageVisibility)
-> Lens ChangeMessageVisibility ChangeMessageVisibility Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangeMessageVisibility' {Text
queueUrl :: Text
$sel:queueUrl:ChangeMessageVisibility' :: ChangeMessageVisibility -> Text
queueUrl} -> Text
queueUrl) (\s :: ChangeMessageVisibility
s@ChangeMessageVisibility' {} Text
a -> ChangeMessageVisibility
s {$sel:queueUrl:ChangeMessageVisibility' :: Text
queueUrl = Text
a} :: ChangeMessageVisibility)

-- | The receipt handle associated with the message whose visibility timeout
-- is changed. This parameter is returned by the @ ReceiveMessage @ action.
changeMessageVisibility_receiptHandle :: Lens.Lens' ChangeMessageVisibility Prelude.Text
changeMessageVisibility_receiptHandle :: (Text -> f Text)
-> ChangeMessageVisibility -> f ChangeMessageVisibility
changeMessageVisibility_receiptHandle = (ChangeMessageVisibility -> Text)
-> (ChangeMessageVisibility -> Text -> ChangeMessageVisibility)
-> Lens ChangeMessageVisibility ChangeMessageVisibility Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangeMessageVisibility' {Text
receiptHandle :: Text
$sel:receiptHandle:ChangeMessageVisibility' :: ChangeMessageVisibility -> Text
receiptHandle} -> Text
receiptHandle) (\s :: ChangeMessageVisibility
s@ChangeMessageVisibility' {} Text
a -> ChangeMessageVisibility
s {$sel:receiptHandle:ChangeMessageVisibility' :: Text
receiptHandle = Text
a} :: ChangeMessageVisibility)

-- | The new value for the message\'s visibility timeout (in seconds). Values
-- range: @0@ to @43200@. Maximum: 12 hours.
changeMessageVisibility_visibilityTimeout :: Lens.Lens' ChangeMessageVisibility Prelude.Int
changeMessageVisibility_visibilityTimeout :: (Int -> f Int)
-> ChangeMessageVisibility -> f ChangeMessageVisibility
changeMessageVisibility_visibilityTimeout = (ChangeMessageVisibility -> Int)
-> (ChangeMessageVisibility -> Int -> ChangeMessageVisibility)
-> Lens ChangeMessageVisibility ChangeMessageVisibility Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangeMessageVisibility' {Int
visibilityTimeout :: Int
$sel:visibilityTimeout:ChangeMessageVisibility' :: ChangeMessageVisibility -> Int
visibilityTimeout} -> Int
visibilityTimeout) (\s :: ChangeMessageVisibility
s@ChangeMessageVisibility' {} Int
a -> ChangeMessageVisibility
s {$sel:visibilityTimeout:ChangeMessageVisibility' :: Int
visibilityTimeout = Int
a} :: ChangeMessageVisibility)

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

instance Prelude.Hashable ChangeMessageVisibility

instance Prelude.NFData ChangeMessageVisibility

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

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

instance Core.ToQuery ChangeMessageVisibility where
  toQuery :: ChangeMessageVisibility -> QueryString
toQuery ChangeMessageVisibility' {Int
Text
visibilityTimeout :: Int
receiptHandle :: Text
queueUrl :: Text
$sel:visibilityTimeout:ChangeMessageVisibility' :: ChangeMessageVisibility -> Int
$sel:receiptHandle:ChangeMessageVisibility' :: ChangeMessageVisibility -> Text
$sel:queueUrl:ChangeMessageVisibility' :: ChangeMessageVisibility -> 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
"ChangeMessageVisibility" :: 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,
        ByteString
"VisibilityTimeout" ByteString -> Int -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Int
visibilityTimeout
      ]

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

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

instance
  Prelude.NFData
    ChangeMessageVisibilityResponse