{-# 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.WorkDocs.Types.SharePrincipal
-- 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.WorkDocs.Types.SharePrincipal 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
import Amazonka.WorkDocs.Types.PrincipalType
import Amazonka.WorkDocs.Types.RoleType

-- | Describes the recipient type and ID, if available.
--
-- /See:/ 'newSharePrincipal' smart constructor.
data SharePrincipal = SharePrincipal'
  { -- | The ID of the recipient.
    SharePrincipal -> Text
id :: Prelude.Text,
    -- | The type of the recipient.
    SharePrincipal -> PrincipalType
type' :: PrincipalType,
    -- | The role of the recipient.
    SharePrincipal -> RoleType
role' :: RoleType
  }
  deriving (SharePrincipal -> SharePrincipal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SharePrincipal -> SharePrincipal -> Bool
$c/= :: SharePrincipal -> SharePrincipal -> Bool
== :: SharePrincipal -> SharePrincipal -> Bool
$c== :: SharePrincipal -> SharePrincipal -> Bool
Prelude.Eq, ReadPrec [SharePrincipal]
ReadPrec SharePrincipal
Int -> ReadS SharePrincipal
ReadS [SharePrincipal]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SharePrincipal]
$creadListPrec :: ReadPrec [SharePrincipal]
readPrec :: ReadPrec SharePrincipal
$creadPrec :: ReadPrec SharePrincipal
readList :: ReadS [SharePrincipal]
$creadList :: ReadS [SharePrincipal]
readsPrec :: Int -> ReadS SharePrincipal
$creadsPrec :: Int -> ReadS SharePrincipal
Prelude.Read, Int -> SharePrincipal -> ShowS
[SharePrincipal] -> ShowS
SharePrincipal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SharePrincipal] -> ShowS
$cshowList :: [SharePrincipal] -> ShowS
show :: SharePrincipal -> String
$cshow :: SharePrincipal -> String
showsPrec :: Int -> SharePrincipal -> ShowS
$cshowsPrec :: Int -> SharePrincipal -> ShowS
Prelude.Show, forall x. Rep SharePrincipal x -> SharePrincipal
forall x. SharePrincipal -> Rep SharePrincipal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SharePrincipal x -> SharePrincipal
$cfrom :: forall x. SharePrincipal -> Rep SharePrincipal x
Prelude.Generic)

-- |
-- Create a value of 'SharePrincipal' 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:
--
-- 'id', 'sharePrincipal_id' - The ID of the recipient.
--
-- 'type'', 'sharePrincipal_type' - The type of the recipient.
--
-- 'role'', 'sharePrincipal_role' - The role of the recipient.
newSharePrincipal ::
  -- | 'id'
  Prelude.Text ->
  -- | 'type''
  PrincipalType ->
  -- | 'role''
  RoleType ->
  SharePrincipal
newSharePrincipal :: Text -> PrincipalType -> RoleType -> SharePrincipal
newSharePrincipal Text
pId_ PrincipalType
pType_ RoleType
pRole_ =
  SharePrincipal'
    { $sel:id:SharePrincipal' :: Text
id = Text
pId_,
      $sel:type':SharePrincipal' :: PrincipalType
type' = PrincipalType
pType_,
      $sel:role':SharePrincipal' :: RoleType
role' = RoleType
pRole_
    }

-- | The ID of the recipient.
sharePrincipal_id :: Lens.Lens' SharePrincipal Prelude.Text
sharePrincipal_id :: Lens' SharePrincipal Text
sharePrincipal_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SharePrincipal' {Text
id :: Text
$sel:id:SharePrincipal' :: SharePrincipal -> Text
id} -> Text
id) (\s :: SharePrincipal
s@SharePrincipal' {} Text
a -> SharePrincipal
s {$sel:id:SharePrincipal' :: Text
id = Text
a} :: SharePrincipal)

-- | The type of the recipient.
sharePrincipal_type :: Lens.Lens' SharePrincipal PrincipalType
sharePrincipal_type :: Lens' SharePrincipal PrincipalType
sharePrincipal_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SharePrincipal' {PrincipalType
type' :: PrincipalType
$sel:type':SharePrincipal' :: SharePrincipal -> PrincipalType
type'} -> PrincipalType
type') (\s :: SharePrincipal
s@SharePrincipal' {} PrincipalType
a -> SharePrincipal
s {$sel:type':SharePrincipal' :: PrincipalType
type' = PrincipalType
a} :: SharePrincipal)

-- | The role of the recipient.
sharePrincipal_role :: Lens.Lens' SharePrincipal RoleType
sharePrincipal_role :: Lens' SharePrincipal RoleType
sharePrincipal_role = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SharePrincipal' {RoleType
role' :: RoleType
$sel:role':SharePrincipal' :: SharePrincipal -> RoleType
role'} -> RoleType
role') (\s :: SharePrincipal
s@SharePrincipal' {} RoleType
a -> SharePrincipal
s {$sel:role':SharePrincipal' :: RoleType
role' = RoleType
a} :: SharePrincipal)

instance Prelude.Hashable SharePrincipal where
  hashWithSalt :: Int -> SharePrincipal -> Int
hashWithSalt Int
_salt SharePrincipal' {Text
PrincipalType
RoleType
role' :: RoleType
type' :: PrincipalType
id :: Text
$sel:role':SharePrincipal' :: SharePrincipal -> RoleType
$sel:type':SharePrincipal' :: SharePrincipal -> PrincipalType
$sel:id:SharePrincipal' :: SharePrincipal -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PrincipalType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RoleType
role'

instance Prelude.NFData SharePrincipal where
  rnf :: SharePrincipal -> ()
rnf SharePrincipal' {Text
PrincipalType
RoleType
role' :: RoleType
type' :: PrincipalType
id :: Text
$sel:role':SharePrincipal' :: SharePrincipal -> RoleType
$sel:type':SharePrincipal' :: SharePrincipal -> PrincipalType
$sel:id:SharePrincipal' :: SharePrincipal -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
id
      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 RoleType
role'

instance Data.ToJSON SharePrincipal where
  toJSON :: SharePrincipal -> Value
toJSON SharePrincipal' {Text
PrincipalType
RoleType
role' :: RoleType
type' :: PrincipalType
id :: Text
$sel:role':SharePrincipal' :: SharePrincipal -> RoleType
$sel:type':SharePrincipal' :: SharePrincipal -> PrincipalType
$sel:id:SharePrincipal' :: SharePrincipal -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id),
            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
"Role" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= RoleType
role')
          ]
      )