{-# 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.DynamoDB.UpdateTimeToLive
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- The @UpdateTimeToLive@ method enables or disables Time to Live (TTL) for
-- the specified table. A successful @UpdateTimeToLive@ call returns the
-- current @TimeToLiveSpecification@. It can take up to one hour for the
-- change to fully process. Any additional @UpdateTimeToLive@ calls for the
-- same table during this one hour duration result in a
-- @ValidationException@.
--
-- TTL compares the current time in epoch time format to the time stored in
-- the TTL attribute of an item. If the epoch time value stored in the
-- attribute is less than the current time, the item is marked as expired
-- and subsequently deleted.
--
-- The epoch time format is the number of seconds elapsed since 12:00:00 AM
-- January 1, 1970 UTC.
--
-- DynamoDB deletes expired items on a best-effort basis to ensure
-- availability of throughput for other data operations.
--
-- DynamoDB typically deletes expired items within two days of expiration.
-- The exact duration within which an item gets deleted after expiration is
-- specific to the nature of the workload. Items that have expired and not
-- been deleted will still show up in reads, queries, and scans.
--
-- As items are deleted, they are removed from any local secondary index
-- and global secondary index immediately in the same eventually consistent
-- way as a standard delete operation.
--
-- For more information, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html Time To Live>
-- in the Amazon DynamoDB Developer Guide.
module Amazonka.DynamoDB.UpdateTimeToLive
  ( -- * Creating a Request
    UpdateTimeToLive (..),
    newUpdateTimeToLive,

    -- * Request Lenses
    updateTimeToLive_tableName,
    updateTimeToLive_timeToLiveSpecification,

    -- * Destructuring the Response
    UpdateTimeToLiveResponse (..),
    newUpdateTimeToLiveResponse,

    -- * Response Lenses
    updateTimeToLiveResponse_timeToLiveSpecification,
    updateTimeToLiveResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DynamoDB.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents the input of an @UpdateTimeToLive@ operation.
--
-- /See:/ 'newUpdateTimeToLive' smart constructor.
data UpdateTimeToLive = UpdateTimeToLive'
  { -- | The name of the table to be configured.
    UpdateTimeToLive -> Text
tableName :: Prelude.Text,
    -- | Represents the settings used to enable or disable Time to Live for the
    -- specified table.
    UpdateTimeToLive -> TimeToLiveSpecification
timeToLiveSpecification :: TimeToLiveSpecification
  }
  deriving (UpdateTimeToLive -> UpdateTimeToLive -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateTimeToLive -> UpdateTimeToLive -> Bool
$c/= :: UpdateTimeToLive -> UpdateTimeToLive -> Bool
== :: UpdateTimeToLive -> UpdateTimeToLive -> Bool
$c== :: UpdateTimeToLive -> UpdateTimeToLive -> Bool
Prelude.Eq, ReadPrec [UpdateTimeToLive]
ReadPrec UpdateTimeToLive
Int -> ReadS UpdateTimeToLive
ReadS [UpdateTimeToLive]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateTimeToLive]
$creadListPrec :: ReadPrec [UpdateTimeToLive]
readPrec :: ReadPrec UpdateTimeToLive
$creadPrec :: ReadPrec UpdateTimeToLive
readList :: ReadS [UpdateTimeToLive]
$creadList :: ReadS [UpdateTimeToLive]
readsPrec :: Int -> ReadS UpdateTimeToLive
$creadsPrec :: Int -> ReadS UpdateTimeToLive
Prelude.Read, Int -> UpdateTimeToLive -> ShowS
[UpdateTimeToLive] -> ShowS
UpdateTimeToLive -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateTimeToLive] -> ShowS
$cshowList :: [UpdateTimeToLive] -> ShowS
show :: UpdateTimeToLive -> String
$cshow :: UpdateTimeToLive -> String
showsPrec :: Int -> UpdateTimeToLive -> ShowS
$cshowsPrec :: Int -> UpdateTimeToLive -> ShowS
Prelude.Show, forall x. Rep UpdateTimeToLive x -> UpdateTimeToLive
forall x. UpdateTimeToLive -> Rep UpdateTimeToLive x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateTimeToLive x -> UpdateTimeToLive
$cfrom :: forall x. UpdateTimeToLive -> Rep UpdateTimeToLive x
Prelude.Generic)

