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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.Session
import qualified Amazonka.Prelude as Prelude

-- | Specifies information about an event that reports data to Amazon
-- Pinpoint.
--
-- /See:/ 'newEvent' smart constructor.
data Event = Event'
  { -- | The version of the SDK that\'s running on the client device.
    Event -> Maybe Text
clientSdkVersion :: Prelude.Maybe Prelude.Text,
    -- | One or more custom metrics that are associated with the event.
    Event -> Maybe (HashMap Text Double)
metrics :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Double),
    -- | The version number of the app that\'s recording the event.
    Event -> Maybe Text
appVersionCode :: Prelude.Maybe Prelude.Text,
    -- | The title of the app that\'s recording the event.
    Event -> Maybe Text
appTitle :: Prelude.Maybe Prelude.Text,
    -- | The package name of the app that\'s recording the event.
    Event -> Maybe Text
appPackageName :: Prelude.Maybe Prelude.Text,
    -- | One or more custom attributes that are associated with the event.
    Event -> Maybe (HashMap Text Text)
attributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name of the SDK that\'s being used to record the event.
    Event -> Maybe Text
sdkName :: Prelude.Maybe Prelude.Text,
    -- | Information about the session in which the event occurred.
    Event -> Maybe Session
session :: Prelude.Maybe Session,
    -- | The name of the event.
    Event -> Text
eventType :: Prelude.Text,
    -- | The date and time, in ISO 8601 format, when the event occurred.
    Event -> Text
timestamp :: Prelude.Text
  }
  deriving (Event -> Event -> Bool
(Event -> Event -> Bool) -> (Event -> Event -> Bool) -> Eq Event
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c== :: Event -> Event -> Bool
Prelude.Eq, ReadPrec [Event]
ReadPrec Event
Int -> ReadS Event
ReadS [Event]
(Int -> ReadS Event)
-> ReadS [Event]
-> ReadPrec Event
-> ReadPrec [Event]
-> Read Event
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Event]
$creadListPrec :: ReadPrec [Event]
readPrec :: ReadPrec Event
$creadPrec :: ReadPrec Event
readList :: ReadS [Event]
$creadList :: ReadS [Event]
readsPrec :: Int -> ReadS Event
$creadsPrec :: Int -> ReadS Event
Prelude.Read, Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Prelude.Show, (forall x. Event -> Rep Event x)
-> (forall x. Rep Event x -> Event) -> Generic Event
forall x. Rep Event x -> Event
forall x. Event -> Rep Event x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Event x -> Event
$cfrom :: forall x. Event -> Rep Event x
Prelude.Generic)

-- |
-- Create a value of 'Event' 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:
--
-- 'clientSdkVersion', 'event_clientSdkVersion' - The version of the SDK that\'s running on the client device.
--
-- 'metrics', 'event_metrics' - One or more custom metrics that are associated with the event.
--
-- 'appVersionCode', 'event_appVersionCode' - The version number of the app that\'s recording the event.
--
-- 'appTitle', 'event_appTitle' - The title of the app that\'s recording the event.
--
-- 'appPackageName', 'event_appPackageName' - The package name of the app that\'s recording the event.
--
-- 'attributes', 'event_attributes' - One or more custom attributes that are associated with the event.
--
-- 'sdkName', 'event_sdkName' - The name of the SDK that\'s being used to record the event.
--
-- 'session', 'event_session' - Information about the session in which the event occurred.
--
-- 'eventType', 'event_eventType' - The name of the event.
--
-- 'timestamp', 'event_timestamp' - The date and time, in ISO 8601 format, when the event occurred.
newEvent ::
  -- | 'eventType'
  Prelude.Text ->
  -- | 'timestamp'
  Prelude.Text ->
  Event
newEvent :: Text -> Text -> Event
newEvent Text
pEventType_ Text
pTimestamp_ =
  Event' :: Maybe Text
