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

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

-- | Represents user interaction event information sent using the @PutEvents@
-- API.
--
-- /See:/ 'newEvent' smart constructor.
data Event = Event'
  { -- | The ID of the recommendation.
    Event -> Maybe Text
recommendationId :: Prelude.Maybe Prelude.Text,
    -- | The event value that corresponds to the @EVENT_VALUE@ field of the
    -- Interactions schema.
    Event -> Maybe Double
eventValue :: Prelude.Maybe Prelude.Double,
    -- | The item ID key that corresponds to the @ITEM_ID@ field of the
    -- Interactions schema.
    Event -> Maybe Text
itemId :: Prelude.Maybe Prelude.Text,
    -- | A list of item IDs that represents the sequence of items you have shown
    -- the user. For example, @[\"itemId1\", \"itemId2\", \"itemId3\"]@.
    Event -> Maybe (NonEmpty Text)
impression :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | An ID associated with the event. If an event ID is not provided, Amazon
    -- Personalize generates a unique ID for the event. An event ID is not used
    -- as an input to the model. Amazon Personalize uses the event ID to
    -- distinquish unique events. Any subsequent events after the first with
    -- the same event ID are not used in model training.
    Event -> Maybe Text
eventId :: Prelude.Maybe Prelude.Text,
    -- | A string map of event-specific data that you might choose to record. For
    -- example, if a user rates a movie on your site, other than movie ID
    -- (@itemId@) and rating (@eventValue@) , you might also send the number of
    -- movie ratings made by the user.
    --
    -- Each item in the map consists of a key-value pair. For example,
    --
    -- @{\"numberOfRatings\": \"12\"}@
    --
    -- The keys use camel case names that match the fields in the Interactions
    -- schema. In the above example, the @numberOfRatings@ would match the
    -- \'NUMBER_OF_RATINGS\' field defined in the Interactions schema.
    Event -> Maybe Text
properties :: Prelude.Maybe Prelude.Text,
    -- | The type of event, such as click or download. This property corresponds
    -- to the @EVENT_TYPE@ field of your Interactions schema and depends on the
    -- types of events you are tracking.
    Event -> Text
eventType :: Prelude.Text,
    -- | The timestamp (in Unix time) on the client side when the event occurred.
    Event -> POSIX
sentAt :: Core.POSIX
  }
  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:
--
-- 'recommendationId', 'event_recommendationId' - The ID of the recommendation.
--
-- 'eventValue', 'event_eventValue' - The event value that corresponds to the @EVENT_VALUE@ field of the
-- Interactions schema.
--
-- 'itemId', 'event_itemId' - The item ID key that corresponds to the @ITEM_ID@ field of the
-- Interactions schema.
--
-- 'impression', 'event_impression' - A list of item IDs that represents the sequence of items you have shown
-- the user. For example, @[\"itemId1\", \"itemId2\", \"itemId3\"]@.
--
-- 'eventId', 'event_eventId' - An ID associated with the event. If an event ID is not provided, Amazon
-- Personalize generates a unique ID for the event. An event ID is not used
-- as an input to the model. Amazon Personalize uses the event ID to
-- distinquish unique events. Any subsequent events after the first with
-- the same event ID are not used in model training.
--
-- 'properties', 'event_properties' - A string map of event-specific data that you might choose to record. For
-- example, if a user rates a movie on your site, other than movie ID
-- (@itemId@) and rating (@eventValue@) , you might also send the number of
-- movie ratings made by the user.
--
-- Each item in the map consists of a key-value pair. For example,
--
-- @{\"numberOfRatings\": \"12\"}@
--
-- The keys use camel case names that match the fields in the Interactions
-- schema. In the above example, the @numberOfRatings@ would match the
-- \'NUMBER_OF_RATINGS\' field defined in the Interactions schema.
--
-- 'eventType', 'event_eventType' - The type of event, such as click or download. This property corresponds
-- to the @EVENT_TYPE@ field of your Interactions schema and depends on the
-- types of events you are tracking.
--
-- 'sentAt', 'event_sentAt' - The timestamp (in Unix time) on the client side when the event occurred.
newEvent ::
  -- | 'eventType'
  Prelude.Text ->
  -- | 'sentAt'
  Prelude.UTCTime ->
  Event
newEvent :: Text -> UTCTime -> Event
newEvent Text
pEventType_ UTCTime
pSentAt_ =
  Event' :: Maybe Text
-> Maybe Double
-> Maybe Text
-> Maybe (NonEmpty Text)
-> Maybe Text
-> Maybe Text
-> Text
-> POSIX
-> Event
Event'
    { $sel:recommendationId:Event' :: Maybe Text
recommendationId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventValue:Event' :: Maybe Double
eventValue = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:itemId:Event' :: Maybe Text
itemId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:impression:Event' :: Maybe (NonEmpty Text)
impression = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:eventId:Event' :: Maybe Text
eventId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:properties:Event' :: Maybe Text
properties = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventType:Event' :: Text
eventType = Text
pEventType_,
      $sel:sentAt:Event' :: POSIX
sentAt = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pSentAt_
    }

-- | The ID of the recommendation.
event_recommendationId :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_recommendationId :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_recommendationId = (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
recommendationId :: Maybe Text
$sel:recommendationId:Event' :: Event -> Maybe Text
recommendationId} -> Maybe Text
recommendationId) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:recommendationId:Event' :: Maybe Text
recommendationId = Maybe Text
a} :: Event)

-- | The event value that corresponds to the @EVENT_VALUE@ field of the
-- Interactions schema.
event_eventValue :: Lens.Lens' Event (Prelude.Maybe Prelude.Double)
event_eventValue :: (Maybe Double -> f (Maybe Double)) -> Event -> f Event
event_eventValue = (Event -> Maybe Double)
-> (Event -> Maybe Double -> Event)
-> Lens Event Event (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Double
eventValue :: Maybe Double
$sel:eventValue:Event' :: Event -> Maybe Double
eventValue} -> Maybe Double
eventValue) (\s :: Event
s@Event' {} Maybe Double
a -> Event
s {$sel:eventValue:Event' :: Maybe Double
eventValue = Maybe Double
a} :: Event)

