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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Pinpoint.Types.EventDimensions
import qualified Amazonka.Prelude as Prelude

-- | Specifies the conditions to evaluate for an event that applies to an
-- activity in a journey.
--
-- /See:/ 'newEventCondition' smart constructor.
data EventCondition = EventCondition'
  { -- | The dimensions for the event filter to use for the activity.
    EventCondition -> Maybe EventDimensions
dimensions :: Prelude.Maybe EventDimensions,
    -- | The message identifier (message_id) for the message to use when
    -- determining whether message events meet the condition.
    EventCondition -> Maybe Text
messageActivity :: Prelude.Maybe Prelude.Text
  }
  deriving (EventCondition -> EventCondition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventCondition -> EventCondition -> Bool
$c/= :: EventCondition -> EventCondition -> Bool
== :: EventCondition -> EventCondition -> Bool
$c== :: EventCondition -> EventCondition -> Bool
Prelude.Eq, ReadPrec [EventCondition]
ReadPrec EventCondition
Int -> ReadS EventCondition
ReadS [EventCondition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventCondition]
$creadListPrec :: ReadPrec [EventCondition]
readPrec :: ReadPrec EventCondition
$creadPrec :: ReadPrec EventCondition
readList :: ReadS [EventCondition]
$creadList :: ReadS [EventCondition]
readsPrec :: Int -> ReadS EventCondition
$creadsPrec :: Int -> ReadS EventCondition
Prelude.Read, Int -> EventCondition -> ShowS
[EventCondition] -> ShowS
EventCondition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventCondition] -> ShowS
$cshowList :: [EventCondition] -> ShowS
show :: EventCondition -> String
$cshow :: EventCondition -> String
showsPrec :: Int -> EventCondition -> ShowS
$cshowsPrec :: Int -> EventCondition -> ShowS
Prelude.Show, forall x. Rep EventCondition x -> EventCondition
forall x. EventCondition -> Rep EventCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventCondition x -> EventCondition
$cfrom :: forall x. EventCondition -> Rep EventCondition x
Prelude.Generic)

-- |
-- Create a value of 'EventCondition' 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:
--
-- 'dimensions', 'eventCondition_dimensions' - The dimensions for the event filter to use for the activity.
--
-- 'messageActivity', 'eventCondition_messageActivity' - The message identifier (message_id) for the message to use when
-- determining whether message events meet the condition.
newEventCondition ::
  EventCondition
newEventCondition :: EventCondition
newEventCondition =
  EventCondition'
    { $sel:dimensions:EventCondition' :: Maybe EventDimensions
dimensions = forall a. Maybe a
Prelude.Nothing,
      $sel:messageActivity:EventCondition' :: Maybe Text
messageActivity = forall a. Maybe a
Prelude.Nothing
    }

-- | The dimensions for the event filter to use for the activity.
eventCondition_dimensions :: Lens.Lens' EventCondition (Prelude.Maybe EventDimensions)
eventCondition_dimensions :: Lens' EventCondition (Maybe EventDimensions)
eventCondition_dimensions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventCondition' {Maybe EventDimensions
dimensions :: Maybe EventDimensions
$sel:dimensions:EventCondition' :: EventCondition -> Maybe EventDimensions
dimensions} -> Maybe EventDimensions
dimensions) (\s :: EventCondition
s@EventCondition' {} Maybe EventDimensions
a -> EventCondition
s {$sel:dimensions:EventCondition' :: Maybe EventDimensions
dimensions = Maybe EventDimensions
a} :: EventCondition)

-- | The message identifier (message_id) for the message to use when
-- determining whether message events meet the condition.
eventCondition_messageActivity :: Lens.Lens' EventCondition (Prelude.Maybe Prelude.Text)
eventCondition_messageActivity :: Lens' EventCondition (Maybe Text)
eventCondition_messageActivity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventCondition' {Maybe Text
messageActivity :: Maybe Text
$sel:messageActivity:EventCondition' :: EventCondition -> Maybe Text
messageActivity} -> Maybe Text
messageActivity) (\s :: EventCondition
s@EventCondition' {} Maybe Text
a -> EventCondition
s {$sel:messageActivity:EventCondition' :: Maybe Text
messageActivity = Maybe Text
a} :: EventCondition)

instance Data.FromJSON EventCondition where
  parseJSON :: Value -> Parser EventCondition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EventCondition"
      ( \Object
x ->
          Maybe EventDimensions -> Maybe Text -> EventCondition
EventCondition'
            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
"Dimensions")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MessageActivity")
      )

instance Prelude.Hashable EventCondition where
  hashWithSalt :: Int -> EventCondition -> Int
hashWithSalt Int
_salt EventCondition' {Maybe Text
Maybe EventDimensions
messageActivity :: Maybe Text
dimensions :: Maybe EventDimensions
$sel:messageActivity:EventCondition' :: EventCondition -> Maybe Text
$sel:dimensions:EventCondition' :: EventCondition -> Maybe EventDimensions
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EventDimensions
dimensions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
messageActivity

instance Prelude.NFData EventCondition where
  rnf :: EventCondition -> ()
rnf EventCondition' {Maybe Text
Maybe EventDimensions
messageActivity :: Maybe Text
dimensions :: Maybe EventDimensions
$sel:messageActivity:EventCondition' :: EventCondition -> Maybe Text
$sel:dimensions:EventCondition' :: EventCondition -> Maybe EventDimensions
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EventDimensions
dimensions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
messageActivity

instance Data.ToJSON EventCondition where
  toJSON :: EventCondition -> Value
toJSON EventCondition' {Maybe Text
Maybe EventDimensions
messageActivity :: Maybe Text
dimensions :: Maybe EventDimensions
$sel:messageActivity:EventCondition' :: EventCondition -> Maybe Text
$sel:dimensions:EventCondition' :: EventCondition -> Maybe EventDimensions
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Dimensions" 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 EventDimensions
dimensions,
            (Key
"MessageActivity" 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 Text
messageActivity
          ]
      )