{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.TimeToLiveSpecification
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DynamoDB.Types.TimeToLiveSpecification 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.AttributeValue
import Amazonka.DynamoDB.Types.WriteRequest
import qualified Amazonka.Prelude as Prelude

-- | Represents the settings used to enable or disable Time to Live (TTL) for
-- the specified table.
--
-- /See:/ 'newTimeToLiveSpecification' smart constructor.
data TimeToLiveSpecification = TimeToLiveSpecification'
  { -- | Indicates whether TTL is to be enabled (true) or disabled (false) on the
    -- table.
    TimeToLiveSpecification -> Bool
enabled :: Prelude.Bool,
    -- | The name of the TTL attribute used to store the expiration time for
    -- items in the table.
    TimeToLiveSpecification -> Text
attributeName :: Prelude.Text
  }
  deriving (TimeToLiveSpecification -> TimeToLiveSpecification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeToLiveSpecification -> TimeToLiveSpecification -> Bool
$c/= :: TimeToLiveSpecification -> TimeToLiveSpecification -> Bool
== :: TimeToLiveSpecification -> TimeToLiveSpecification -> Bool
$c== :: TimeToLiveSpecification -> TimeToLiveSpecification -> Bool
Prelude.Eq, ReadPrec [TimeToLiveSpecification]
ReadPrec TimeToLiveSpecification
Int -> ReadS TimeToLiveSpecification
ReadS [TimeToLiveSpecification]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimeToLiveSpecification]
$creadListPrec :: ReadPrec [TimeToLiveSpecification]
readPrec :: ReadPrec TimeToLiveSpecification
$creadPrec :: ReadPrec TimeToLiveSpecification
readList :: ReadS [TimeToLiveSpecification]
$creadList :: ReadS [TimeToLiveSpecification]
readsPrec :: Int -> ReadS TimeToLiveSpecification
$creadsPrec :: Int -> ReadS TimeToLiveSpecification
Prelude.Read, Int -> TimeToLiveSpecification -> ShowS
[TimeToLiveSpecification] -> ShowS
TimeToLiveSpecification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimeToLiveSpecification] -> ShowS
$cshowList :: [TimeToLiveSpecification] -> ShowS
show :: TimeToLiveSpecification -> String
$cshow :: TimeToLiveSpecification -> String
showsPrec :: Int -> TimeToLiveSpecification -> ShowS
$cshowsPrec :: Int -> TimeToLiveSpecification -> ShowS
Prelude.Show, forall x. Rep TimeToLiveSpecification x -> TimeToLiveSpecification
forall x. TimeToLiveSpecification -> Rep TimeToLiveSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimeToLiveSpecification x -> TimeToLiveSpecification
$cfrom :: forall x. TimeToLiveSpecification -> Rep TimeToLiveSpecification x
Prelude.Generic)

-- |
-- Create a value of 'TimeToLiveSpecification' 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:
--
-- 'enabled', 'timeToLiveSpecification_enabled' - Indicates whether TTL is to be enabled (true) or disabled (false) on the
-- table.
--
-- 'attributeName', 'timeToLiveSpecification_attributeName' - The name of the TTL attribute used to store the expiration time for
-- items in the table.
newTimeToLiveSpecification ::
  -- | 'enabled'
  Prelude.Bool ->
  -- | 'attributeName'
  Prelude.Text ->
  TimeToLiveSpecification
newTimeToLiveSpecification :: Bool -> Text -> TimeToLiveSpecification
newTimeToLiveSpecification Bool
pEnabled_ Text
pAttributeName_ =
  TimeToLiveSpecification'
    { $sel:enabled:TimeToLiveSpecification' :: Bool
enabled = Bool
pEnabled_,
      $sel:attributeName:TimeToLiveSpecification' :: Text
attributeName = Text
pAttributeName_
    }

-- | Indicates whether TTL is to be enabled (true) or disabled (false) on the
-- table.
timeToLiveSpecification_enabled :: Lens.Lens' TimeToLiveSpecification Prelude.Bool
timeToLiveSpecification_enabled :: Lens' TimeToLiveSpecification Bool
timeToLiveSpecification_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeToLiveSpecification' {Bool
enabled :: Bool
$sel:enabled:TimeToLiveSpecification' :: TimeToLiveSpecification -> Bool
enabled} -> Bool
enabled) (\s :: TimeToLiveSpecification
s@TimeToLiveSpecification' {} Bool
a -> TimeToLiveSpecification
s {$sel:enabled:TimeToLiveSpecification' :: Bool
enabled = Bool
a} :: TimeToLiveSpecification)

-- | The name of the TTL attribute used to store the expiration time for
-- items in the table.
timeToLiveSpecification_attributeName :: Lens.Lens' TimeToLiveSpecification Prelude.Text
timeToLiveSpecification_attributeName :: Lens' TimeToLiveSpecification Text
timeToLiveSpecification_attributeName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeToLiveSpecification' {Text
attributeName :: Text
$sel:attributeName:TimeToLiveSpecification' :: TimeToLiveSpecification -> Text
attributeName} -> Text
attributeName) (\s :: TimeToLiveSpecification
s@TimeToLiveSpecification' {} Text
a -> TimeToLiveSpecification
s {$sel:attributeName:TimeToLiveSpecification' :: Text
attributeName = Text
a} :: TimeToLiveSpecification)

instance Data.FromJSON TimeToLiveSpecification where
  parseJSON :: Value -> Parser TimeToLiveSpecification
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TimeToLiveSpecification"
      ( \Object
x ->
          Bool -> Text -> TimeToLiveSpecification
TimeToLiveSpecification'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Enabled")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"AttributeName")
      )

instance Prelude.Hashable TimeToLiveSpecification where
  hashWithSalt :: Int -> TimeToLiveSpecification -> Int
hashWithSalt Int
_salt TimeToLiveSpecification' {Bool
Text
attributeName :: Text
enabled :: Bool
$sel:attributeName:TimeToLiveSpecification' :: TimeToLiveSpecification -> Text
$sel:enabled:TimeToLiveSpecification' :: TimeToLiveSpecification -> Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
attributeName

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

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