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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 Text
properties :: Prelude.Maybe Prelude.Text,
    -- | The ID associated with the user.
    User -> Text
userId :: Prelude.Text
  }
  deriving (User -> User -> Bool
(User -> User -> Bool) -> (User -> User -> Bool) -> Eq User
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, ReadPrec [User]
ReadPrec User
Int -> ReadS User
ReadS [User]
(Int -> ReadS User)
-> ReadS [User] -> ReadPrec User -> ReadPrec [User] -> Read User
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [User]
$creadListPrec :: ReadPrec [User]
readPrec :: ReadPrec User
$creadPrec :: ReadPrec User
readList :: ReadS [User]
$creadList :: ReadS [User]
readsPrec :: Int -> ReadS User
$creadsPrec :: Int -> ReadS User
Prelude.Read, Int -> User -> ShowS
[User] -> ShowS
User -> String
(Int -> User -> ShowS)
-> (User -> String) -> ([User] -> ShowS) -> Show User
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. User -> Rep User x)
-> (forall x. Rep User x -> User) -> Generic User
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' :: Maybe Text -> Text -> User
User'
    { $sel:properties:User' :: Maybe Text
properties = Maybe Text
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 :: (Maybe Text -> f (Maybe Text)) -> User -> f User
user_properties = (User -> Maybe Text)
-> (User -> Maybe Text -> User)
-> Lens User User (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Maybe Text
properties :: Maybe Text
$sel:properties:User' :: User -> Maybe Text
properties} -> Maybe Text
properties) (\s :: User
s@User' {} Maybe Text
a -> User
s {$sel:properties:User' :: Maybe Text
properties = Maybe Text
a} :: User)

-- | The ID associated with the user.
user_userId :: Lens.Lens' User Prelude.Text
user_userId :: (Text -> f Text) -> User -> f User
user_userId = (User -> Text)
-> (User -> Text -> User) -> Lens User User Text Text
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

instance Prelude.NFData User

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