{-# 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.Rum.Types.RumEvent
-- 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.Rum.Types.RumEvent where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | A structure that contains the information for one performance event that
-- RUM collects from a user session with your application.
--
-- /See:/ 'newRumEvent' smart constructor.
data RumEvent = RumEvent'
  { -- | Metadata about this event, which contains a JSON serialization of the
    -- identity of the user for this session. The user information comes from
    -- information such as the HTTP user-agent request header and document
    -- interface.
    RumEvent -> Maybe Text
metadata :: Prelude.Maybe Prelude.Text,
    -- | A string containing details about the event.
    RumEvent -> Text
details :: Prelude.Text,
    -- | A unique ID for this event.
    RumEvent -> Text
id :: Prelude.Text,
    -- | The exact time that this event occurred.
    RumEvent -> POSIX
timestamp :: Data.POSIX,
    -- | The JSON schema that denotes the type of event this is, such as a page
    -- load or a new session.
    RumEvent -> Text
type' :: Prelude.Text
  }
  deriving (RumEvent -> RumEvent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RumEvent -> RumEvent -> Bool
$c/= :: RumEvent -> RumEvent -> Bool
== :: RumEvent -> RumEvent -> Bool
$c== :: RumEvent -> RumEvent -> Bool
Prelude.Eq, ReadPrec [RumEvent]
ReadPrec RumEvent
Int -> ReadS RumEvent
ReadS [RumEvent]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RumEvent]
$creadListPrec :: ReadPrec [RumEvent]
readPrec :: ReadPrec RumEvent
$creadPrec :: ReadPrec RumEvent
readList :: ReadS [RumEvent]
$creadList :: ReadS [RumEvent]
readsPrec :: Int -> ReadS RumEvent
$creadsPrec :: Int -> ReadS RumEvent
Prelude.Read, Int -> RumEvent -> ShowS
[RumEvent] -> ShowS
RumEvent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RumEvent] -> ShowS
$cshowList :: [RumEvent] -> ShowS
show :: RumEvent -> String
$cshow :: RumEvent -> String
showsPrec :: Int -> RumEvent -> ShowS
$cshowsPrec :: Int -> RumEvent -> ShowS
Prelude.Show, forall x. Rep RumEvent x -> RumEvent
forall x. RumEvent -> Rep RumEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RumEvent x -> RumEvent
$cfrom :: forall x. RumEvent -> Rep RumEvent x
Prelude.Generic)

-- |
-- Create a value of 'RumEvent' 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:
--
-- 'metadata', 'rumEvent_metadata' - Metadata about this event, which contains a JSON serialization of the
-- identity of the user for this session. The user information comes from
-- information such as the HTTP user-agent request header and document
-- interface.
--
-- 'details', 'rumEvent_details' - A string containing details about the event.
--
-- 'id', 'rumEvent_id' - A unique ID for this event.
--
-- 'timestamp', 'rumEvent_timestamp' - The exact time that this event occurred.
--
-- 'type'', 'rumEvent_type' - The JSON schema that denotes the type of event this is, such as a page
-- load or a new session.
newRumEvent ::
  -- | 'details'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  -- | 'timestamp'
  Prelude.UTCTime ->
  -- | 'type''
  Prelude.Text ->
  RumEvent
newRumEvent :: Text -> Text -> UTCTime -> Text -> RumEvent
newRumEvent Text
pDetails_ Text
pId_ UTCTime
pTimestamp_ Text
pType_ =
  RumEvent'
    { $sel:metadata:RumEvent' :: Maybe Text
metadata = forall a. Maybe a
Prelude.Nothing,
      $sel:details:RumEvent' :: Text
details = Text
pDetails_,
      $sel:id:RumEvent' :: Text
id = Text
pId_,
      $sel:timestamp:RumEvent' :: POSIX
timestamp = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pTimestamp_,
      $sel:type':RumEvent' :: Text
type' = Text
pType_
    }

-- | Metadata about this event, which contains a JSON serialization of the
-- identity of the user for this session. The user information comes from
-- information such as the HTTP user-agent request header and document
-- interface.
rumEvent_metadata :: Lens.Lens' RumEvent (Prelude.Maybe Prelude.Text)
rumEvent_metadata :: Lens' RumEvent (Maybe Text)
rumEvent_metadata = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RumEvent' {Maybe Text
metadata :: Maybe Text
$sel:metadata:RumEvent' :: RumEvent -> Maybe Text
metadata} -> Maybe Text
metadata) (\s :: RumEvent
s@RumEvent' {} Maybe Text
a -> RumEvent
s {$sel:metadata:RumEvent' :: Maybe Text
metadata = Maybe Text
a} :: RumEvent)

