{-# 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.Pinpoint.Types.EventFilter
-- 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.Pinpoint.Types.EventFilter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.EventDimensions
import Amazonka.Pinpoint.Types.FilterType
import qualified Amazonka.Prelude as Prelude

-- | Specifies the settings for an event that causes a campaign to be sent or
-- a journey activity to be performed.
--
-- /See:/ 'newEventFilter' smart constructor.
data EventFilter = EventFilter'
  { -- | The type of event that causes the campaign to be sent or the journey
    -- activity to be performed. Valid values are: SYSTEM, sends the campaign
    -- or performs the activity when a system event occurs; and, ENDPOINT,
    -- sends the campaign or performs the activity when an endpoint event
    -- (Events resource) occurs.
    EventFilter -> FilterType
filterType :: FilterType,
    -- | The dimensions for the event filter to use for the campaign or the
    -- journey activity.
    EventFilter -> EventDimensions
dimensions :: EventDimensions
  }
  deriving (EventFilter -> EventFilter -> Bool
(EventFilter -> EventFilter -> Bool)
-> (EventFilter -> EventFilter -> Bool) -> Eq EventFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventFilter -> EventFilter -> Bool
$c/= :: EventFilter -> EventFilter -> Bool
== :: EventFilter -> EventFilter -> Bool
$c== :: EventFilter -> EventFilter -> Bool
Prelude.Eq, ReadPrec [EventFilter]
ReadPrec EventFilter
Int -> ReadS EventFilter
ReadS [EventFilter]
(Int -> ReadS EventFilter)
-> ReadS [EventFilter]
-> ReadPrec EventFilter
-> ReadPrec [EventFilter]
-> Read EventFilter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventFilter]
$creadListPrec :: ReadPrec [EventFilter]
readPrec :: ReadPrec EventFilter
$creadPrec :: ReadPrec EventFilter
readList :: ReadS [EventFilter]
$creadList :: ReadS [EventFilter]
readsPrec :: Int -> ReadS EventFilter
$creadsPrec :: Int -> ReadS EventFilter
Prelude.Read, Int -> EventFilter -> ShowS
[EventFilter] -> ShowS
EventFilter -> String
(Int -> EventFilter -> ShowS)
-> (EventFilter -> String)
-> ([EventFilter] -> ShowS)
-> Show EventFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventFilter] -> ShowS
$cshowList :: [EventFilter] -> ShowS
show :: EventFilter -> String
$cshow :: EventFilter -> String
showsPrec :: Int -> EventFilter -> ShowS
$cshowsPrec :: Int -> EventFilter -> ShowS
Prelude.Show, (forall x. EventFilter -> Rep EventFilter x)
-> (forall x. Rep EventFilter x -> EventFilter)
-> Generic EventFilter
forall x. Rep EventFilter x -> EventFilter
forall x. EventFilter -> Rep EventFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventFilter x -> EventFilter
$cfrom :: forall x. EventFilter -> Rep EventFilter x
Prelude.Generic)

-- |
-- Create a value of 'EventFilter' 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:
--
-- 'filterType', 'eventFilter_filterType' - The type of event that causes the campaign to be sent or the journey
-- activity to be performed. Valid values are: SYSTEM, sends the campaign
-- or performs the activity when a system event occurs; and, ENDPOINT,
-- sends the campaign or performs the activity when an endpoint event
-- (Events resource) occurs.
--
-- 'dimensions', 'eventFilter_dimensions' - The dimensions for the event filter to use for the campaign or the
-- journey activity.
newEventFilter ::
  -- | 'filterType'
  FilterType ->
  -- | 'dimensions'
  EventDimensions ->
  EventFilter
newEventFilter :: FilterType -> EventDimensions -> EventFilter
newEventFilter FilterType
pFilterType_ EventDimensions
pDimensions_ =
  EventFilter' :: FilterType -> EventDimensions -> EventFilter
EventFilter'
    { $sel:filterType:EventFilter' :: FilterType
filterType = FilterType
pFilterType_,
      $sel:dimensions:EventFilter' :: EventDimensions
dimensions = EventDimensions
pDimensions_
    }

-- | The type of event that causes the campaign to be sent or the journey
-- activity to be performed. Valid values are: SYSTEM, sends the campaign
-- or performs the activity when a system event occurs; and, ENDPOINT,
-- sends the campaign or performs the activity when an endpoint event
-- (Events resource) occurs.
eventFilter_filterType :: Lens.Lens' EventFilter FilterType
eventFilter_filterType :: (FilterType -> f FilterType) -> EventFilter -> f EventFilter
eventFilter_filterType = (EventFilter -> FilterType)
-> (EventFilter -> FilterType -> EventFilter)
-> Lens EventFilter EventFilter FilterType FilterType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventFilter' {FilterType
filterType :: FilterType
$sel:filterType:EventFilter' :: EventFilter -> FilterType
filterType} -> FilterType
filterType) (\s :: EventFilter
s@EventFilter' {} FilterType
a -> EventFilter
s {$sel:filterType:EventFilter' :: FilterType
filterType = FilterType
a} :: EventFilter)

-- | The dimensions for the event filter to use for the campaign or the
-- journey activity.
eventFilter_dimensions :: Lens.Lens' EventFilter EventDimensions
eventFilter_dimensions :: (EventDimensions -> f EventDimensions)
-> EventFilter -> f EventFilter
eventFilter_dimensions = (EventFilter -> EventDimensions)
-> (EventFilter -> EventDimensions -> EventFilter)
-> Lens EventFilter EventFilter EventDimensions EventDimensions
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventFilter' {EventDimensions
dimensions :: EventDimensions
$sel:dimensions:EventFilter' :: EventFilter -> EventDimensions
dimensions} -> EventDimensions
dimensions) (\s :: EventFilter
s@EventFilter' {} EventDimensions
a -> EventFilter
s {$sel:dimensions:EventFilter' :: EventDimensions
dimensions = EventDimensions
a} :: EventFilter)

instance Core.FromJSON EventFilter where
  parseJSON :: Value -> Parser EventFilter
parseJSON =
    String
-> (Object -> Parser EventFilter) -> Value -> Parser EventFilter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EventFilter"
      ( \Object
x ->
          FilterType -> EventDimensions -> EventFilter
EventFilter'
            (FilterType -> EventDimensions -> EventFilter)
-> Parser FilterType -> Parser (EventDimensions -> EventFilter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser FilterType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"FilterType")
            Parser (EventDimensions -> EventFilter)
-> Parser EventDimensions -> Parser EventFilter
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EventDimensions
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Dimensions")
      )

instance Prelude.Hashable EventFilter

instance Prelude.NFData EventFilter

instance Core.ToJSON EventFilter where
  toJSON :: EventFilter -> Value
toJSON EventFilter' {FilterType
EventDimensions
dimensions :: EventDimensions
filterType :: FilterType
$sel:dimensions:EventFilter' :: EventFilter -> EventDimensions
$sel:filterType:EventFilter' :: EventFilter -> FilterType
..} =
    [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
"FilterType" Text -> FilterType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= FilterType
filterType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Dimensions" Text -> EventDimensions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EventDimensions
dimensions)
          ]
      )