-> Maybe (HashMap Text Double)
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe Session
-> Text
-> Text
-> Event
Event'
    { $sel:clientSdkVersion:Event' :: Maybe Text
clientSdkVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:metrics:Event' :: Maybe (HashMap Text Double)
metrics = Maybe (HashMap Text Double)
forall a. Maybe a
Prelude.Nothing,
      $sel:appVersionCode:Event' :: Maybe Text
appVersionCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:appTitle:Event' :: Maybe Text
appTitle = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:appPackageName:Event' :: Maybe Text
appPackageName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:attributes:Event' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:sdkName:Event' :: Maybe Text
sdkName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:session:Event' :: Maybe Session
session = Maybe Session
forall a. Maybe a
Prelude.Nothing,
      $sel:eventType:Event' :: Text
eventType = Text
pEventType_,
      $sel:timestamp:Event' :: Text
timestamp = Text
pTimestamp_
    }

-- | The version of the SDK that\'s running on the client device.
event_clientSdkVersion :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_clientSdkVersion :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_clientSdkVersion = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
clientSdkVersion :: Maybe Text
$sel:clientSdkVersion:Event' :: Event -> Maybe Text
clientSdkVersion} -> Maybe Text
clientSdkVersion) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:clientSdkVersion:Event' :: Maybe Text
clientSdkVersion = Maybe Text
a} :: Event)

-- | One or more custom metrics that are associated with the event.
event_metrics :: Lens.Lens' Event (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Double))
event_metrics :: (Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
-> Event -> f Event
event_metrics = (Event -> Maybe (HashMap Text Double))
-> (Event -> Maybe (HashMap Text Double) -> Event)
-> Lens
     Event
     Event
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe (HashMap Text Double)
metrics :: Maybe (HashMap Text Double)
$sel:metrics:Event' :: Event -> Maybe (HashMap Text Double)
metrics} -> Maybe (HashMap Text Double)
metrics) (\s :: Event
s@Event' {} Maybe (HashMap Text Double)
a -> Event
s {$sel:metrics:Event' :: Maybe (HashMap Text Double)
metrics = Maybe (HashMap Text Double)
a} :: Event) ((Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
 -> Event -> f Event)
-> ((Maybe (HashMap Text Double)
     -> f (Maybe (HashMap Text Double)))
    -> Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
-> (Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
-> Event
-> f Event
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Double)
  (HashMap Text Double)
  (HashMap Text Double)
  (HashMap Text Double)
-> Iso
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
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 Double)
  (HashMap Text Double)
  (HashMap Text Double)
  (HashMap Text Double)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The version number of the app that\'s recording the event.
event_appVersionCode :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_appVersionCode :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_appVersionCode = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
appVersionCode :: Maybe Text
$sel:appVersionCode:Event' :: Event -> Maybe Text
appVersionCode} -> Maybe Text
appVersionCode) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:appVersionCode:Event' :: Maybe Text
appVersionCode = Maybe Text
a} :: Event)

-- | The title of the app that\'s recording the event.
event_appTitle :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_appTitle :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_appTitle = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
appTitle :: Maybe Text
$sel:appTitle:Event' :: Event -> Maybe Text
appTitle} -> Maybe Text
appTitle) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:appTitle:Event' :: Maybe Text
appTitle = Maybe Text
a} :: Event)

-- | The package name of the app that\'s recording the event.
event_appPackageName :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_appPackageName :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_appPackageName = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
appPackageName :: Maybe Text
$sel:appPackageName:Event' :: Event -> Maybe Text
appPackageName} -> Maybe Text
appPackageName) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:appPackageName:Event' :: Maybe Text
appPackageName = Maybe Text
a} :: Event)

-- | One or more custom attributes that are associated with the event.
event_attributes :: Lens.Lens' Event (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
event_attributes :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Event -> f Event
event_attributes = (Event -> Maybe (HashMap Text Text))
-> (Event -> Maybe (HashMap Text Text) -> Event)
-> Lens
     Event Event (Maybe (HashMap Text Text)) (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe (HashMap Text Text)
attributes :: Maybe (HashMap Text Text)
$sel:attributes:Event' :: Event -> Maybe (HashMap Text Text)
attributes} -> Maybe (HashMap Text Text)
attributes) (\s :: Event
s@Event' {} Maybe (HashMap Text Text)
a -> Event
s {$sel:attributes:Event' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
a} :: Event) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Event -> f Event)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Event
-> f Event
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the SDK that\'s being used to record the event.
event_sdkName :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_sdkName :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_sdkName = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
sdkName :: Maybe Text
$sel:sdkName:Event' :: Event -> Maybe Text
sdkName} -> Maybe Text
sdkName) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:sdkName:Event' :: Maybe Text
sdkName = Maybe Text
a} :: Event)

