{-# 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.WorkMail.Types.Permission
-- 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.WorkMail.Types.Permission 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.WorkMail.Types.MemberType
import Amazonka.WorkMail.Types.PermissionType

-- | Permission granted to a user, group, or resource to access a certain
-- aspect of another user, group, or resource mailbox.
--
-- /See:/ 'newPermission' smart constructor.
data Permission = Permission'
  { -- | The identifier of the user, group, or resource to which the permissions
    -- are granted.
    Permission -> Text
granteeId :: Prelude.Text,
    -- | The type of user, group, or resource referred to in GranteeId.
    Permission -> MemberType
granteeType :: MemberType,
    -- | The permissions granted to the grantee. SEND_AS allows the grantee to
    -- send email as the owner of the mailbox (the grantee is not mentioned on
    -- these emails). SEND_ON_BEHALF allows the grantee to send email on behalf
    -- of the owner of the mailbox (the grantee is not mentioned as the
    -- physical sender of these emails). FULL_ACCESS allows the grantee full
    -- access to the mailbox, irrespective of other folder-level permissions
    -- set on the mailbox.
    Permission -> [PermissionType]
permissionValues :: [PermissionType]
  }
  deriving (Permission -> Permission -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Permission -> Permission -> Bool
$c/= :: Permission -> Permission -> Bool
== :: Permission -> Permission -> Bool
$c== :: Permission -> Permission -> Bool
Prelude.Eq, ReadPrec [Permission]
ReadPrec Permission
Int -> ReadS Permission
ReadS [Permission]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Permission]
$creadListPrec :: ReadPrec [Permission]
readPrec :: ReadPrec Permission
$creadPrec :: ReadPrec Permission
readList :: ReadS [Permission]
$creadList :: ReadS [Permission]
readsPrec :: Int -> ReadS Permission
$creadsPrec :: Int -> ReadS Permission
Prelude.Read, Int -> Permission -> ShowS
[Permission] -> ShowS
Permission -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Permission] -> ShowS
$cshowList :: [Permission] -> ShowS
show :: Permission -> String
$cshow :: Permission -> String
showsPrec :: Int -> Permission -> ShowS
$cshowsPrec :: Int -> Permission -> ShowS
Prelude.Show, forall x. Rep Permission x -> Permission
forall x. Permission -> Rep Permission x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Permission x -> Permission
$cfrom :: forall x. Permission -> Rep Permission x
Prelude.Generic)

-- |
-- Create a value of 'Permission' 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:
--
-- 'granteeId', 'permission_granteeId' - The identifier of the user, group, or resource to which the permissions
-- are granted.
--
-- 'granteeType', 'permission_granteeType' - The type of user, group, or resource referred to in GranteeId.
--
-- 'permissionValues', 'permission_permissionValues' - The permissions granted to the grantee. SEND_AS allows the grantee to
-- send email as the owner of the mailbox (the grantee is not mentioned on
-- these emails). SEND_ON_BEHALF allows the grantee to send email on behalf
-- of the owner of the mailbox (the grantee is not mentioned as the
-- physical sender of these emails). FULL_ACCESS allows the grantee full
-- access to the mailbox, irrespective of other folder-level permissions
-- set on the mailbox.
newPermission ::
  -- | 'granteeId'
  Prelude.Text ->
  -- | 'granteeType'
  MemberType ->
  Permission
newPermission :: Text -> MemberType -> Permission
newPermission Text
pGranteeId_ MemberType
pGranteeType_ =
  Permission'
    { $sel:granteeId:Permission' :: Text
granteeId = Text
pGranteeId_,
      $sel:granteeType:Permission' :: MemberType
granteeType = MemberType
pGranteeType_,
      $sel:permissionValues:Permission' :: [PermissionType]
permissionValues = forall a. Monoid a => a
Prelude.mempty
    }

-- | The identifier of the user, group, or resource to which the permissions
-- are granted.
permission_granteeId :: Lens.Lens' Permission Prelude.Text
permission_granteeId :: Lens' Permission Text
permission_granteeId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Text
granteeId :: Text
$sel:granteeId:Permission' :: Permission -> Text
granteeId} -> Text
granteeId) (\s :: Permission
s@Permission' {} Text
a -> Permission
s {$sel:granteeId:Permission' :: Text
granteeId = Text
a} :: Permission)

-- | The type of user, group, or resource referred to in GranteeId.
permission_granteeType :: Lens.Lens' Permission MemberType
permission_granteeType :: Lens' Permission MemberType
permission_granteeType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {MemberType
granteeType :: MemberType
$sel:granteeType:Permission' :: Permission -> MemberType
granteeType} -> MemberType
granteeType) (\s :: Permission
s@Permission' {} MemberType
a -> Permission
s {$sel:granteeType:Permission' :: MemberType
granteeType = MemberType
a} :: Permission)

-- | The permissions granted to the grantee. SEND_AS allows the grantee to
-- send email as the owner of the mailbox (the grantee is not mentioned on
-- these emails). SEND_ON_BEHALF allows the grantee to send email on behalf
-- of the owner of the mailbox (the grantee is not mentioned as the
-- physical sender of these emails). FULL_ACCESS allows the grantee full
-- access to the mailbox, irrespective of other folder-level permissions
-- set on the mailbox.
permission_permissionValues :: Lens.Lens' Permission [PermissionType]
permission_permissionValues :: Lens' Permission [PermissionType]
permission_permissionValues = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {[PermissionType]
permissionValues :: [PermissionType]
$sel:permissionValues:Permission' :: Permission -> [PermissionType]
permissionValues} -> [PermissionType]
permissionValues) (\s :: Permission
s@Permission' {} [PermissionType]
a -> Permission
s {$sel:permissionValues:Permission' :: [PermissionType]
permissionValues = [PermissionType]
a} :: Permission) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON Permission where
  parseJSON :: Value -> Parser Permission
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Permission"
      ( \Object
x ->
          Text -> MemberType -> [PermissionType] -> Permission
Permission'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"GranteeId")
            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
"GranteeType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PermissionValues"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable Permission where
  hashWithSalt :: Int -> Permission -> Int
hashWithSalt Int
_salt Permission' {[PermissionType]
Text
MemberType
permissionValues :: [PermissionType]
granteeType :: MemberType
granteeId :: Text
$sel:permissionValues:Permission' :: Permission -> [PermissionType]
$sel:granteeType:Permission' :: Permission -> MemberType
$sel:granteeId:Permission' :: Permission -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
granteeId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` MemberType
granteeType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [PermissionType]
permissionValues

instance Prelude.NFData Permission where
  rnf :: Permission -> ()
rnf Permission' {[PermissionType]
Text
MemberType
permissionValues :: [PermissionType]
granteeType :: MemberType
granteeId :: Text
$sel:permissionValues:Permission' :: Permission -> [PermissionType]
$sel:granteeType:Permission' :: Permission -> MemberType
$sel:granteeId:Permission' :: Permission -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
granteeId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf MemberType
granteeType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [PermissionType]
permissionValues