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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.AttributeDimension
import Amazonka.Pinpoint.Types.MetricDimension
import Amazonka.Pinpoint.Types.SetDimension
import qualified Amazonka.Prelude as Prelude

-- | Specifies the dimensions for an event filter that determines when a
-- campaign is sent or a journey activity is performed.
--
-- /See:/ 'newEventDimensions' smart constructor.
data EventDimensions = EventDimensions'
  { -- | One or more custom metrics that your application reports to Amazon
    -- Pinpoint. You can use these metrics as selection criteria when you
    -- create an event filter.
    EventDimensions -> Maybe (HashMap Text MetricDimension)
metrics :: Prelude.Maybe (Prelude.HashMap Prelude.Text MetricDimension),
    -- | The name of the event that causes the campaign to be sent or the journey
    -- activity to be performed. This can be a standard event that Amazon
    -- Pinpoint generates, such as _email.delivered. For campaigns, this can
    -- also be a custom event that\'s specific to your application. For
    -- information about standard events, see
    -- <https://docs.aws.amazon.com/pinpoint/latest/developerguide/event-streams.html Streaming Amazon Pinpoint Events>
    -- in the /Amazon Pinpoint Developer Guide/.
    EventDimensions -> Maybe SetDimension
eventType :: Prelude.Maybe SetDimension,
    -- | One or more custom attributes that your application reports to Amazon
    -- Pinpoint. You can use these attributes as selection criteria when you
    -- create an event filter.
    EventDimensions -> Maybe (HashMap Text AttributeDimension)
attributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeDimension)
  }
  deriving (EventDimensions -> EventDimensions -> Bool
(EventDimensions -> EventDimensions -> Bool)
-> (EventDimensions -> EventDimensions -> Bool)
-> Eq EventDimensions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventDimensions -> EventDimensions -> Bool
$c/= :: EventDimensions -> EventDimensions -> Bool
== :: EventDimensions -> EventDimensions -> Bool
$c== :: EventDimensions -> EventDimensions -> Bool
Prelude.Eq, ReadPrec [EventDimensions]
ReadPrec EventDimensions
Int -> ReadS EventDimensions
ReadS [EventDimensions]
(Int -> ReadS EventDimensions)
-> ReadS [EventDimensions]
-> ReadPrec EventDimensions
-> ReadPrec [EventDimensions]
-> Read EventDimensions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventDimensions]
$creadListPrec :: ReadPrec [EventDimensions]
readPrec :: ReadPrec EventDimensions
$creadPrec :: ReadPrec EventDimensions
readList :: ReadS [EventDimensions]
$creadList :: ReadS [EventDimensions]
readsPrec :: Int -> ReadS EventDimensions
$creadsPrec :: Int -> ReadS EventDimensions
Prelude.Read, Int -> EventDimensions -> ShowS
[EventDimensions] -> ShowS
EventDimensions -> String
(Int -> EventDimensions -> ShowS)
-> (EventDimensions -> String)
-> ([EventDimensions] -> ShowS)
-> Show EventDimensions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventDimensions] -> ShowS
$cshowList :: [EventDimensions] -> ShowS
show :: EventDimensions -> String
$cshow :: EventDimensions -> String
showsPrec :: Int -> EventDimensions -> ShowS
$cshowsPrec :: Int -> EventDimensions -> ShowS
Prelude.Show, (forall x. EventDimensions -> Rep EventDimensions x)
-> (forall x. Rep EventDimensions x -> EventDimensions)
-> Generic EventDimensions
forall x. Rep EventDimensions x -> EventDimensions
forall x. EventDimensions -> Rep EventDimensions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventDimensions x -> EventDimensions
$cfrom :: forall x. EventDimensions -> Rep EventDimensions x
Prelude.Generic)

-- |
-- Create a value of 'EventDimensions' 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:
--
-- 'metrics', 'eventDimensions_metrics' - One or more custom metrics that your application reports to Amazon
-- Pinpoint. You can use these metrics as selection criteria when you
-- create an event filter.
--
-- 'eventType', 'eventDimensions_eventType' - The name of the event that causes the campaign to be sent or the journey
-- activity to be performed. This can be a standard event that Amazon
-- Pinpoint generates, such as _email.delivered. For campaigns, this can
-- also be a custom event that\'s specific to your application. For
-- information about standard events, see
-- <https://docs.aws.amazon.com/pinpoint/latest/developerguide/event-streams.html Streaming Amazon Pinpoint Events>
-- in the /Amazon Pinpoint Developer Guide/.
--
-- 'attributes', 'eventDimensions_attributes' - One or more custom attributes that your application reports to Amazon
-- Pinpoint. You can use these attributes as selection criteria when you
-- create an event filter.
newEventDimensions ::
  EventDimensions
newEventDimensions :: EventDimensions
newEventDimensions =
  EventDimensions' :: Maybe (HashMap Text MetricDimension)
