{-# 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.Kendra.Types.UserContext
-- 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.Kendra.Types.UserContext where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Kendra.Types.DataSourceGroup
import qualified Amazonka.Prelude as Prelude

-- | Provides information about the user context for an Amazon Kendra index.
--
-- User context filtering is a kind of personalized search with the benefit
-- of controlling access to documents. For example, not all teams that
-- search the company portal for information should access top-secret
-- company documents, nor are these documents relevant to all users. Only
-- specific users or groups of teams given access to top-secret documents
-- should see these documents in their search results.
--
-- You provide one of the following:
--
-- -   User token
--
-- -   User ID, the groups the user belongs to, and any data sources the
--     groups can access.
--
-- If you provide both, an exception is thrown.
--
-- /See:/ 'newUserContext' smart constructor.
data UserContext = UserContext'
  { -- | The list of data source groups you want to filter search results based
    -- on groups\' access to documents in that data source.
    UserContext -> Maybe (NonEmpty DataSourceGroup)
dataSourceGroups :: Prelude.Maybe (Prelude.NonEmpty DataSourceGroup),
    -- | The list of groups you want to filter search results based on the
    -- groups\' access to documents.
    UserContext -> Maybe (NonEmpty Text)
groups :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The user context token for filtering search results for a user. It must
    -- be a JWT or a JSON token.
    UserContext -> Maybe Text
token :: Prelude.Maybe Prelude.Text,
    -- | The identifier of the user you want to filter search results based on
    -- their access to documents.
    UserContext -> Maybe Text
userId :: Prelude.Maybe Prelude.Text
  }
  deriving (UserContext -> UserContext -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserContext -> UserContext -> Bool
$c/= :: UserContext -> UserContext -> Bool
== :: UserContext -> UserContext -> Bool
$c== :: UserContext -> UserContext -> Bool
Prelude.Eq, ReadPrec [UserContext]
ReadPrec UserContext
Int -> ReadS UserContext
ReadS [UserContext]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserContext]
$creadListPrec :: ReadPrec [UserContext]
readPrec :: ReadPrec UserContext
$creadPrec :: ReadPrec UserContext
readList :: ReadS [UserContext]
$creadList :: ReadS [UserContext]
readsPrec :: Int -> ReadS UserContext
$creadsPrec :: Int -> ReadS UserContext
Prelude.Read, Int -> UserContext -> ShowS
[UserContext] -> ShowS
UserContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserContext] -> ShowS
$cshowList :: [UserContext] -> ShowS
show :: UserContext -> String
$cshow :: UserContext -> String
showsPrec :: Int -> UserContext -> ShowS
$cshowsPrec :: Int -> UserContext -> ShowS
Prelude.Show, forall x. Rep UserContext x -> UserContext
forall x. UserContext -> Rep UserContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UserContext x -> UserContext
$cfrom :: forall x. UserContext -> Rep UserContext x
Prelude.Generic)

-- |
-- Create a value of 'UserContext' 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:
--
-- 'dataSourceGroups', 'userContext_dataSourceGroups' - The list of data source groups you want to filter search results based
-- on groups\' access to documents in that data source.
--
-- 'groups', 'userContext_groups' - The list of groups you want to filter search results based on the
-- groups\' access to documents.
--
-- 'token', 'userContext_token' - The user context token for filtering search results for a user. It must
-- be a JWT or a JSON token.
--
-- 'userId', 'userContext_userId' - The identifier of the user you want to filter search results based on
-- their access to documents.
newUserContext ::
  UserContext
newUserContext :: UserContext
newUserContext =
  UserContext'
    { $sel:dataSourceGroups:UserContext' :: Maybe (NonEmpty DataSourceGroup)
dataSourceGroups = forall a. Maybe a
Prelude.Nothing,
      $sel:groups:UserContext' :: Maybe (NonEmpty Text)
groups = forall a. Maybe a
Prelude.Nothing,
      $sel:token:UserContext' :: Maybe Text
token = forall a. Maybe a
Prelude.Nothing,
      $sel:userId:UserContext' :: Maybe Text
userId = forall a. Maybe a
Prelude.Nothing
    }