-- | Information about the session in which the event occurred.
event_session :: Lens.Lens' Event (Prelude.Maybe Session)
event_session :: (Maybe Session -> f (Maybe Session)) -> Event -> f Event
event_session = (Event -> Maybe Session)
-> (Event -> Maybe Session -> Event)
-> Lens Event Event (Maybe Session) (Maybe Session)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Session
session :: Maybe Session
$sel:session:Event' :: Event -> Maybe Session
session} -> Maybe Session
session) (\s :: Event
s@Event' {} Maybe Session
a -> Event
s {$sel:session:Event' :: Maybe Session
session = Maybe Session
a} :: Event)

-- | The name of the event.
event_eventType :: Lens.Lens' Event Prelude.Text
event_eventType :: (Text -> f Text) -> Event -> f Event
event_eventType = (Event -> Text)
-> (Event -> Text -> Event) -> Lens Event Event Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Text
eventType :: Text
$sel:eventType:Event' :: Event -> Text
eventType} -> Text
eventType) (\s :: Event
s@Event' {} Text
a -> Event
s {$sel:eventType:Event' :: Text
eventType = Text
a} :: Event)

-- | The date and time, in ISO 8601 format, when the event occurred.
event_timestamp :: Lens.Lens' Event Prelude.Text
event_timestamp :: (Text -> f Text) -> Event -> f Event
event_timestamp = (Event -> Text)
-> (Event -> Text -> Event) -> Lens Event Event Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Text
timestamp :: Text
$sel:timestamp:Event' :: Event -> Text
timestamp} -> Text
timestamp) (\s :: Event
s@Event' {} Text
a -> Event
s {$sel:timestamp:Event' :: Text
timestamp = Text
a} :: Event)

instance Prelude.Hashable Event

instance Prelude.NFData Event

instance Core.ToJSON Event where
  toJSON :: Event -> Value
toJSON Event' {Maybe Text
Maybe (HashMap Text Double)
Maybe (HashMap Text Text)
Maybe Session
Text
timestamp :: Text
eventType :: Text
session :: Maybe Session
sdkName :: Maybe Text
attributes :: Maybe (HashMap Text Text)
appPackageName :: Maybe Text
appTitle :: Maybe Text
appVersionCode :: Maybe Text
metrics :: Maybe (HashMap Text Double)
clientSdkVersion :: Maybe Text
$sel:timestamp:Event' :: Event -> Text
$sel:eventType:Event' :: Event -> Text
$sel:session:Event' :: Event -> Maybe Session
$sel:sdkName:Event' :: Event -> Maybe Text
$sel:attributes:Event' :: Event -> Maybe (HashMap Text Text)
$sel:appPackageName:Event' :: Event -> Maybe Text
$sel:appTitle:Event' :: Event -> Maybe Text
$sel:appVersionCode:Event' :: Event -> Maybe Text
$sel:metrics:Event' :: Event -> Maybe (HashMap Text Double)
$sel:clientSdkVersion:Event' :: Event -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ClientSdkVersion" 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
clientSdkVersion,
            (Text
"Metrics" Text -> HashMap Text Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Double -> Pair)
-> Maybe (HashMap Text Double) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Double)
metrics,
            (Text
"AppVersionCode" 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
appVersionCode,
            (Text
"AppTitle" 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
appTitle,
            (Text
"AppPackageName" 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
appPackageName,
            (Text
"Attributes" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
attributes,
            (Text
"SdkName" 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
sdkName,
            (Text
"Session" Text -> Session -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Session -> Pair) -> Maybe Session -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Session
session,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"EventType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
eventType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Timestamp" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
timestamp)
          ]
      )