{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutEvents
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Records user interaction event data. For more information see
-- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
module Amazonka.PersonalizeEvents.PutEvents
  ( -- * Creating a Request
    PutEvents (..),
    newPutEvents,

    -- * Request Lenses
    putEvents_userId,
    putEvents_trackingId,
    putEvents_sessionId,
    putEvents_eventList,

    -- * Destructuring the Response
    PutEventsResponse (..),
    newPutEventsResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.PersonalizeEvents.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPutEvents' smart constructor.
data PutEvents = PutEvents'
  { -- | The user associated with the event.
    PutEvents -> Maybe (Sensitive Text)
userId :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The tracking ID for the event. The ID is generated by a call to the
    -- <https://docs.aws.amazon.com/personalize/latest/dg/API_CreateEventTracker.html CreateEventTracker>
    -- API.
    PutEvents -> Text
trackingId :: Prelude.Text,
    -- | The session ID associated with the user\'s visit. Your application
    -- generates the sessionId when a user first visits your website or uses
    -- your application. Amazon Personalize uses the sessionId to associate
    -- events with the user before they log in. For more information, see
    -- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
    PutEvents -> Text
sessionId :: Prelude.Text,
    -- | A list of event data from the session.
    PutEvents -> NonEmpty (Sensitive Event)
eventList :: Prelude.NonEmpty (Data.Sensitive Event)
  }
  deriving (PutEvents -> PutEvents -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutEvents -> PutEvents -> Bool
$c/= :: PutEvents -> PutEvents -> Bool
== :: PutEvents -> PutEvents -> Bool
$c== :: PutEvents -> PutEvents -> Bool
Prelude.Eq, Int -> PutEvents -> ShowS
[PutEvents] -> ShowS
PutEvents -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutEvents] -> ShowS
$cshowList :: [PutEvents] -> ShowS
show :: PutEvents -> String
$cshow :: PutEvents -> String
showsPrec :: Int -> PutEvents -> ShowS
$cshowsPrec :: Int -> PutEvents -> ShowS
Prelude.Show, forall x. Rep PutEvents x -> PutEvents
forall x. PutEvents -> Rep PutEvents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutEvents x -> PutEvents
$cfrom :: forall x. PutEvents -> Rep PutEvents x
Prelude.Generic)

-- |
-- Create a value of 'PutEvents' 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:
--
-- 'userId', 'putEvents_userId' - The user associated with the event.
--
-- 'trackingId', 'putEvents_trackingId' - The tracking ID for the event. The ID is generated by a call to the
-- <https://docs.aws.amazon.com/personalize/latest/dg/API_CreateEventTracker.html CreateEventTracker>
-- API.
--
-- 'sessionId', 'putEvents_sessionId' - The session ID associated with the user\'s visit. Your application
-- generates the sessionId when a user first visits your website or uses
-- your application. Amazon Personalize uses the sessionId to associate
-- events with the user before they log in. For more information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
--
-- 'eventList', 'putEvents_eventList' - A list of event data from the session.
newPutEvents ::
  -- | 'trackingId'
  Prelude.Text ->
  -- | 'sessionId'
  Prelude.Text ->
  -- | 'eventList'
  Prelude.NonEmpty Event ->
  PutEvents
newPutEvents :: Text -> Text -> NonEmpty Event -> PutEvents
newPutEvents Text
pTrackingId_ Text
pSessionId_ NonEmpty Event
pEventList_ =
  PutEvents'
    { $sel:userId:PutEvents' :: Maybe (Sensitive Text)
userId = forall a. Maybe a
Prelude.Nothing,
      $sel:trackingId:PutEvents' :: Text
trackingId = Text
pTrackingId_,
      $sel:sessionId:PutEvents' :: Text
sessionId = Text
pSessionId_,
      $sel:eventList:PutEvents' :: NonEmpty (Sensitive Event)
eventList = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Event
pEventList_
    }

-- | The user associated with the event.
putEvents_userId :: Lens.Lens' PutEvents (Prelude.Maybe Prelude.Text)
putEvents_userId :: Lens' PutEvents (Maybe Text)
putEvents_userId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {Maybe (Sensitive Text)
userId :: Maybe (Sensitive Text)
$sel:userId:PutEvents' :: PutEvents -> Maybe (Sensitive Text)
userId} -> Maybe (Sensitive Text)
userId) (\s :: PutEvents
s@PutEvents' {} Maybe (Sensitive Text)
a -> PutEvents
s {$sel:userId:PutEvents' :: Maybe (Sensitive Text)
userId = Maybe (Sensitive Text)
a} :: PutEvents) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The tracking ID for the event. The ID is generated by a call to the
-- <https://docs.aws.amazon.com/personalize/latest/dg/API_CreateEventTracker.html CreateEventTracker>
-- API.
putEvents_trackingId :: Lens.Lens' PutEvents Prelude.Text
putEvents_trackingId :: Lens' PutEvents Text
putEvents_trackingId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {Text
trackingId :: Text
$sel:trackingId:PutEvents' :: PutEvents -> Text
trackingId} -> Text
trackingId) (\s :: PutEvents
s@PutEvents' {} Text
a -> PutEvents
s {$sel:trackingId:PutEvents' :: Text
trackingId = Text
a} :: PutEvents)

