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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Evidently.Types.EventType
import qualified Amazonka.Prelude as Prelude

-- | A structure that contains the information about one evaluation event or
-- custom event sent to Evidently. This is a JSON payload. If this event
-- specifies a pre-defined event type, the payload must follow the defined
-- event schema.
--
-- /See:/ 'newEvent' smart constructor.
data Event = Event'
  { -- | The event data.
    Event -> Text
data' :: Prelude.Text,
    -- | The timestamp of the event.
    Event -> POSIX
timestamp :: Data.POSIX,
    -- | @aws.evidently.evaluation@ specifies an evaluation event, which
    -- determines which feature variation that a user sees.
    -- @aws.evidently.custom@ specifies a custom event, which generates metrics
    -- from user actions such as clicks and checkouts.
    Event -> EventType
type' :: EventType
  }
  deriving (Event -> Event -> Bool
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]
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
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. 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:
--
-- 'data'', 'event_data' - The event data.
--
-- 'timestamp', 'event_timestamp' - The timestamp of the event.
--
-- 'type'', 'event_type' - @aws.evidently.evaluation@ specifies an evaluation event, which
-- determines which feature variation that a user sees.
-- @aws.evidently.custom@ specifies a custom event, which generates metrics
-- from user actions such as clicks and checkouts.
newEvent ::
  -- | 'data''
  Prelude.Text ->
  -- | 'timestamp'
  Prelude.UTCTime ->
  -- | 'type''
  EventType ->
  Event
newEvent :: Text -> UTCTime -> EventType -> Event
newEvent Text
pData_ UTCTime
pTimestamp_ EventType
pType_ =
  Event'
    { $sel:data':Event' :: Text
data' = Text
pData_,
      $sel:timestamp:Event' :: POSIX
timestamp = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pTimestamp_,
      $sel:type':Event' :: EventType
type' = EventType
pType_
    }

-- | The event data.
event_data :: Lens.Lens' Event Prelude.Text
event_data :: Lens' Event Text
event_data = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Text
data' :: Text
$sel:data':Event' :: Event -> Text
data'} -> Text
data') (\s :: Event
s@Event' {} Text
a -> Event
s {$sel:data':Event' :: Text
data' = Text
a} :: Event)

-- | The timestamp of the event.
event_timestamp :: Lens.Lens' Event Prelude.UTCTime
event_timestamp :: Lens' Event UTCTime
event_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {POSIX
timestamp :: POSIX
$sel:timestamp:Event' :: Event -> POSIX
timestamp} -> POSIX
timestamp) (\s :: Event
s@Event' {} POSIX
a -> Event
s {$sel:timestamp:Event' :: POSIX
timestamp = POSIX
a} :: Event) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | @aws.evidently.evaluation@ specifies an evaluation event, which
-- determines which feature variation that a user sees.
-- @aws.evidently.custom@ specifies a custom event, which generates metrics
-- from user actions such as clicks and checkouts.
event_type :: Lens.Lens' Event EventType
event_type :: Lens' Event EventType
event_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {EventType
type' :: EventType
$sel:type':Event' :: Event -> EventType
type'} -> EventType
type') (\s :: Event
s@Event' {} EventType
a -> Event
s {$sel:type':Event' :: EventType
type' = EventType
a} :: Event)

instance Prelude.Hashable Event where
  hashWithSalt :: Int -> Event -> Int
hashWithSalt Int
_salt Event' {Text
POSIX
EventType
type' :: EventType
timestamp :: POSIX
data' :: Text
$sel:type':Event' :: Event -> EventType
$sel:timestamp:Event' :: Event -> POSIX
$sel:data':Event' :: Event -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
data'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EventType
type'

instance Prelude.NFData Event where
  rnf :: Event -> ()
rnf Event' {Text
POSIX
EventType
type' :: EventType
timestamp :: POSIX
data' :: Text
$sel:type':Event' :: Event -> EventType
$sel:timestamp:Event' :: Event -> POSIX
$sel:data':Event' :: Event -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
data'
      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 EventType
type'

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