{-# 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-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)
module Amazonka.DynamoDB.Types.TimeToLiveSpecification where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(TimeToLiveSpecification -> TimeToLiveSpecification -> Bool)
-> (TimeToLiveSpecification -> TimeToLiveSpecification -> Bool)
-> Eq TimeToLiveSpecification
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]
(Int -> ReadS TimeToLiveSpecification)
-> ReadS [TimeToLiveSpecification]
-> ReadPrec TimeToLiveSpecification
-> ReadPrec [TimeToLiveSpecification]
-> Read 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
(Int -> TimeToLiveSpecification -> ShowS)
-> (TimeToLiveSpecification -> String)
-> ([TimeToLiveSpecification] -> ShowS)
-> Show TimeToLiveSpecification
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.
 TimeToLiveSpecification -> Rep TimeToLiveSpecification x)
-> (forall x.
    Rep TimeToLiveSpecification x -> TimeToLiveSpecification)
-> Generic TimeToLiveSpecification
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' :: Bool -> Text -> TimeToLiveSpecification
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 :: (Bool -> f Bool)
-> TimeToLiveSpecification -> f TimeToLiveSpecification
timeToLiveSpecification_enabled = (TimeToLiveSpecification -> Bool)
-> (TimeToLiveSpecification -> Bool -> TimeToLiveSpecification)
-> Lens TimeToLiveSpecification TimeToLiveSpecification Bool Bool
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 :: (Text -> f Text)
-> TimeToLiveSpecification -> f TimeToLiveSpecification
timeToLiveSpecification_attributeName = (TimeToLiveSpecification -> Text)
-> (TimeToLiveSpecification -> Text -> TimeToLiveSpecification)
-> Lens TimeToLiveSpecification TimeToLiveSpecification Text Text
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 Core.FromJSON TimeToLiveSpecification where
  parseJSON :: Value -> Parser TimeToLiveSpecification
parseJSON =
    String
-> (Object -> Parser TimeToLiveSpecification)
-> Value
-> Parser TimeToLiveSpecification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimeToLiveSpecification"
      ( \Object
x ->
          Bool -> Text -> TimeToLiveSpecification
TimeToLiveSpecification'
            (Bool -> Text -> TimeToLiveSpecification)
-> Parser Bool -> Parser (Text -> TimeToLiveSpecification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Enabled")
            Parser (Text -> TimeToLiveSpecification)
-> Parser Text -> Parser TimeToLiveSpecification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AttributeName")
      )

instance Prelude.Hashable TimeToLiveSpecification

instance Prelude.NFData TimeToLiveSpecification

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Enabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
enabled),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AttributeName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attributeName)
          ]
      )