{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Glue.Types.EventBatchingCondition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:batchWindow:EventBatchingCondition' :: Maybe Natural
batchWindow =
        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 :: Lens' EventBatchingCondition (Maybe Natural)
eventBatchingCondition_batchWindow = 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 :: Lens' EventBatchingCondition Natural
eventBatchingCondition_batchSize = 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 Data.FromJSON EventBatchingCondition where
  parseJSON :: Value -> Parser EventBatchingCondition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EventBatchingCondition"
      ( \Object
x ->
          Maybe Natural -> Natural -> EventBatchingCondition
EventBatchingCondition'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"BatchWindow")
            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
"BatchSize")
      )

instance Prelude.Hashable EventBatchingCondition where
  hashWithSalt :: Int -> EventBatchingCondition -> Int
hashWithSalt Int
_salt EventBatchingCondition' {Natural
Maybe Natural
batchSize :: Natural
batchWindow :: Maybe Natural
$sel:batchSize:EventBatchingCondition' :: EventBatchingCondition -> Natural
$sel:batchWindow:EventBatchingCondition' :: EventBatchingCondition -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
batchWindow
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
batchSize

instance Prelude.NFData EventBatchingCondition where
  rnf :: EventBatchingCondition -> ()
rnf EventBatchingCondition' {Natural
Maybe Natural
batchSize :: Natural
batchWindow :: Maybe Natural
$sel:batchSize:EventBatchingCondition' :: EventBatchingCondition -> Natural
$sel:batchWindow:EventBatchingCondition' :: EventBatchingCondition -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
batchWindow
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
batchSize

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"BatchWindow" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
batchWindow,
            forall a. a -> Maybe a
Prelude.Just (Key
"BatchSize" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
batchSize)
          ]
      )