-> Maybe SetDimension
-> Maybe (HashMap Text AttributeDimension)
-> EventDimensions
EventDimensions'
    { $sel:metrics:EventDimensions' :: Maybe (HashMap Text MetricDimension)
metrics = Maybe (HashMap Text MetricDimension)
forall a. Maybe a
Prelude.Nothing,
      $sel:eventType:EventDimensions' :: Maybe SetDimension
eventType = Maybe SetDimension
forall a. Maybe a
Prelude.Nothing,
      $sel:attributes:EventDimensions' :: Maybe (HashMap Text AttributeDimension)
attributes = Maybe (HashMap Text AttributeDimension)
forall a. Maybe a
Prelude.Nothing
    }

-- | One or more custom metrics that your application reports to Amazon
-- Pinpoint. You can use these metrics as selection criteria when you
-- create an event filter.
eventDimensions_metrics :: Lens.Lens' EventDimensions (Prelude.Maybe (Prelude.HashMap Prelude.Text MetricDimension))
eventDimensions_metrics :: (Maybe (HashMap Text MetricDimension)
 -> f (Maybe (HashMap Text MetricDimension)))
-> EventDimensions -> f EventDimensions
eventDimensions_metrics = (EventDimensions -> Maybe (HashMap Text MetricDimension))
-> (EventDimensions
    -> Maybe (HashMap Text MetricDimension) -> EventDimensions)
-> Lens
     EventDimensions
     EventDimensions
     (Maybe (HashMap Text MetricDimension))
     (Maybe (HashMap Text MetricDimension))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDimensions' {Maybe (HashMap Text MetricDimension)
metrics :: Maybe (HashMap Text MetricDimension)
$sel:metrics:EventDimensions' :: EventDimensions -> Maybe (HashMap Text MetricDimension)
metrics} -> Maybe (HashMap Text MetricDimension)
metrics) (\s :: EventDimensions
s@EventDimensions' {} Maybe (HashMap Text MetricDimension)
a -> EventDimensions
s {$sel:metrics:EventDimensions' :: Maybe (HashMap Text MetricDimension)
metrics = Maybe (HashMap Text MetricDimension)
a} :: EventDimensions) ((Maybe (HashMap Text MetricDimension)
  -> f (Maybe (HashMap Text MetricDimension)))
 -> EventDimensions -> f EventDimensions)
-> ((Maybe (HashMap Text MetricDimension)
     -> f (Maybe (HashMap Text MetricDimension)))
    -> Maybe (HashMap Text MetricDimension)
    -> f (Maybe (HashMap Text MetricDimension)))
-> (Maybe (HashMap Text MetricDimension)
    -> f (Maybe (HashMap Text MetricDimension)))
-> EventDimensions
-> f EventDimensions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text MetricDimension)
  (HashMap Text MetricDimension)
  (HashMap Text MetricDimension)
  (HashMap Text MetricDimension)
-> Iso
     (Maybe (HashMap Text MetricDimension))
     (Maybe (HashMap Text MetricDimension))
     (Maybe (HashMap Text MetricDimension))
     (Maybe (HashMap Text MetricDimension))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text MetricDimension)
  (HashMap Text MetricDimension)
  (HashMap Text MetricDimension)
  (HashMap Text MetricDimension)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the event that causes the campaign to be sent or the journey
-- activity to be performed. This can be a standard event that Amazon
-- Pinpoint generates, such as _email.delivered. For campaigns, this can
-- also be a custom event that\'s specific to your application. For
-- information about standard events, see
-- <https://docs.aws.amazon.com/pinpoint/latest/developerguide/event-streams.html Streaming Amazon Pinpoint Events>
-- in the /Amazon Pinpoint Developer Guide/.
eventDimensions_eventType :: Lens.Lens' EventDimensions (Prelude.Maybe SetDimension)
eventDimensions_eventType :: (Maybe SetDimension -> f (Maybe SetDimension))
-> EventDimensions -> f EventDimensions
eventDimensions_eventType = (EventDimensions -> Maybe SetDimension)
-> (EventDimensions -> Maybe SetDimension -> EventDimensions)
-> Lens
     EventDimensions
     EventDimensions
     (Maybe SetDimension)
     (Maybe SetDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDimensions' {Maybe SetDimension
eventType :: Maybe SetDimension
$sel:eventType:EventDimensions' :: EventDimensions -> Maybe SetDimension
eventType} -> Maybe SetDimension
eventType) (\s :: EventDimensions
s@EventDimensions' {} Maybe SetDimension
a -> EventDimensions
s {$sel:eventType:EventDimensions' :: Maybe SetDimension
eventType = Maybe SetDimension
a} :: EventDimensions)

-- | One or more custom attributes that your application reports to Amazon
-- Pinpoint. You can use these attributes as selection criteria when you
-- create an event filter.
eventDimensions_attributes :: Lens.Lens' EventDimensions (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeDimension))
eventDimensions_attributes :: (Maybe (HashMap Text AttributeDimension)
 -> f (Maybe (HashMap Text AttributeDimension)))
-> EventDimensions -> f EventDimensions
eventDimensions_attributes = (EventDimensions -> Maybe (HashMap Text AttributeDimension))
-> (EventDimensions
    -> Maybe (HashMap Text AttributeDimension) -> EventDimensions)