-- | The list of data source groups you want to filter search results based
-- on groups\' access to documents in that data source.
userContext_dataSourceGroups :: Lens.Lens' UserContext (Prelude.Maybe (Prelude.NonEmpty DataSourceGroup))
userContext_dataSourceGroups :: Lens' UserContext (Maybe (NonEmpty DataSourceGroup))
userContext_dataSourceGroups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserContext' {Maybe (NonEmpty DataSourceGroup)
dataSourceGroups :: Maybe (NonEmpty DataSourceGroup)
$sel:dataSourceGroups:UserContext' :: UserContext -> Maybe (NonEmpty DataSourceGroup)
dataSourceGroups} -> Maybe (NonEmpty DataSourceGroup)
dataSourceGroups) (\s :: UserContext
s@UserContext' {} Maybe (NonEmpty DataSourceGroup)
a -> UserContext
s {$sel:dataSourceGroups:UserContext' :: Maybe (NonEmpty DataSourceGroup)
dataSourceGroups = Maybe (NonEmpty DataSourceGroup)
a} :: UserContext) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The list of groups you want to filter search results based on the
-- groups\' access to documents.
userContext_groups :: Lens.Lens' UserContext (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
userContext_groups :: Lens' UserContext (Maybe (NonEmpty Text))
userContext_groups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserContext' {Maybe (NonEmpty Text)
groups :: Maybe (NonEmpty Text)
$sel:groups:UserContext' :: UserContext -> Maybe (NonEmpty Text)
groups} -> Maybe (NonEmpty Text)
groups) (\s :: UserContext
s@UserContext' {} Maybe (NonEmpty Text)
a -> UserContext
s {$sel:groups:UserContext' :: Maybe (NonEmpty Text)
groups = Maybe (NonEmpty Text)
a} :: UserContext) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The user context token for filtering search results for a user. It must
-- be a JWT or a JSON token.
userContext_token :: Lens.Lens' UserContext (Prelude.Maybe Prelude.Text)
userContext_token :: Lens' UserContext (Maybe Text)
userContext_token = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserContext' {Maybe Text
token :: Maybe Text
$sel:token:UserContext' :: UserContext -> Maybe Text
token} -> Maybe Text
token) (\s :: UserContext
s@UserContext' {} Maybe Text
a -> UserContext
s {$sel:token:UserContext' :: Maybe Text
token = Maybe Text
a} :: UserContext)

-- | The identifier of the user you want to filter search results based on
-- their access to documents.
userContext_userId :: Lens.Lens' UserContext (Prelude.Maybe Prelude.Text)
userContext_userId :: Lens' UserContext (Maybe Text)
userContext_userId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserContext' {Maybe Text
userId :: Maybe Text
$sel:userId:UserContext' :: UserContext -> Maybe Text
userId} -> Maybe Text
userId) (\s :: UserContext
s@UserContext' {} Maybe Text
a -> UserContext
s {$sel:userId:UserContext' :: Maybe Text
userId = Maybe Text
a} :: UserContext)

instance Prelude.Hashable UserContext where
  hashWithSalt :: Int -> UserContext -> Int
hashWithSalt Int
_salt UserContext' {Maybe (NonEmpty Text)
Maybe (NonEmpty DataSourceGroup)
Maybe Text
userId :: Maybe Text
token :: Maybe Text
groups :: Maybe (NonEmpty Text)
dataSourceGroups :: Maybe (NonEmpty DataSourceGroup)
$sel:userId:UserContext' :: UserContext -> Maybe Text
$sel:token:UserContext' :: UserContext -> Maybe Text
$sel:groups:UserContext' :: UserContext -> Maybe (NonEmpty Text)
$sel:dataSourceGroups:UserContext' :: UserContext -> Maybe (NonEmpty DataSourceGroup)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty DataSourceGroup)
dataSourceGroups
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
groups
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
token
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
userId

instance Prelude.NFData UserContext where
  rnf :: UserContext -> ()
rnf UserContext' {Maybe (NonEmpty Text)
Maybe (NonEmpty DataSourceGroup)
Maybe Text
userId :: Maybe Text
token :: Maybe Text
groups :: Maybe (NonEmpty Text)
dataSourceGroups :: Maybe (NonEmpty DataSourceGroup)
$sel:userId:UserContext' :: UserContext -> Maybe Text
$sel:token:UserContext' :: UserContext -> Maybe Text
$sel:groups:UserContext' :: UserContext -> Maybe (NonEmpty Text)
$sel:dataSourceGroups:UserContext' :: UserContext -> Maybe (NonEmpty DataSourceGroup)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty DataSourceGroup)
dataSourceGroups
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
groups
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
token
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
userId

instance Data.ToJSON UserContext where
  toJSON :: UserContext -> Value
toJSON UserContext' {Maybe (NonEmpty Text)
Maybe (NonEmpty DataSourceGroup)
Maybe Text
userId :: Maybe Text
token :: Maybe Text
groups :: Maybe (NonEmpty Text)
dataSourceGroups :: Maybe (NonEmpty DataSourceGroup)
$sel:userId:UserContext' :: UserContext -> Maybe Text
$sel:token:UserContext' :: UserContext -> Maybe Text
$sel:groups:UserContext' :: UserContext -> Maybe (NonEmpty Text)
$sel:dataSourceGroups:UserContext' :: UserContext -> Maybe (NonEmpty DataSourceGroup)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DataSourceGroups" 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 (NonEmpty DataSourceGroup)
dataSourceGroups,
            (Key
"Groups" 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 (NonEmpty Text)
groups,
            (Key
"Token" 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 Text
token,
            (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 Text
userId
          ]
      )