-- |
-- Create a value of 'UpdateTimeToLive' 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:
--
-- 'tableName', 'updateTimeToLive_tableName' - The name of the table to be configured.
--
-- 'timeToLiveSpecification', 'updateTimeToLive_timeToLiveSpecification' - Represents the settings used to enable or disable Time to Live for the
-- specified table.
newUpdateTimeToLive ::
  -- | 'tableName'
  Prelude.Text ->
  -- | 'timeToLiveSpecification'
  TimeToLiveSpecification ->
  UpdateTimeToLive
newUpdateTimeToLive :: Text -> TimeToLiveSpecification -> UpdateTimeToLive
newUpdateTimeToLive
  Text
pTableName_
  TimeToLiveSpecification
pTimeToLiveSpecification_ =
    UpdateTimeToLive'
      { $sel:tableName:UpdateTimeToLive' :: Text
tableName = Text
pTableName_,
        $sel:timeToLiveSpecification:UpdateTimeToLive' :: TimeToLiveSpecification
timeToLiveSpecification = TimeToLiveSpecification
pTimeToLiveSpecification_
      }

-- | The name of the table to be configured.
updateTimeToLive_tableName :: Lens.Lens' UpdateTimeToLive Prelude.Text
updateTimeToLive_tableName :: Lens' UpdateTimeToLive Text
updateTimeToLive_tableName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTimeToLive' {Text
tableName :: Text
$sel:tableName:UpdateTimeToLive' :: UpdateTimeToLive -> Text
tableName} -> Text
tableName) (\s :: UpdateTimeToLive
s@UpdateTimeToLive' {} Text
a -> UpdateTimeToLive
s {$sel:tableName:UpdateTimeToLive' :: Text
tableName = Text
a} :: UpdateTimeToLive)

-- | Represents the settings used to enable or disable Time to Live for the
-- specified table.
updateTimeToLive_timeToLiveSpecification :: Lens.Lens' UpdateTimeToLive TimeToLiveSpecification
updateTimeToLive_timeToLiveSpecification :: Lens' UpdateTimeToLive TimeToLiveSpecification
updateTimeToLive_timeToLiveSpecification = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTimeToLive' {TimeToLiveSpecification
timeToLiveSpecification :: TimeToLiveSpecification
$sel:timeToLiveSpecification:UpdateTimeToLive' :: UpdateTimeToLive -> TimeToLiveSpecification
timeToLiveSpecification} -> TimeToLiveSpecification
timeToLiveSpecification) (\s :: UpdateTimeToLive
s@UpdateTimeToLive' {} TimeToLiveSpecification
a -> UpdateTimeToLive
s {$sel:timeToLiveSpecification:UpdateTimeToLive' :: TimeToLiveSpecification
timeToLiveSpecification = TimeToLiveSpecification
a} :: UpdateTimeToLive)

instance Core.AWSRequest UpdateTimeToLive where
  type
    AWSResponse UpdateTimeToLive =
      UpdateTimeToLiveResponse
  request :: (Service -> Service)
-> UpdateTimeToLive -> Request UpdateTimeToLive
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateTimeToLive
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateTimeToLive)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe TimeToLiveSpecification -> Int -> UpdateTimeToLiveResponse
UpdateTimeToLiveResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"TimeToLiveSpecification")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UpdateTimeToLive where
  hashWithSalt :: Int -> UpdateTimeToLive -> Int
