{-# 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-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.WorkMail.Types.Permission where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Permission -> Permission -> Bool)
-> (Permission -> Permission -> Bool) -> Eq Permission
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]
(Int -> ReadS Permission)
-> ReadS [Permission]
-> ReadPrec Permission
-> ReadPrec [Permission]
-> Read 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
(Int -> Permission -> ShowS)
-> (Permission -> String)
-> ([Permission] -> ShowS)
-> Show Permission
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. Permission -> Rep Permission x)
-> (forall x. Rep Permission x -> Permission) -> Generic Permission
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' :: Text -> MemberType -> [PermissionType] -> Permission
Permission'
    { $sel:granteeId:Permission' :: Text
granteeId = Text
pGranteeId_,
      $sel:granteeType:Permission' :: MemberType
granteeType = MemberType
pGranteeType_,
      $sel:permissionValues:Permission' :: [PermissionType]
permissionValues = [PermissionType]
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 :: (Text -> f Text) -> Permission -> f Permission
permission_granteeId = (Permission -> Text)
-> (Permission -> Text -> Permission)
-> Lens Permission Permission Text Text
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 :: (MemberType -> f MemberType) -> Permission -> f Permission
permission_granteeType = (Permission -> MemberType)
-> (Permission -> MemberType -> Permission)
-> Lens Permission Permission MemberType MemberType
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 :: ([PermissionType] -> f [PermissionType])
-> Permission -> f Permission
permission_permissionValues = (Permission -> [PermissionType])
-> (Permission -> [PermissionType] -> Permission)
-> Lens Permission Permission [PermissionType] [PermissionType]
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) (([PermissionType] -> f [PermissionType])
 -> Permission -> f Permission)
-> (([PermissionType] -> f [PermissionType])
    -> [PermissionType] -> f [PermissionType])
-> ([PermissionType] -> f [PermissionType])
-> Permission
-> f Permission
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([PermissionType] -> f [PermissionType])
-> [PermissionType] -> f [PermissionType]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Permission

instance Prelude.NFData Permission