{-# 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.Glue.Types.EventBatchingCondition
-- 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.Glue.Types.EventBatchingCondition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Batch condition that must be met (specified number of events received or
-- batch time window expired) before EventBridge event trigger fires.
--
-- /See:/ 'newEventBatchingCondition' smart constructor.
data EventBatchingCondition = EventBatchingCondition'
  { -- | Window of time in seconds after which EventBridge event trigger fires.
    -- Window starts when first event is received.
    EventBatchingCondition -> Maybe Natural
batchWindow :: Prelude.Maybe Prelude.Natural,
    -- | Number of events that must be received from Amazon EventBridge before
    -- EventBridge event trigger fires.
    EventBatchingCondition -> Natural
batchSize :: Prelude.Natural
  }
  deriving (EventBatchingCondition -> EventBatchingCondition -> Bool
(EventBatchingCondition -> EventBatchingCondition -> Bool)
-> (EventBatchingCondition -> EventBatchingCondition -> Bool)
-> Eq EventBatchingCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventBatchingCondition -> EventBatchingCondition -> Bool
$c/= :: EventBatchingCondition -> EventBatchingCondition -> Bool
== :: EventBatchingCondition -> EventBatchingCondition -> Bool
$c== :: EventBatchingCondition -> EventBatchingCondition -> Bool
Prelude.Eq, ReadPrec [EventBatchingCondition]
ReadPrec EventBatchingCondition
Int -> ReadS EventBatchingCondition
ReadS [EventBatchingCondition]
(Int -> ReadS EventBatchingCondition)
-> ReadS [EventBatchingCondition]
-> ReadPrec EventBatchingCondition
-> ReadPrec [EventBatchingCondition]
-> Read EventBatchingCondition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventBatchingCondition]
$creadListPrec :: ReadPrec [EventBatchingCondition]
readPrec :: ReadPrec EventBatchingCondition
$creadPrec :: ReadPrec EventBatchingCondition
readList :: ReadS [EventBatchingCondition]
$creadList :: ReadS [EventBatchingCondition]
readsPrec :: Int -> ReadS EventBatchingCondition
$creadsPrec :: Int -> ReadS EventBatchingCondition
Prelude.Read, Int -> EventBatchingCondition -> ShowS
[EventBatchingCondition] -> ShowS
EventBatchingCondition -> String
(Int -> EventBatchingCondition -> ShowS)
-> (EventBatchingCondition -> String)
-> ([EventBatchingCondition] -> ShowS)
-> Show EventBatchingCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventBatchingCondition] -> ShowS
$cshowList :: [EventBatchingCondition] -> ShowS
show :: EventBatchingCondition -> String
$cshow :: EventBatchingCondition -> String
showsPrec :: Int -> EventBatchingCondition -> ShowS
$cshowsPrec :: Int -> EventBatchingCondition -> ShowS
Prelude.Show, (forall x. EventBatchingCondition -> Rep EventBatchingCondition x)
-> (forall x.
    Rep EventBatchingCondition x -> EventBatchingCondition)
-> Generic EventBatchingCondition
forall x. Rep EventBatchingCondition x -> EventBatchingCondition
forall x. EventBatchingCondition -> Rep EventBatchingCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventBatchingCondition x -> EventBatchingCondition
$cfrom :: forall x. EventBatchingCondition -> Rep EventBatchingCondition x
Prelude.Generic)

-- |
-- Create a value of 'EventBatchingCondition' 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:
--
-- 'batchWindow', 'eventBatchingCondition_batchWindow' - Window of time in seconds after which EventBridge event trigger fires.
-- Window starts when first event is received.
--
-- 'batchSize', 'eventBatchingCondition_batchSize' - Number of events that must be received from Amazon EventBridge before
-- EventBridge event trigger fires.
newEventBatchingCondition ::
  -- | 'batchSize'
  Prelude.Natural ->
  EventBatchingCondition
newEventBatchingCondition :: Natural -> EventBatchingCondition
newEventBatchingCondition Natural
pBatchSize_ =
  EventBatchingCondition' :: Maybe Natural -> Natural -> EventBatchingCondition
EventBatchingCondition'
    { $sel:batchWindow:EventBatchingCondition' :: Maybe Natural
batchWindow =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:batchSize:EventBatchingCondition' :: Natural
batchSize = Natural
pBatchSize_
    }

-- | Window of time in seconds after which EventBridge event trigger fires.
-- Window starts when first event is received.
eventBatchingCondition_batchWindow :: Lens.Lens' EventBatchingCondition (Prelude.Maybe Prelude.Natural)
eventBatchingCondition_batchWindow :: (Maybe Natural -> f (Maybe Natural))
-> EventBatchingCondition -> f EventBatchingCondition
eventBatchingCondition_batchWindow = (EventBatchingCondition -> Maybe Natural)
-> (EventBatchingCondition
    -> Maybe Natural -> EventBatchingCondition)
-> Lens
     EventBatchingCondition
     EventBatchingCondition
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventBatchingCondition' {Maybe Natural
batchWindow :: Maybe Natural
$sel:batchWindow:EventBatchingCondition' :: EventBatchingCondition -> Maybe Natural
batchWindow} -> Maybe Natural
batchWindow) (\s :: EventBatchingCondition
s@EventBatchingCondition' {} Maybe Natural
a -> EventBatchingCondition
s {$sel:batchWindow:EventBatchingCondition' :: Maybe Natural
batchWindow = Maybe Natural
a} :: EventBatchingCondition)

-- | Number of events that must be received from Amazon EventBridge before
-- EventBridge event trigger fires.
eventBatchingCondition_batchSize :: Lens.Lens' EventBatchingCondition Prelude.Natural
eventBatchingCondition_batchSize :: (Natural -> f Natural)
-> EventBatchingCondition -> f EventBatchingCondition
eventBatchingCondition_batchSize = (EventBatchingCondition -> Natural)
-> (EventBatchingCondition -> Natural -> EventBatchingCondition)
-> Lens
     EventBatchingCondition EventBatchingCondition Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventBatchingCondition' {Natural
batchSize :: Natural
$sel:batchSize:EventBatchingCondition' :: EventBatchingCondition -> Natural
batchSize} -> Natural
batchSize) (\s :: EventBatchingCondition
s@EventBatchingCondition' {} Natural
a -> EventBatchingCondition
s {$sel:batchSize:EventBatchingCondition' :: Natural
batchSize = Natural
a} :: EventBatchingCondition)

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

instance Prelude.Hashable EventBatchingCondition

instance Prelude.NFData EventBatchingCondition

instance Core.ToJSON EventBatchingCondition where
  toJSON :: EventBatchingCondition -> Value
toJSON EventBatchingCondition' {Natural
Maybe Natural
batchSize :: Natural
batchWindow :: Maybe Natural
$sel:batchSize:EventBatchingCondition' :: EventBatchingCondition -> Natural
$sel:batchWindow:EventBatchingCondition' :: EventBatchingCondition -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"BatchWindow" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
batchWindow,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"BatchSize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
batchSize)
          ]
      )