-- | The session ID associated with the user\'s visit. Your application
-- generates the sessionId when a user first visits your website or uses
-- your application. Amazon Personalize uses the sessionId to associate
-- events with the user before they log in. For more information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
putEvents_sessionId :: Lens.Lens' PutEvents Prelude.Text
putEvents_sessionId :: Lens' PutEvents Text
putEvents_sessionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {Text
sessionId :: Text
$sel:sessionId:PutEvents' :: PutEvents -> Text
sessionId} -> Text
sessionId) (\s :: PutEvents
s@PutEvents' {} Text
a -> PutEvents
s {$sel:sessionId:PutEvents' :: Text
sessionId = Text
a} :: PutEvents)

-- | A list of event data from the session.
putEvents_eventList :: Lens.Lens' PutEvents (Prelude.NonEmpty Event)
putEvents_eventList :: Lens' PutEvents (NonEmpty Event)
putEvents_eventList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {NonEmpty (Sensitive Event)
eventList :: NonEmpty (Sensitive Event)
$sel:eventList:PutEvents' :: PutEvents -> NonEmpty (Sensitive Event)
eventList} -> NonEmpty (Sensitive Event)
eventList) (\s :: PutEvents
s@PutEvents' {} NonEmpty (Sensitive Event)
a -> PutEvents
s {$sel:eventList:PutEvents' :: NonEmpty (Sensitive Event)
eventList = NonEmpty (Sensitive Event)
a} :: PutEvents) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutEvents where
  type AWSResponse PutEvents = PutEventsResponse
  request :: (Service -> Service) -> PutEvents -> Request PutEvents
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutEvents
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutEvents)))
response = forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull PutEventsResponse
PutEventsResponse'

instance Prelude.Hashable PutEvents where
  hashWithSalt :: Int -> PutEvents -> Int
hashWithSalt Int
_salt PutEvents' {Maybe (Sensitive Text)
NonEmpty (Sensitive Event)
Text
eventList :: NonEmpty (Sensitive Event)
sessionId :: Text
trackingId :: Text
userId :: Maybe (Sensitive Text)
$sel:eventList:PutEvents' :: PutEvents -> NonEmpty (Sensitive Event)
$sel:sessionId:PutEvents' :: PutEvents -> Text
$sel:trackingId:PutEvents' :: PutEvents -> Text
$sel:userId:PutEvents' :: PutEvents -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
userId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
trackingId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sessionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty (Sensitive Event)
eventList

instance Prelude.NFData PutEvents where
  rnf :: PutEvents -> ()
