{-# 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.Delegate
-- 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.Delegate where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WorkMail.Types.MemberType

-- | The name of the attribute, which is one of the values defined in the
-- UserAttribute enumeration.
--
-- /See:/ 'newDelegate' smart constructor.
data Delegate = Delegate'
  { -- | The identifier for the user or group associated as the resource\'s
    -- delegate.
    Delegate -> Text
id :: Prelude.Text,
    -- | The type of the delegate: user or group.
    Delegate -> MemberType
type' :: MemberType
  }
  deriving (Delegate -> Delegate -> Bool
(Delegate -> Delegate -> Bool)
-> (Delegate -> Delegate -> Bool) -> Eq Delegate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Delegate -> Delegate -> Bool
$c/= :: Delegate -> Delegate -> Bool
== :: Delegate -> Delegate -> Bool
$c== :: Delegate -> Delegate -> Bool
Prelude.Eq, ReadPrec [Delegate]
ReadPrec Delegate
Int -> ReadS Delegate
ReadS [Delegate]
(Int -> ReadS Delegate)
-> ReadS [Delegate]
-> ReadPrec Delegate
-> ReadPrec [Delegate]
-> Read Delegate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Delegate]
$creadListPrec :: ReadPrec [Delegate]
readPrec :: ReadPrec Delegate
$creadPrec :: ReadPrec Delegate
readList :: ReadS [Delegate]
$creadList :: ReadS [Delegate]
readsPrec :: Int -> ReadS Delegate
$creadsPrec :: Int -> ReadS Delegate
Prelude.Read, Int -> Delegate -> ShowS
[Delegate] -> ShowS
Delegate -> String
(Int -> Delegate -> ShowS)
-> (Delegate -> String) -> ([Delegate] -> ShowS) -> Show Delegate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Delegate] -> ShowS
$cshowList :: [Delegate] -> ShowS
show :: Delegate -> String
$cshow :: Delegate -> String
showsPrec :: Int -> Delegate -> ShowS
$cshowsPrec :: Int -> Delegate -> ShowS
Prelude.Show, (forall x. Delegate -> Rep Delegate x)
-> (forall x. Rep Delegate x -> Delegate) -> Generic Delegate
forall x. Rep Delegate x -> Delegate
forall x. Delegate -> Rep Delegate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Delegate x -> Delegate
$cfrom :: forall x. Delegate -> Rep Delegate x
Prelude.Generic)

-- |
-- Create a value of 'Delegate' 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', 'delegate_id' - The identifier for the user or group associated as the resource\'s
-- delegate.
--
-- 'type'', 'delegate_type' - The type of the delegate: user or group.
newDelegate ::
  -- | 'id'
  Prelude.Text ->
  -- | 'type''
  MemberType ->
  Delegate
newDelegate :: Text -> MemberType -> Delegate
newDelegate Text
pId_ MemberType
pType_ =
  Delegate' :: Text -> MemberType -> Delegate
Delegate' {$sel:id:Delegate' :: Text
id = Text
pId_, $sel:type':Delegate' :: MemberType
type' = MemberType
pType_}

-- | The identifier for the user or group associated as the resource\'s
-- delegate.
delegate_id :: Lens.Lens' Delegate Prelude.Text
delegate_id :: (Text -> f Text) -> Delegate -> f Delegate
delegate_id = (Delegate -> Text)
-> (Delegate -> Text -> Delegate)
-> Lens Delegate Delegate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Delegate' {Text
id :: Text
$sel:id:Delegate' :: Delegate -> Text
id} -> Text
id) (\s :: Delegate
s@Delegate' {} Text
a -> Delegate
s {$sel:id:Delegate' :: Text
id = Text
a} :: Delegate)

-- | The type of the delegate: user or group.
delegate_type :: Lens.Lens' Delegate MemberType
delegate_type :: (MemberType -> f MemberType) -> Delegate -> f Delegate
delegate_type = (Delegate -> MemberType)
-> (Delegate -> MemberType -> Delegate)
-> Lens Delegate Delegate MemberType MemberType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Delegate' {MemberType
type' :: MemberType
$sel:type':Delegate' :: Delegate -> MemberType
type'} -> MemberType
type') (\s :: Delegate
s@Delegate' {} MemberType
a -> Delegate
s {$sel:type':Delegate' :: MemberType
type' = MemberType
a} :: Delegate)

instance Core.FromJSON Delegate where
  parseJSON :: Value -> Parser Delegate
parseJSON =
    String -> (Object -> Parser Delegate) -> Value -> Parser Delegate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Delegate"
      ( \Object
x ->
          Text -> MemberType -> Delegate
Delegate'
            (Text -> MemberType -> Delegate)
-> Parser Text -> Parser (MemberType -> Delegate)
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
"Id") Parser (MemberType -> Delegate)
-> Parser MemberType -> Parser Delegate
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
"Type")
      )

instance Prelude.Hashable Delegate

instance Prelude.NFData Delegate