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

-- | Represents user metadata added to a Users dataset using the @PutUsers@
-- API. For more information see
-- <https://docs.aws.amazon.com/personalize/latest/dg/importing-users.html Importing Users Incrementally>.
--
-- /See:/ 'newUser' smart constructor.
data User = User'
  { -- | A string map of user-specific metadata. Each element in the map consists
    -- of a key-value pair. For example, @{\"numberOfVideosWatched\": \"45\"}@.
    --
    -- The keys use camel case names that match the fields in the schema for
    -- the Users dataset. In the previous example, the @numberOfVideosWatched@
    -- matches the \'NUMBER_OF_VIDEOS_WATCHED\' field defined in the Users
    -- schema. For categorical string data, to include multiple categories for
    -- a single user, separate each category with a pipe separator (@|@). For
    -- example, @\\\"Member|Frequent shopper\\\"@.
    User -> Maybe (Sensitive Text)
properties :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The ID associated with the user.
    User -> Text
userId :: Prelude.Text
  }
  deriving (User -> User -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: User -> User -> Bool
$c/= :: User -> User -> Bool
== :: User -> User -> Bool
$c== :: User -> User -> Bool
Prelude.Eq, Int -> User -> ShowS
[User] -> ShowS
User -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [User] -> ShowS
$cshowList :: [User] -> ShowS
show :: User -> String
$cshow :: User -> String
showsPrec :: Int -> User -> ShowS
$cshowsPrec :: Int -> User -> ShowS
Prelude.Show, forall x. Rep User x -> User
forall x. User -> Rep User x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep User x -> User
$cfrom :: forall x. User -> Rep User x
Prelude.Generic)

-- |
-- Create a value of 'User' 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:
--
-- 'properties', 'user_properties' - A string map of user-specific metadata. Each element in the map consists
-- of a key-value pair. For example, @{\"numberOfVideosWatched\": \"45\"}@.
--
-- The keys use camel case names that match the fields in the schema for
-- the Users dataset. In the previous example, the @numberOfVideosWatched@
-- matches the \'NUMBER_OF_VIDEOS_WATCHED\' field defined in the Users
-- schema. For categorical string data, to include multiple categories for
-- a single user, separate each category with a pipe separator (@|@). For
-- example, @\\\"Member|Frequent shopper\\\"@.
--
-- 'userId', 'user_userId' - The ID associated with the user.
newUser ::
  -- | 'userId'
  Prelude.Text ->
  User
newUser :: Text -> User
newUser Text
pUserId_ =
  User'
    { $sel:properties:User' :: Maybe (Sensitive Text)
properties = forall a. Maybe a
Prelude.Nothing,
      $sel:userId:User' :: Text
userId = Text
pUserId_
    }

-- | A string map of user-specific metadata. Each element in the map consists
-- of a key-value pair. For example, @{\"numberOfVideosWatched\": \"45\"}@.
--
-- The keys use camel case names that match the fields in the schema for
-- the Users dataset. In the previous example, the @numberOfVideosWatched@
-- matches the \'NUMBER_OF_VIDEOS_WATCHED\' field defined in the Users
-- schema. For categorical string data, to include multiple categories for
-- a single user, separate each category with a pipe separator (@|@). For
-- example, @\\\"Member|Frequent shopper\\\"@.
user_properties :: Lens.Lens' User (Prelude.Maybe Prelude.Text)
user_properties :: Lens' User (Maybe Text)
user_properties = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Maybe (Sensitive Text)
properties :: Maybe (Sensitive Text)
$sel:properties:User' :: User -> Maybe (Sensitive Text)
properties} -> Maybe (Sensitive Text)
properties) (\s :: User
s@User' {} Maybe (Sensitive Text)
a -> User
s {$sel:properties:User' :: Maybe (Sensitive Text)
properties = Maybe (Sensitive Text)
a} :: User) 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 ID associated with the user.
user_userId :: Lens.Lens' User Prelude.Text
user_userId :: Lens' User Text
user_userId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Text
userId :: Text
$sel:userId:User' :: User -> Text
userId} -> Text
userId) (\s :: User
s@User' {} Text
a -> User
s {$sel:userId:User' :: Text
userId = Text
a} :: User)

instance Prelude.Hashable User where
  hashWithSalt :: Int -> User -> Int
hashWithSalt Int
_salt User' {Maybe (Sensitive Text)
Text
userId :: Text
properties :: Maybe (Sensitive Text)
$sel:userId:User' :: User -> Text
$sel:properties:User' :: User -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
properties
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
userId

instance Prelude.NFData User where
  rnf :: User -> ()
rnf User' {Maybe (Sensitive Text)
Text
userId :: Text
properties :: Maybe (Sensitive Text)
$sel:userId:User' :: User -> Text
$sel:properties:User' :: User -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
properties
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
userId

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