hashWithSalt Int
_salt UpdateTimeToLive' {Text
TimeToLiveSpecification
timeToLiveSpecification :: TimeToLiveSpecification
tableName :: Text
$sel:timeToLiveSpecification:UpdateTimeToLive' :: UpdateTimeToLive -> TimeToLiveSpecification
$sel:tableName:UpdateTimeToLive' :: UpdateTimeToLive -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
tableName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` TimeToLiveSpecification
timeToLiveSpecification

instance Prelude.NFData UpdateTimeToLive where
  rnf :: UpdateTimeToLive -> ()
rnf UpdateTimeToLive' {Text
TimeToLiveSpecification
timeToLiveSpecification :: TimeToLiveSpecification
tableName :: Text
$sel:timeToLiveSpecification:UpdateTimeToLive' :: UpdateTimeToLive -> TimeToLiveSpecification
$sel:tableName:UpdateTimeToLive' :: UpdateTimeToLive -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
tableName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf TimeToLiveSpecification
timeToLiveSpecification

instance Data.ToHeaders UpdateTimeToLive where
  toHeaders :: UpdateTimeToLive -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"DynamoDB_20120810.UpdateTimeToLive" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON UpdateTimeToLive where
  toJSON :: UpdateTimeToLive -> Value
toJSON UpdateTimeToLive' {Text
TimeToLiveSpecification
timeToLiveSpecification :: TimeToLiveSpecification
tableName :: Text
$sel:timeToLiveSpecification:UpdateTimeToLive' :: UpdateTimeToLive -> TimeToLiveSpecification
$sel:tableName:UpdateTimeToLive' :: UpdateTimeToLive -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"TableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
tableName),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"TimeToLiveSpecification"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= TimeToLiveSpecification
timeToLiveSpecification
              )
          ]
      )

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

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

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

-- |
-- Create a value of 'UpdateTimeToLiveResponse' 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:
--
-- 'timeToLiveSpecification', 'updateTimeToLiveResponse_timeToLiveSpecification' - Represents the output of an @UpdateTimeToLive@ operation.
--
-- 'httpStatus', 'updateTimeToLiveResponse_httpStatus' - The response's http status code.
newUpdateTimeToLiveResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateTimeToLiveResponse
newUpdateTimeToLiveResponse :: Int -> UpdateTimeToLiveResponse
newUpdateTimeToLiveResponse Int
pHttpStatus_ =
  UpdateTimeToLiveResponse'
    { $sel:timeToLiveSpecification:UpdateTimeToLiveResponse' :: Maybe TimeToLiveSpecification
timeToLiveSpecification =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateTimeToLiveResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Represents the output of an @UpdateTimeToLive@ operation.
updateTimeToLiveResponse_timeToLiveSpecification :: Lens.Lens' UpdateTimeToLiveResponse (Prelude.Maybe TimeToLiveSpecification)
updateTimeToLiveResponse_timeToLiveSpecification :: Lens' UpdateTimeToLiveResponse (Maybe TimeToLiveSpecification)
updateTimeToLiveResponse_timeToLiveSpecification = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTimeToLiveResponse' {Maybe TimeToLiveSpecification
timeToLiveSpecification :: Maybe TimeToLiveSpecification
$sel:timeToLiveSpecification:UpdateTimeToLiveResponse' :: UpdateTimeToLiveResponse -> Maybe TimeToLiveSpecification
timeToLiveSpecification} -> Maybe TimeToLiveSpecification
timeToLiveSpecification) (\s :: UpdateTimeToLiveResponse
s@UpdateTimeToLiveResponse' {} Maybe TimeToLiveSpecification
a -> UpdateTimeToLiveResponse
s {$sel:timeToLiveSpecification:UpdateTimeToLiveResponse' :: Maybe TimeToLiveSpecification
timeToLiveSpecification = Maybe TimeToLiveSpecification
a} :: UpdateTimeToLiveResponse)

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

instance Prelude.NFData UpdateTimeToLiveResponse where
  rnf :: UpdateTimeToLiveResponse -> ()
rnf UpdateTimeToLiveResponse' {Int
Maybe TimeToLiveSpecification
httpStatus :: Int
timeToLiveSpecification :: Maybe TimeToLiveSpecification
$sel:httpStatus:UpdateTimeToLiveResponse' :: UpdateTimeToLiveResponse -> Int
$sel:timeToLiveSpecification:UpdateTimeToLiveResponse' :: UpdateTimeToLiveResponse -> Maybe TimeToLiveSpecification
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe TimeToLiveSpecification
timeToLiveSpecification
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus