{-# 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.Pinpoint.Types.EndpointUser
-- 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.Pinpoint.Types.EndpointUser where

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

-- | Specifies data for one or more attributes that describe the user who\'s
-- associated with an endpoint.
--
-- /See:/ 'newEndpointUser' smart constructor.
data EndpointUser = EndpointUser'
  { -- | One or more custom attributes that describe the user by associating a
    -- name with an array of values. For example, the value of an attribute
    -- named Interests might be: [\"Science\", \"Music\", \"Travel\"]. You can
    -- use these attributes as filter criteria when you create segments.
    -- Attribute names are case sensitive.
    --
    -- An attribute name can contain up to 50 characters. An attribute value
    -- can contain up to 100 characters. When you define the name of a custom
    -- attribute, avoid using the following characters: number sign (#), colon
    -- (:), question mark (?), backslash (\\), and slash (\/). The Amazon
    -- Pinpoint console can\'t display attribute names that contain these
    -- characters. This restriction doesn\'t apply to attribute values.
    EndpointUser -> Maybe (HashMap Text [Text])
userAttributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]),
    -- | The unique identifier for the user.
    EndpointUser -> Maybe Text
userId :: Prelude.Maybe Prelude.Text
  }
  deriving (EndpointUser -> EndpointUser -> Bool
(EndpointUser -> EndpointUser -> Bool)
-> (EndpointUser -> EndpointUser -> Bool) -> Eq EndpointUser
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EndpointUser -> EndpointUser -> Bool
$c/= :: EndpointUser -> EndpointUser -> Bool
== :: EndpointUser -> EndpointUser -> Bool
$c== :: EndpointUser -> EndpointUser -> Bool
Prelude.Eq, ReadPrec [EndpointUser]
ReadPrec EndpointUser
Int -> ReadS EndpointUser
ReadS [EndpointUser]
(Int -> ReadS EndpointUser)
-> ReadS [EndpointUser]
-> ReadPrec EndpointUser
-> ReadPrec [EndpointUser]
-> Read EndpointUser
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EndpointUser]
$creadListPrec :: ReadPrec [EndpointUser]
readPrec :: ReadPrec EndpointUser
$creadPrec :: ReadPrec EndpointUser
readList :: ReadS [EndpointUser]
$creadList :: ReadS [EndpointUser]
readsPrec :: Int -> ReadS EndpointUser
$creadsPrec :: Int -> ReadS EndpointUser
Prelude.Read, Int -> EndpointUser -> ShowS
[EndpointUser] -> ShowS
EndpointUser -> String
(Int -> EndpointUser -> ShowS)
-> (EndpointUser -> String)
-> ([EndpointUser] -> ShowS)
-> Show EndpointUser
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EndpointUser] -> ShowS
$cshowList :: [EndpointUser] -> ShowS
show :: EndpointUser -> String
$cshow :: EndpointUser -> String
showsPrec :: Int -> EndpointUser -> ShowS
$cshowsPrec :: Int -> EndpointUser -> ShowS
Prelude.Show, (forall x. EndpointUser -> Rep EndpointUser x)
-> (forall x. Rep EndpointUser x -> EndpointUser)
-> Generic EndpointUser
forall x. Rep EndpointUser x -> EndpointUser
forall x. EndpointUser -> Rep EndpointUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EndpointUser x -> EndpointUser
$cfrom :: forall x. EndpointUser -> Rep EndpointUser x
Prelude.Generic)

-- |
-- Create a value of 'EndpointUser' 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:
--
-- 'userAttributes', 'endpointUser_userAttributes' - One or more custom attributes that describe the user by associating a
-- name with an array of values. For example, the value of an attribute
-- named Interests might be: [\"Science\", \"Music\", \"Travel\"]. You can
-- use these attributes as filter criteria when you create segments.
-- Attribute names are case sensitive.
--
-- An attribute name can contain up to 50 characters. An attribute value
-- can contain up to 100 characters. When you define the name of a custom
-- attribute, avoid using the following characters: number sign (#), colon
-- (:), question mark (?), backslash (\\), and slash (\/). The Amazon
-- Pinpoint console can\'t display attribute names that contain these
-- characters. This restriction doesn\'t apply to attribute values.
--
-- 'userId', 'endpointUser_userId' - The unique identifier for the user.
newEndpointUser ::
  EndpointUser
newEndpointUser :: EndpointUser
newEndpointUser =
  EndpointUser' :: Maybe (HashMap Text [Text]) -> Maybe Text -> EndpointUser
EndpointUser'
    { $sel:userAttributes:EndpointUser' :: Maybe (HashMap Text [Text])
userAttributes = Maybe (HashMap Text [Text])
forall a. Maybe a
Prelude.Nothing,
      $sel:userId:EndpointUser' :: Maybe Text
userId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | One or more custom attributes that describe the user by associating a
-- name with an array of values. For example, the value of an attribute
-- named Interests might be: [\"Science\", \"Music\", \"Travel\"]. You can
-- use these attributes as filter criteria when you create segments.
-- Attribute names are case sensitive.
--
-- An attribute name can contain up to 50 characters. An attribute value
-- can contain up to 100 characters. When you define the name of a custom
-- attribute, avoid using the following characters: number sign (#), colon
-- (:), question mark (?), backslash (\\), and slash (\/). The Amazon
-- Pinpoint console can\'t display attribute names that contain these
-- characters. This restriction doesn\'t apply to attribute values.
endpointUser_userAttributes :: Lens.Lens' EndpointUser (Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]))
endpointUser_userAttributes :: (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> EndpointUser -> f EndpointUser
endpointUser_userAttributes = (EndpointUser -> Maybe (HashMap Text [Text]))
-> (EndpointUser -> Maybe (HashMap Text [Text]) -> EndpointUser)
-> Lens
     EndpointUser
     EndpointUser
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointUser' {Maybe (HashMap Text [Text])
userAttributes :: Maybe (HashMap Text [Text])
$sel:userAttributes:EndpointUser' :: EndpointUser -> Maybe (HashMap Text [Text])
userAttributes} -> Maybe (HashMap Text [Text])
userAttributes) (\s :: EndpointUser
s@EndpointUser' {} Maybe (HashMap Text [Text])
a -> EndpointUser
s {$sel:userAttributes:EndpointUser' :: Maybe (HashMap Text [Text])
userAttributes = Maybe (HashMap Text [Text])
a} :: EndpointUser) ((Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
 -> EndpointUser -> f EndpointUser)
-> ((Maybe (HashMap Text [Text])
     -> f (Maybe (HashMap Text [Text])))
    -> Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> EndpointUser
-> f EndpointUser
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
-> Iso
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [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
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The unique identifier for the user.
endpointUser_userId :: Lens.Lens' EndpointUser (Prelude.Maybe Prelude.Text)
endpointUser_userId :: (Maybe Text -> f (Maybe Text)) -> EndpointUser -> f EndpointUser
endpointUser_userId = (EndpointUser -> Maybe Text)
-> (EndpointUser -> Maybe Text -> EndpointUser)
-> Lens EndpointUser EndpointUser (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointUser' {Maybe Text
userId :: Maybe Text
$sel:userId:EndpointUser' :: EndpointUser -> Maybe Text
userId} -> Maybe Text
userId) (\s :: EndpointUser
s@EndpointUser' {} Maybe Text
a -> EndpointUser
s {$sel:userId:EndpointUser' :: Maybe Text
userId = Maybe Text
a} :: EndpointUser)

instance Core.FromJSON EndpointUser where
  parseJSON :: Value -> Parser EndpointUser
parseJSON =
    String
-> (Object -> Parser EndpointUser) -> Value -> Parser EndpointUser
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EndpointUser"
      ( \Object
x ->
          Maybe (HashMap Text [Text]) -> Maybe Text -> EndpointUser
EndpointUser'
            (Maybe (HashMap Text [Text]) -> Maybe Text -> EndpointUser)
-> Parser (Maybe (HashMap Text [Text]))
-> Parser (Maybe Text -> EndpointUser)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text [Text])))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"UserAttributes" Parser (Maybe (Maybe (HashMap Text [Text])))
-> Maybe (HashMap Text [Text])
-> Parser (Maybe (HashMap Text [Text]))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text [Text])
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> EndpointUser)
-> Parser (Maybe Text) -> Parser EndpointUser
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"UserId")
      )

instance Prelude.Hashable EndpointUser

instance Prelude.NFData EndpointUser

instance Core.ToJSON EndpointUser where
  toJSON :: EndpointUser -> Value
toJSON EndpointUser' {Maybe Text
Maybe (HashMap Text [Text])
userId :: Maybe Text
userAttributes :: Maybe (HashMap Text [Text])
$sel:userId:EndpointUser' :: EndpointUser -> Maybe Text
$sel:userAttributes:EndpointUser' :: EndpointUser -> Maybe (HashMap Text [Text])
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"UserAttributes" Text -> HashMap Text [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text [Text] -> Pair)
-> Maybe (HashMap Text [Text]) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text [Text])
userAttributes,
            (Text
"UserId" 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
userId
          ]
      )