-- | A string containing details about the event.
rumEvent_details :: Lens.Lens' RumEvent Prelude.Text
rumEvent_details :: Lens' RumEvent Text
rumEvent_details = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RumEvent' {Text
details :: Text
$sel:details:RumEvent' :: RumEvent -> Text
details} -> Text
details) (\s :: RumEvent
s@RumEvent' {} Text
a -> RumEvent
s {$sel:details:RumEvent' :: Text
details = Text
a} :: RumEvent)

-- | A unique ID for this event.
rumEvent_id :: Lens.Lens' RumEvent Prelude.Text
rumEvent_id :: Lens' RumEvent Text
rumEvent_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RumEvent' {Text
id :: Text
$sel:id:RumEvent' :: RumEvent -> Text
id} -> Text
id) (\s :: RumEvent
s@RumEvent' {} Text
a -> RumEvent
s {$sel:id:RumEvent' :: Text
id = Text
a} :: RumEvent)

-- | The exact time that this event occurred.
rumEvent_timestamp :: Lens.Lens' RumEvent Prelude.UTCTime
rumEvent_timestamp :: Lens' RumEvent UTCTime
rumEvent_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RumEvent' {POSIX
timestamp :: POSIX
$sel:timestamp:RumEvent' :: RumEvent -> POSIX
timestamp} -> POSIX
timestamp) (\s :: RumEvent
s@RumEvent' {} POSIX
a -> RumEvent
s {$sel:timestamp:RumEvent' :: POSIX
timestamp = POSIX
a} :: RumEvent) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The JSON schema that denotes the type of event this is, such as a page
-- load or a new session.
rumEvent_type :: Lens.Lens' RumEvent Prelude.Text
rumEvent_type :: Lens' RumEvent Text
rumEvent_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RumEvent' {Text
type' :: Text
$sel:type':RumEvent' :: RumEvent -> Text
type'} -> Text
type') (\s :: RumEvent
s@RumEvent' {} Text
a -> RumEvent
s {$sel:type':RumEvent' :: Text
type' = Text
a} :: RumEvent)

instance Prelude.Hashable RumEvent where
  hashWithSalt :: Int -> RumEvent -> Int
hashWithSalt Int
_salt RumEvent' {Maybe Text
Text
POSIX
type' :: Text
timestamp :: POSIX
id :: Text
details :: Text
metadata :: Maybe Text
$sel:type':RumEvent' :: RumEvent -> Text
$sel:timestamp:RumEvent' :: RumEvent -> POSIX
$sel:id:RumEvent' :: RumEvent -> Text
$sel:details:RumEvent' :: RumEvent -> Text
$sel:metadata:RumEvent' :: RumEvent -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
metadata
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
details
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
type'

instance Prelude.NFData RumEvent where
  rnf :: RumEvent -> ()
rnf RumEvent' {Maybe Text
Text
POSIX
type' :: Text
timestamp :: POSIX
id :: Text
details :: Text
metadata :: Maybe Text
$sel:type':RumEvent' :: RumEvent -> Text
$sel:timestamp:RumEvent' :: RumEvent -> POSIX
$sel:id:RumEvent' :: RumEvent -> Text
$sel:details:RumEvent' :: RumEvent -> Text
$sel:metadata:RumEvent' :: RumEvent -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
metadata
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
details
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
timestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
type'

instance Data.ToJSON RumEvent where
  toJSON :: RumEvent -> Value
toJSON RumEvent' {Maybe Text
Text
POSIX
type' :: Text
timestamp :: POSIX
id :: Text
details :: Text
metadata :: Maybe Text
$sel:type':RumEvent' :: RumEvent -> Text
$sel:timestamp:RumEvent' :: RumEvent -> POSIX
$sel:id:RumEvent' :: RumEvent -> Text
$sel:details:RumEvent' :: RumEvent -> Text
$sel:metadata:RumEvent' :: RumEvent -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"metadata" 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
metadata,
            forall a. a -> Maybe a
Prelude.Just (Key
"details" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
details),
            forall a. a -> Maybe a
Prelude.Just (Key
"id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id),
            forall a. a -> Maybe a
Prelude.Just (Key
"timestamp" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= POSIX
timestamp),
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
type')
          ]
      )