-> Lens
     EventDimensions
     EventDimensions
     (Maybe (HashMap Text AttributeDimension))
     (Maybe (HashMap Text AttributeDimension))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDimensions' {Maybe (HashMap Text AttributeDimension)
attributes :: Maybe (HashMap Text AttributeDimension)
$sel:attributes:EventDimensions' :: EventDimensions -> Maybe (HashMap Text AttributeDimension)
attributes} -> Maybe (HashMap Text AttributeDimension)
attributes) (\s :: EventDimensions
s@EventDimensions' {} Maybe (HashMap Text AttributeDimension)
a -> EventDimensions
s {$sel:attributes:EventDimensions' :: Maybe (HashMap Text AttributeDimension)
attributes = Maybe (HashMap Text AttributeDimension)
a} :: EventDimensions) ((Maybe (HashMap Text AttributeDimension)
  -> f (Maybe (HashMap Text AttributeDimension)))
 -> EventDimensions -> f EventDimensions)
-> ((Maybe (HashMap Text AttributeDimension)
     -> f (Maybe (HashMap Text AttributeDimension)))
    -> Maybe (HashMap Text AttributeDimension)
    -> f (Maybe (HashMap Text AttributeDimension)))
-> (Maybe (HashMap Text AttributeDimension)
    -> f (Maybe (HashMap Text AttributeDimension)))
-> EventDimensions
-> f EventDimensions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text AttributeDimension)
  (HashMap Text AttributeDimension)
  (HashMap Text AttributeDimension)
  (HashMap Text AttributeDimension)
-> Iso
     (Maybe (HashMap Text AttributeDimension))
     (Maybe (HashMap Text AttributeDimension))
     (Maybe (HashMap Text AttributeDimension))
     (Maybe (HashMap Text AttributeDimension))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text AttributeDimension)
  (HashMap Text AttributeDimension)
  (HashMap Text AttributeDimension)
  (HashMap Text AttributeDimension)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON EventDimensions where
  parseJSON :: Value -> Parser EventDimensions
parseJSON =
    String
-> (Object -> Parser EventDimensions)
-> Value
-> Parser EventDimensions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EventDimensions"
      ( \Object
x ->
          Maybe (HashMap Text MetricDimension)
-> Maybe SetDimension
-> Maybe (HashMap Text AttributeDimension)
-> EventDimensions
EventDimensions'
            (Maybe (HashMap Text MetricDimension)
 -> Maybe SetDimension
 -> Maybe (HashMap Text AttributeDimension)
 -> EventDimensions)
-> Parser (Maybe (HashMap Text MetricDimension))
-> Parser
     (Maybe SetDimension
      -> Maybe (HashMap Text AttributeDimension) -> EventDimensions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text -> Parser (Maybe (Maybe (HashMap Text MetricDimension)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Metrics" Parser (Maybe (Maybe (HashMap Text MetricDimension)))
-> Maybe (HashMap Text MetricDimension)
-> Parser (Maybe (HashMap Text MetricDimension))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text MetricDimension)
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe SetDimension
   -> Maybe (HashMap Text AttributeDimension) -> EventDimensions)
-> Parser (Maybe SetDimension)
-> Parser
     (Maybe (HashMap Text AttributeDimension) -> EventDimensions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SetDimension)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventType")
            Parser (Maybe (HashMap Text AttributeDimension) -> EventDimensions)
-> Parser (Maybe (HashMap Text AttributeDimension))
-> Parser EventDimensions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe (Maybe (HashMap Text AttributeDimension)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Attributes" Parser (Maybe (Maybe (HashMap Text AttributeDimension)))
-> Maybe (HashMap Text AttributeDimension)
-> Parser (Maybe (HashMap Text AttributeDimension))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text AttributeDimension)
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable EventDimensions

instance Prelude.NFData EventDimensions

instance Core.ToJSON EventDimensions where
  toJSON :: EventDimensions -> Value
toJSON EventDimensions' {Maybe (HashMap Text AttributeDimension)
Maybe (HashMap Text MetricDimension)
Maybe SetDimension
attributes :: Maybe (HashMap Text AttributeDimension)
eventType :: Maybe SetDimension
metrics :: Maybe (HashMap Text MetricDimension)
$sel:attributes:EventDimensions' :: EventDimensions -> Maybe (HashMap Text AttributeDimension)
$sel:eventType:EventDimensions' :: EventDimensions -> Maybe SetDimension
$sel:metrics:EventDimensions' :: EventDimensions -> Maybe (HashMap Text MetricDimension)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Metrics" Text -> HashMap Text MetricDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text MetricDimension -> Pair)
-> Maybe (HashMap Text MetricDimension) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text MetricDimension)
metrics,
            (Text
"EventType" Text -> SetDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SetDimension -> Pair) -> Maybe SetDimension -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SetDimension
eventType,
            (Text
"Attributes" Text -> HashMap Text AttributeDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text AttributeDimension -> Pair)
-> Maybe (HashMap Text AttributeDimension) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text AttributeDimension)
attributes
          ]
      )