rnf PutEvents' {Maybe (Sensitive Text)
NonEmpty (Sensitive Event)
Text
eventList :: NonEmpty (Sensitive Event)
sessionId :: Text
trackingId :: Text
userId :: Maybe (Sensitive Text)
$sel:eventList:PutEvents' :: PutEvents -> NonEmpty (Sensitive Event)
$sel:sessionId:PutEvents' :: PutEvents -> Text
$sel:trackingId:PutEvents' :: PutEvents -> Text
$sel:userId:PutEvents' :: PutEvents -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
userId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
trackingId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sessionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty (Sensitive Event)
eventList

instance Data.ToHeaders PutEvents where
  toHeaders :: PutEvents -> [Header]
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON PutEvents where
  toJSON :: PutEvents -> Value
toJSON PutEvents' {Maybe (Sensitive Text)
NonEmpty (Sensitive Event)
Text
eventList :: NonEmpty (Sensitive Event)
sessionId :: Text
trackingId :: Text
userId :: Maybe (Sensitive Text)
$sel:eventList:PutEvents' :: PutEvents -> NonEmpty (Sensitive Event)
$sel:sessionId:PutEvents' :: PutEvents -> Text
$sel:trackingId:PutEvents' :: PutEvents -> Text
$sel:userId:PutEvents' :: PutEvents -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"userId" 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 (Sensitive Text)
userId,
            forall a. a -> Maybe a
Prelude.Just (Key
"trackingId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
trackingId),
            forall a. a -> Maybe a
Prelude.Just (Key
"sessionId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sessionId),
            forall a. a -> Maybe a
Prelude.Just (Key
"eventList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty (Sensitive Event)
eventList)
          ]
      )

instance Data.ToPath PutEvents where
  toPath :: PutEvents -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/events"

instance Data.ToQuery PutEvents where
  toQuery :: PutEvents -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutEventsResponse' smart constructor.
data PutEventsResponse = PutEventsResponse'
  {
  }
  deriving (PutEventsResponse -> PutEventsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutEventsResponse -> PutEventsResponse -> Bool
$c/= :: PutEventsResponse -> PutEventsResponse -> Bool
== :: PutEventsResponse -> PutEventsResponse -> Bool
$c== :: PutEventsResponse -> PutEventsResponse -> Bool
Prelude.Eq, ReadPrec [PutEventsResponse]
ReadPrec PutEventsResponse
Int -> ReadS PutEventsResponse
ReadS [PutEventsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutEventsResponse]
$creadListPrec :: ReadPrec [PutEventsResponse]
readPrec :: ReadPrec PutEventsResponse
$creadPrec :: ReadPrec PutEventsResponse
readList :: ReadS [PutEventsResponse]
$creadList :: ReadS [PutEventsResponse]
readsPrec :: Int -> ReadS PutEventsResponse
$creadsPrec :: Int -> ReadS PutEventsResponse
Prelude.Read, Int -> PutEventsResponse -> ShowS
[PutEventsResponse] -> ShowS
PutEventsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutEventsResponse] -> ShowS
$cshowList :: [PutEventsResponse] -> ShowS
show :: PutEventsResponse -> String
$cshow :: PutEventsResponse -> String
showsPrec :: Int -> PutEventsResponse -> ShowS
$cshowsPrec :: Int -> PutEventsResponse -> ShowS
Prelude.Show, forall x. Rep PutEventsResponse x -> PutEventsResponse
forall x. PutEventsResponse -> Rep PutEventsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutEventsResponse x -> PutEventsResponse
$cfrom :: forall x. PutEventsResponse -> Rep PutEventsResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutEventsResponse' 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.
newPutEventsResponse ::
  PutEventsResponse
newPutEventsResponse :: PutEventsResponse
newPutEventsResponse = PutEventsResponse
PutEventsResponse'

instance Prelude.NFData PutEventsResponse where
  rnf :: PutEventsResponse -> ()
rnf PutEventsResponse
_ = ()