{-# 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.StreamSpecification
-- 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.StreamSpecification where

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.Types.StreamViewType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents the DynamoDB Streams configuration for a table in DynamoDB.
--
-- /See:/ 'newStreamSpecification' smart constructor.
data StreamSpecification = StreamSpecification'
  { -- | When an item in the table is modified, @StreamViewType@ determines what
    -- information is written to the stream for this table. Valid values for
    -- @StreamViewType@ are:
    --
    -- -   @KEYS_ONLY@ - Only the key attributes of the modified item are
    --     written to the stream.
    --
    -- -   @NEW_IMAGE@ - The entire item, as it appears after it was modified,
    --     is written to the stream.
    --
    -- -   @OLD_IMAGE@ - The entire item, as it appeared before it was
    --     modified, is written to the stream.
    --
    -- -   @NEW_AND_OLD_IMAGES@ - Both the new and the old item images of the
    --     item are written to the stream.
    StreamSpecification -> Maybe StreamViewType
streamViewType :: Prelude.Maybe StreamViewType,
    -- | Indicates whether DynamoDB Streams is enabled (true) or disabled (false)
    -- on the table.
    StreamSpecification -> Bool
streamEnabled :: Prelude.Bool
  }
  deriving (StreamSpecification -> StreamSpecification -> Bool
(StreamSpecification -> StreamSpecification -> Bool)
-> (StreamSpecification -> StreamSpecification -> Bool)
-> Eq StreamSpecification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StreamSpecification -> StreamSpecification -> Bool
$c/= :: StreamSpecification -> StreamSpecification -> Bool
== :: StreamSpecification -> StreamSpecification -> Bool
$c== :: StreamSpecification -> StreamSpecification -> Bool
Prelude.Eq, ReadPrec [StreamSpecification]
ReadPrec StreamSpecification
Int -> ReadS StreamSpecification
ReadS [StreamSpecification]
(Int -> ReadS StreamSpecification)
-> ReadS [StreamSpecification]
-> ReadPrec StreamSpecification
-> ReadPrec [StreamSpecification]
-> Read StreamSpecification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StreamSpecification]
$creadListPrec :: ReadPrec [StreamSpecification]
readPrec :: ReadPrec StreamSpecification
$creadPrec :: ReadPrec StreamSpecification
readList :: ReadS [StreamSpecification]
$creadList :: ReadS [StreamSpecification]
readsPrec :: Int -> ReadS StreamSpecification
$creadsPrec :: Int -> ReadS StreamSpecification
Prelude.Read, Int -> StreamSpecification -> ShowS
[StreamSpecification] -> ShowS
StreamSpecification -> String
(Int -> StreamSpecification -> ShowS)
-> (StreamSpecification -> String)
-> ([StreamSpecification] -> ShowS)
-> Show StreamSpecification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StreamSpecification] -> ShowS
$cshowList :: [StreamSpecification] -> ShowS
show :: StreamSpecification -> String
$cshow :: StreamSpecification -> String
showsPrec :: Int -> StreamSpecification -> ShowS
$cshowsPrec :: Int -> StreamSpecification -> ShowS
Prelude.Show, (forall x. StreamSpecification -> Rep StreamSpecification x)
-> (forall x. Rep StreamSpecification x -> StreamSpecification)
-> Generic StreamSpecification
forall x. Rep StreamSpecification x -> StreamSpecification
forall x. StreamSpecification -> Rep StreamSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StreamSpecification x -> StreamSpecification
$cfrom :: forall x. StreamSpecification -> Rep StreamSpecification x
Prelude.Generic)

-- |
-- Create a value of 'StreamSpecification' 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:
--
-- 'streamViewType', 'streamSpecification_streamViewType' - When an item in the table is modified, @StreamViewType@ determines what
-- information is written to the stream for this table. Valid values for
-- @StreamViewType@ are:
--
-- -   @KEYS_ONLY@ - Only the key attributes of the modified item are
--     written to the stream.
--
-- -   @NEW_IMAGE@ - The entire item, as it appears after it was modified,
--     is written to the stream.
--
-- -   @OLD_IMAGE@ - The entire item, as it appeared before it was
--     modified, is written to the stream.
--
-- -   @NEW_AND_OLD_IMAGES@ - Both the new and the old item images of the
--     item are written to the stream.
--
-- 'streamEnabled', 'streamSpecification_streamEnabled' - Indicates whether DynamoDB Streams is enabled (true) or disabled (false)
-- on the table.
newStreamSpecification ::
  -- | 'streamEnabled'
  Prelude.Bool ->
  StreamSpecification
