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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(EventCondition -> EventCondition -> Bool)
-> (EventCondition -> EventCondition -> Bool) -> Eq EventCondition
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]
(Int -> ReadS EventCondition)
-> ReadS [EventCondition]
-> ReadPrec EventCondition
-> ReadPrec [EventCondition]
-> Read 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
(Int -> EventCondition -> ShowS)
-> (EventCondition -> String)
-> ([EventCondition] -> ShowS)
-> Show EventCondition
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. EventCondition -> Rep EventCondition x)
-> (forall x. Rep EventCondition x -> EventCondition)
-> Generic EventCondition
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' :: Maybe EventDimensions -> Maybe Text -> EventCondition
EventCondition'
    { $sel:dimensions:EventCondition' :: Maybe EventDimensions
dimensions = Maybe EventDimensions
forall a. Maybe a
Prelude.Nothing,
      $sel:messageActivity:EventCondition' :: Maybe Text
messageActivity = Maybe Text
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 :: (Maybe EventDimensions -> f (Maybe EventDimensions))
-> EventCondition -> f EventCondition
eventCondition_dimensions = (EventCondition -> Maybe EventDimensions)
-> (EventCondition -> Maybe EventDimensions -> EventCondition)
-> Lens
     EventCondition
     EventCondition
     (Maybe EventDimensions)
     (Maybe EventDimensions)
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 :: (Maybe Text -> f (Maybe Text))
-> EventCondition -> f EventCondition
eventCondition_messageActivity = (EventCondition -> Maybe Text)
-> (EventCondition -> Maybe Text -> EventCondition)
-> Lens EventCondition EventCondition (Maybe Text) (Maybe Text)
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 Core.FromJSON EventCondition where
  parseJSON :: Value -> Parser EventCondition
parseJSON =
    String
-> (Object -> Parser EventCondition)
-> Value
-> Parser EventCondition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EventCondition"
      ( \Object
x ->
          Maybe EventDimensions -> Maybe Text -> EventCondition
EventCondition'
            (Maybe EventDimensions -> Maybe Text -> EventCondition)
-> Parser (Maybe EventDimensions)
-> Parser (Maybe Text -> EventCondition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EventDimensions)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Dimensions")
            Parser (Maybe Text -> EventCondition)
-> Parser (Maybe Text) -> Parser EventCondition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MessageActivity")
      )

instance Prelude.Hashable EventCondition

instance Prelude.NFData EventCondition

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Dimensions" Text -> EventDimensions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EventDimensions -> Pair) -> Maybe EventDimensions -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventDimensions
dimensions,
            (Text
"MessageActivity" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
messageActivity
          ]
      )