-- | The item ID key that corresponds to the @ITEM_ID@ field of the
-- Interactions schema.
event_itemId :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_itemId :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_itemId = (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
itemId :: Maybe Text
$sel:itemId:Event' :: Event -> Maybe Text
itemId} -> Maybe Text
itemId) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:itemId:Event' :: Maybe Text
itemId = Maybe Text
a} :: Event)

-- | A list of item IDs that represents the sequence of items you have shown
-- the user. For example, @[\"itemId1\", \"itemId2\", \"itemId3\"]@.
event_impression :: Lens.Lens' Event (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
event_impression :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Event -> f Event
event_impression = (Event -> Maybe (NonEmpty Text))
-> (Event -> Maybe (NonEmpty Text) -> Event)
-> Lens Event Event (Maybe (NonEmpty Text)) (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe (NonEmpty Text)
impression :: Maybe (NonEmpty Text)
$sel:impression:Event' :: Event -> Maybe (NonEmpty Text)
impression} -> Maybe (NonEmpty Text)
impression) (\s :: Event
s@Event' {} Maybe (NonEmpty Text)
a -> Event
s {$sel:impression:Event' :: Maybe (NonEmpty Text)
impression = Maybe (NonEmpty Text)
a} :: Event) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> Event -> f Event)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Event
-> f Event
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty 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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An ID associated with the event. If an event ID is not provided, Amazon
-- Personalize generates a unique ID for the event. An event ID is not used
-- as an input to the model. Amazon Personalize uses the event ID to
-- distinquish unique events. Any subsequent events after the first with
-- the same event ID are not used in model training.
event_eventId :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_eventId :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_eventId = (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
eventId :: Maybe Text
$sel:eventId:Event' :: Event -> Maybe Text
eventId} -> Maybe Text
eventId) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:eventId:Event' :: Maybe Text
eventId = Maybe Text
a} :: Event)

-- | A string map of event-specific data that you might choose to record. For
-- example, if a user rates a movie on your site, other than movie ID
-- (@itemId@) and rating (@eventValue@) , you might also send the number of
-- movie ratings made by the user.
--
-- Each item in the map consists of a key-value pair. For example,
--
-- @{\"numberOfRatings\": \"12\"}@
--
-- The keys use camel case names that match the fields in the Interactions
-- schema. In the above example, the @numberOfRatings@ would match the
-- \'NUMBER_OF_RATINGS\' field defined in the Interactions schema.
event_properties :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_properties :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_properties = (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
properties :: Maybe Text
$sel:properties:Event' :: Event -> Maybe Text
properties} -> Maybe Text
properties) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:properties:Event' :: Maybe Text
properties = Maybe Text
a} :: Event)

-- | The type of event, such as click or download. This property corresponds
-- to the @EVENT_TYPE@ field of your Interactions schema and depends on the
-- types of events you are tracking.
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 timestamp (in Unix time) on the client side when the event occurred.
event_sentAt :: Lens.Lens' Event Prelude.UTCTime
event_sentAt :: (UTCTime -> f UTCTime) -> Event -> f Event
event_sentAt = (Event -> POSIX)
-> (Event -> POSIX -> Event) -> Lens Event Event POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {POSIX
sentAt :: POSIX
$sel:sentAt:Event' :: Event -> POSIX
sentAt} -> POSIX
sentAt) (\s :: Event
s@Event' {} POSIX
a -> Event
s {$sel:sentAt:Event' :: POSIX
sentAt = POSIX
a} :: Event) ((POSIX -> f POSIX) -> Event -> f Event)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> Event
-> f Event
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Prelude.Hashable Event

instance Prelude.NFData Event

instance Core.ToJSON Event where
  toJSON :: Event -> Value
toJSON Event' {Maybe Double
Maybe (NonEmpty Text)
Maybe Text
Text
POSIX
sentAt :: POSIX
eventType :: Text
properties :: Maybe Text
eventId :: Maybe Text
impression :: Maybe (NonEmpty Text)
itemId :: Maybe Text
eventValue :: Maybe Double
recommendationId :: Maybe Text
$sel:sentAt:Event' :: Event -> POSIX
$sel:eventType:Event' :: Event -> Text
$sel:properties:Event' :: Event -> Maybe Text
$sel:eventId:Event' :: Event -> Maybe Text
$sel:impression:Event' :: Event -> Maybe (NonEmpty Text)
$sel:itemId:Event' :: Event -> Maybe Text
$sel:eventValue:Event' :: Event -> Maybe Double
$sel:recommendationId:Event' :: Event -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"recommendationId" 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
recommendationId,
            (Text
"eventValue" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
eventValue,
            (Text
"itemId" 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
itemId,
            (Text
"impression" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
impression,
            (Text
"eventId" 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
eventId,
            (Text
"properties" 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
properties,
            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
"sentAt" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
sentAt)
          ]
      )