newStreamSpecification :: Bool -> StreamSpecification
newStreamSpecification Bool
pStreamEnabled_ =
  StreamSpecification' :: Maybe StreamViewType -> Bool -> StreamSpecification
StreamSpecification'
    { $sel:streamViewType:StreamSpecification' :: Maybe StreamViewType
streamViewType =
        Maybe StreamViewType
forall a. Maybe a
Prelude.Nothing,
      $sel:streamEnabled:StreamSpecification' :: Bool
streamEnabled = Bool
pStreamEnabled_
    }

-- | When an item in the table is modified, @StreamViewType@ determines what
-- information is written to the stream for this table. Valid values for
-- @StreamViewType@ are:
--
-- -   @KEYS_ONLY@ - Only the key attributes of the modified item are
--     written to the stream.
--
-- -   @NEW_IMAGE@ - The entire item, as it appears after it was modified,
--     is written to the stream.
--
-- -   @OLD_IMAGE@ - The entire item, as it appeared before it was
--     modified, is written to the stream.
--
-- -   @NEW_AND_OLD_IMAGES@ - Both the new and the old item images of the
--     item are written to the stream.
streamSpecification_streamViewType :: Lens.Lens' StreamSpecification (Prelude.Maybe StreamViewType)
streamSpecification_streamViewType :: (Maybe StreamViewType -> f (Maybe StreamViewType))
-> StreamSpecification -> f StreamSpecification
streamSpecification_streamViewType = (StreamSpecification -> Maybe StreamViewType)
-> (StreamSpecification
    -> Maybe StreamViewType -> StreamSpecification)
-> Lens
     StreamSpecification
     StreamSpecification
     (Maybe StreamViewType)
     (Maybe StreamViewType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamSpecification' {Maybe StreamViewType
streamViewType :: Maybe StreamViewType
$sel:streamViewType:StreamSpecification' :: StreamSpecification -> Maybe StreamViewType
streamViewType} -> Maybe StreamViewType
streamViewType) (\s :: StreamSpecification
s@StreamSpecification' {} Maybe StreamViewType
a -> StreamSpecification
s {$sel:streamViewType:StreamSpecification' :: Maybe StreamViewType
streamViewType = Maybe StreamViewType
a} :: StreamSpecification)

-- | Indicates whether DynamoDB Streams is enabled (true) or disabled (false)
-- on the table.
streamSpecification_streamEnabled :: Lens.Lens' StreamSpecification Prelude.Bool
streamSpecification_streamEnabled :: (Bool -> f Bool) -> StreamSpecification -> f StreamSpecification
streamSpecification_streamEnabled = (StreamSpecification -> Bool)
-> (StreamSpecification -> Bool -> StreamSpecification)
-> Lens StreamSpecification StreamSpecification Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamSpecification' {Bool
streamEnabled :: Bool
$sel:streamEnabled:StreamSpecification' :: StreamSpecification -> Bool
streamEnabled} -> Bool
streamEnabled) (\s :: StreamSpecification
s@StreamSpecification' {} Bool
a -> StreamSpecification
s {$sel:streamEnabled:StreamSpecification' :: Bool
streamEnabled = Bool
a} :: StreamSpecification)

instance Core.FromJSON StreamSpecification where
  parseJSON :: Value -> Parser StreamSpecification
parseJSON =
    String
-> (Object -> Parser StreamSpecification)
-> Value
-> Parser StreamSpecification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"StreamSpecification"
      ( \Object
x ->
          Maybe StreamViewType -> Bool -> StreamSpecification
StreamSpecification'
            (Maybe StreamViewType -> Bool -> StreamSpecification)
-> Parser (Maybe StreamViewType)
-> Parser (Bool -> StreamSpecification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe StreamViewType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"StreamViewType")
            Parser (Bool -> StreamSpecification)
-> Parser Bool -> Parser StreamSpecification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"StreamEnabled")
      )

instance Prelude.Hashable StreamSpecification

instance Prelude.NFData StreamSpecification

instance Core.ToJSON StreamSpecification where
  toJSON :: StreamSpecification -> Value
toJSON StreamSpecification' {Bool
Maybe StreamViewType
streamEnabled :: Bool
streamViewType :: Maybe StreamViewType
$sel:streamEnabled:StreamSpecification' :: StreamSpecification -> Bool
$sel:streamViewType:StreamSpecification' :: StreamSpecification -> Maybe StreamViewType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"StreamViewType" Text -> StreamViewType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (StreamViewType -> Pair) -> Maybe StreamViewType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe StreamViewType
streamViewType,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"StreamEnabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
streamEnabled)
          ]
      )