{-# 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.Principal
-- 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.Principal 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.PrincipalType
import Amazonka.Kendra.Types.ReadAccessType
import qualified Amazonka.Prelude as Prelude

-- | Provides user and group information for
-- <https://docs.aws.amazon.com/kendra/latest/dg/user-context-filter.html user context filtering>.
--
-- /See:/ 'newPrincipal' smart constructor.
data Principal = Principal'
  { -- | The identifier of the data source the principal should access documents
    -- from.
    Principal -> Maybe Text
dataSourceId :: Prelude.Maybe Prelude.Text,
    -- | The name of the user or group.
    Principal -> Text
name :: Prelude.Text,
    -- | The type of principal.
    Principal -> PrincipalType
type' :: PrincipalType,
    -- | Whether to allow or deny document access to the principal.
    Principal -> ReadAccessType
access :: ReadAccessType
  }
  deriving (Principal -> Principal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Principal -> Principal -> Bool
$c/= :: Principal -> Principal -> Bool
== :: Principal -> Principal -> Bool
$c== :: Principal -> Principal -> Bool
Prelude.Eq, ReadPrec [Principal]
ReadPrec Principal
Int -> ReadS Principal
ReadS [Principal]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Principal]
$creadListPrec :: ReadPrec [Principal]
readPrec :: ReadPrec Principal
$creadPrec :: ReadPrec Principal
readList :: ReadS [Principal]
$creadList :: ReadS [Principal]
readsPrec :: Int -> ReadS Principal
$creadsPrec :: Int -> ReadS Principal
Prelude.Read, Int -> Principal -> ShowS
[Principal] -> ShowS
Principal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Principal] -> ShowS
$cshowList :: [Principal] -> ShowS
show :: Principal -> String
$cshow :: Principal -> String
showsPrec :: Int -> Principal -> ShowS
$cshowsPrec :: Int -> Principal -> ShowS
Prelude.Show, forall x. Rep Principal x -> Principal
forall x. Principal -> Rep Principal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Principal x -> Principal
$cfrom :: forall x. Principal -> Rep Principal x
Prelude.Generic)

-- |
-- Create a value of 'Principal' 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:
--
-- 'dataSourceId', 'principal_dataSourceId' - The identifier of the data source the principal should access documents
-- from.
--
-- 'name', 'principal_name' - The name of the user or group.
--
-- 'type'', 'principal_type' - The type of principal.
--
-- 'access', 'principal_access' - Whether to allow or deny document access to the principal.
newPrincipal ::
  -- | 'name'
  Prelude.Text ->
  -- | 'type''
  PrincipalType ->
  -- | 'access'
  ReadAccessType ->
  Principal
newPrincipal :: Text -> PrincipalType -> ReadAccessType -> Principal
newPrincipal Text
pName_ PrincipalType
pType_ ReadAccessType
pAccess_ =
  Principal'
    { $sel:dataSourceId:Principal' :: Maybe Text
dataSourceId = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Principal' :: Text
name = Text
pName_,
      $sel:type':Principal' :: PrincipalType
type' = PrincipalType
pType_,
      $sel:access:Principal' :: ReadAccessType
access = ReadAccessType
pAccess_
    }

-- | The identifier of the data source the principal should access documents
-- from.
principal_dataSourceId :: Lens.Lens' Principal (Prelude.Maybe Prelude.Text)
principal_dataSourceId :: Lens' Principal (Maybe Text)
principal_dataSourceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Maybe Text
dataSourceId :: Maybe Text
$sel:dataSourceId:Principal' :: Principal -> Maybe Text
dataSourceId} -> Maybe Text
dataSourceId) (\s :: Principal
s@Principal' {} Maybe Text
a -> Principal
s {$sel:dataSourceId:Principal' :: Maybe Text
dataSourceId = Maybe Text
a} :: Principal)

-- | The name of the user or group.
principal_name :: Lens.Lens' Principal Prelude.Text
principal_name :: Lens' Principal Text
principal_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Text
name :: Text
$sel:name:Principal' :: Principal -> Text
name} -> Text
name) (\s :: Principal
s@Principal' {} Text
a -> Principal
s {$sel:name:Principal' :: Text
name = Text
a} :: Principal)

-- | The type of principal.
principal_type :: Lens.Lens' Principal PrincipalType
principal_type :: Lens' Principal PrincipalType
principal_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {PrincipalType
type' :: PrincipalType
$sel:type':Principal' :: Principal -> PrincipalType
type'} -> PrincipalType
type') (\s :: Principal
s@Principal' {} PrincipalType
a -> Principal
s {$sel:type':Principal' :: PrincipalType
type' = PrincipalType
a} :: Principal)

-- | Whether to allow or deny document access to the principal.
principal_access :: Lens.Lens' Principal ReadAccessType
principal_access :: Lens' Principal ReadAccessType
principal_access = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {ReadAccessType
access :: ReadAccessType
$sel:access:Principal' :: Principal -> ReadAccessType
access} -> ReadAccessType
access) (\s :: Principal
s@Principal' {} ReadAccessType
a -> Principal
s {$sel:access:Principal' :: ReadAccessType
access = ReadAccessType
a} :: Principal)

instance Data.FromJSON Principal where
  parseJSON :: Value -> Parser Principal
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Principal"
      ( \Object
x ->
          Maybe Text -> Text -> PrincipalType -> ReadAccessType -> Principal
Principal'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DataSourceId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Type")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Access")
      )

instance Prelude.Hashable Principal where
  hashWithSalt :: Int -> Principal -> Int
hashWithSalt Int
_salt Principal' {Maybe Text
Text
PrincipalType
ReadAccessType
access :: ReadAccessType
type' :: PrincipalType
name :: Text
dataSourceId :: Maybe Text
$sel:access:Principal' :: Principal -> ReadAccessType
$sel:type':Principal' :: Principal -> PrincipalType
$sel:name:Principal' :: Principal -> Text
$sel:dataSourceId:Principal' :: Principal -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
dataSourceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PrincipalType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ReadAccessType
access

instance Prelude.NFData Principal where
  rnf :: Principal -> ()
rnf Principal' {Maybe Text
Text
PrincipalType
ReadAccessType
access :: ReadAccessType
type' :: PrincipalType
name :: Text
dataSourceId :: Maybe Text
$sel:access:Principal' :: Principal -> ReadAccessType
$sel:type':Principal' :: Principal -> PrincipalType
$sel:name:Principal' :: Principal -> Text
$sel:dataSourceId:Principal' :: Principal -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
dataSourceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PrincipalType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ReadAccessType
access

instance Data.ToJSON Principal where
  toJSON :: Principal -> Value
toJSON Principal' {Maybe Text
Text
PrincipalType
ReadAccessType
access :: ReadAccessType
type' :: PrincipalType
name :: Text
dataSourceId :: Maybe Text
$sel:access:Principal' :: Principal -> ReadAccessType
$sel:type':Principal' :: Principal -> PrincipalType
$sel:name:Principal' :: Principal -> Text
$sel:dataSourceId:Principal' :: Principal -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DataSourceId" 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
dataSourceId,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= PrincipalType
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"Access" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ReadAccessType
access)
          ]
      )