{-# 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-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.WorkDocs.Types.SharePrincipal where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(SharePrincipal -> SharePrincipal -> Bool)
-> (SharePrincipal -> SharePrincipal -> Bool) -> Eq SharePrincipal
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]
(Int -> ReadS SharePrincipal)
-> ReadS [SharePrincipal]
-> ReadPrec SharePrincipal
-> ReadPrec [SharePrincipal]
-> Read 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
(Int -> SharePrincipal -> ShowS)
-> (SharePrincipal -> String)
-> ([SharePrincipal] -> ShowS)
-> Show SharePrincipal
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. SharePrincipal -> Rep SharePrincipal x)
-> (forall x. Rep SharePrincipal x -> SharePrincipal)
-> Generic SharePrincipal
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' :: Text -> PrincipalType -> RoleType -> SharePrincipal
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 :: (Text -> f Text) -> SharePrincipal -> f SharePrincipal
sharePrincipal_id = (SharePrincipal -> Text)
-> (SharePrincipal -> Text -> SharePrincipal)
-> Lens SharePrincipal SharePrincipal Text Text
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 :: (PrincipalType -> f PrincipalType)
-> SharePrincipal -> f SharePrincipal
sharePrincipal_type = (SharePrincipal -> PrincipalType)
-> (SharePrincipal -> PrincipalType -> SharePrincipal)
-> Lens SharePrincipal SharePrincipal PrincipalType PrincipalType
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 :: (RoleType -> f RoleType) -> SharePrincipal -> f SharePrincipal
sharePrincipal_role = (SharePrincipal -> RoleType)
-> (SharePrincipal -> RoleType -> SharePrincipal)
-> Lens SharePrincipal SharePrincipal RoleType RoleType
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

instance Prelude.NFData SharePrincipal

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> PrincipalType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PrincipalType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Role" Text -> RoleType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RoleType
role')
          ]
      )