{-# 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.S3.Types.Grantee
-- 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.S3.Types.Grantee where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.Type

-- | Container for the person being granted permissions.
--
-- /See:/ 'newGrantee' smart constructor.
data Grantee = Grantee'
  { -- | URI of the grantee group.
    Grantee -> Maybe Text
uri :: Prelude.Maybe Prelude.Text,
    -- | Email address of the grantee.
    --
    -- Using email addresses to specify a grantee is only supported in the
    -- following Amazon Web Services Regions:
    --
    -- -   US East (N. Virginia)
    --
    -- -   US West (N. California)
    --
    -- -   US West (Oregon)
    --
    -- -   Asia Pacific (Singapore)
    --
    -- -   Asia Pacific (Sydney)
    --
    -- -   Asia Pacific (Tokyo)
    --
    -- -   Europe (Ireland)
    --
    -- -   South America (São Paulo)
    --
    -- For a list of all the Amazon S3 supported Regions and endpoints, see
    -- <https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region Regions and Endpoints>
    -- in the Amazon Web Services General Reference.
    Grantee -> Maybe Text
emailAddress :: Prelude.Maybe Prelude.Text,
    -- | Screen name of the grantee.
    Grantee -> Maybe Text
displayName :: Prelude.Maybe Prelude.Text,
    -- | The canonical user ID of the grantee.
    Grantee -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | Type of grantee
    Grantee -> Type
type' :: Type
  }
  deriving (Grantee -> Grantee -> Bool
(Grantee -> Grantee -> Bool)
-> (Grantee -> Grantee -> Bool) -> Eq Grantee
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Grantee -> Grantee -> Bool
$c/= :: Grantee -> Grantee -> Bool
== :: Grantee -> Grantee -> Bool
$c== :: Grantee -> Grantee -> Bool
Prelude.Eq, ReadPrec [Grantee]
ReadPrec Grantee
Int -> ReadS Grantee
ReadS [Grantee]
(Int -> ReadS Grantee)
-> ReadS [Grantee]
-> ReadPrec Grantee
-> ReadPrec [Grantee]
-> Read Grantee
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Grantee]
$creadListPrec :: ReadPrec [Grantee]
readPrec :: ReadPrec Grantee
$creadPrec :: ReadPrec Grantee
readList :: ReadS [Grantee]
$creadList :: ReadS [Grantee]
readsPrec :: Int -> ReadS Grantee
$creadsPrec :: Int -> ReadS Grantee
Prelude.Read, Int -> Grantee -> ShowS
[Grantee] -> ShowS
Grantee -> String
(Int -> Grantee -> ShowS)
-> (Grantee -> String) -> ([Grantee] -> ShowS) -> Show Grantee
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Grantee] -> ShowS
$cshowList :: [Grantee] -> ShowS
show :: Grantee -> String
$cshow :: Grantee -> String
showsPrec :: Int -> Grantee -> ShowS
$cshowsPrec :: Int -> Grantee -> ShowS
Prelude.Show, (forall x. Grantee -> Rep Grantee x)
-> (forall x. Rep Grantee x -> Grantee) -> Generic Grantee
forall x. Rep Grantee x -> Grantee
forall x. Grantee -> Rep Grantee x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Grantee x -> Grantee
$cfrom :: forall x. Grantee -> Rep Grantee x
Prelude.Generic)

-- |
-- Create a value of 'Grantee' 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:
--
-- 'uri', 'grantee_uri' - URI of the grantee group.
--
-- 'emailAddress', 'grantee_emailAddress' - Email address of the grantee.
--
-- Using email addresses to specify a grantee is only supported in the
-- following Amazon Web Services Regions:
--
-- -   US East (N. Virginia)
--
-- -   US West (N. California)
--
-- -   US West (Oregon)
--
-- -   Asia Pacific (Singapore)
--
-- -   Asia Pacific (Sydney)
--
-- -   Asia Pacific (Tokyo)
--
-- -   Europe (Ireland)
--
-- -   South America (São Paulo)
--
-- For a list of all the Amazon S3 supported Regions and endpoints, see
-- <https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region Regions and Endpoints>
-- in the Amazon Web Services General Reference.
--
-- 'displayName', 'grantee_displayName' - Screen name of the grantee.
--
-- 'id', 'grantee_id' - The canonical user ID of the grantee.
--
-- 'type'', 'grantee_type' - Type of grantee
newGrantee ::
  -- | 'type''
  Type ->
  Grantee
newGrantee :: Type -> Grantee
newGrantee Type
pType_ =
  Grantee' :: Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Type -> Grantee
Grantee'
    { $sel:uri:Grantee' :: Maybe Text
uri = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:emailAddress:Grantee' :: Maybe Text
emailAddress = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:displayName:Grantee' :: Maybe Text
displayName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Grantee' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Grantee' :: Type
type' = Type
pType_
    }

-- | URI of the grantee group.
grantee_uri :: Lens.Lens' Grantee (Prelude.Maybe Prelude.Text)
grantee_uri :: (Maybe Text -> f (Maybe Text)) -> Grantee -> f Grantee
grantee_uri = (Grantee -> Maybe Text)
-> (Grantee -> Maybe Text -> Grantee)
-> Lens Grantee Grantee (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Grantee' {Maybe Text
uri :: Maybe Text
$sel:uri:Grantee' :: Grantee -> Maybe Text
uri} -> Maybe Text
uri) (\s :: Grantee
s@Grantee' {} Maybe Text
a -> Grantee
s {$sel:uri:Grantee' :: Maybe Text
uri = Maybe Text
a} :: Grantee)

-- | Email address of the grantee.
--
-- Using email addresses to specify a grantee is only supported in the
-- following Amazon Web Services Regions:
--
-- -   US East (N. Virginia)
--
-- -   US West (N. California)
--
-- -   US West (Oregon)
--
-- -   Asia Pacific (Singapore)
--
-- -   Asia Pacific (Sydney)
--
-- -   Asia Pacific (Tokyo)
--
-- -   Europe (Ireland)
--
-- -   South America (São Paulo)
--
-- For a list of all the Amazon S3 supported Regions and endpoints, see
-- <https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region Regions and Endpoints>
-- in the Amazon Web Services General Reference.
grantee_emailAddress :: Lens.Lens' Grantee (Prelude.Maybe Prelude.Text)
grantee_emailAddress :: (Maybe Text -> f (Maybe Text)) -> Grantee -> f Grantee
grantee_emailAddress = (Grantee -> Maybe Text)
-> (Grantee -> Maybe Text -> Grantee)
-> Lens Grantee Grantee (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Grantee' {Maybe Text
emailAddress :: Maybe Text
$sel:emailAddress:Grantee' :: Grantee -> Maybe Text
emailAddress} -> Maybe Text
emailAddress) (\s :: Grantee
s@Grantee' {} Maybe Text
a -> Grantee
s {$sel:emailAddress:Grantee' :: Maybe Text
emailAddress = Maybe Text
a} :: Grantee)

-- | Screen name of the grantee.
grantee_displayName :: Lens.Lens' Grantee (Prelude.Maybe Prelude.Text)
grantee_displayName :: (Maybe Text -> f (Maybe Text)) -> Grantee -> f Grantee
grantee_displayName = (Grantee -> Maybe Text)
-> (Grantee -> Maybe Text -> Grantee)
-> Lens Grantee Grantee (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Grantee' {Maybe Text
displayName :: Maybe Text
$sel:displayName:Grantee' :: Grantee -> Maybe Text
displayName} -> Maybe Text
displayName) (\s :: Grantee
s@Grantee' {} Maybe Text
a -> Grantee
s {$sel:displayName:Grantee' :: Maybe Text
displayName = Maybe Text
a} :: Grantee)

-- | The canonical user ID of the grantee.
grantee_id :: Lens.Lens' Grantee (Prelude.Maybe Prelude.Text)
grantee_id :: (Maybe Text -> f (Maybe Text)) -> Grantee -> f Grantee
grantee_id = (Grantee -> Maybe Text)
-> (Grantee -> Maybe Text -> Grantee)
-> Lens Grantee Grantee (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Grantee' {Maybe Text
id :: Maybe Text
$sel:id:Grantee' :: Grantee -> Maybe Text
id} -> Maybe Text
id) (\s :: Grantee
s@Grantee' {} Maybe Text
a -> Grantee
s {$sel:id:Grantee' :: Maybe Text
id = Maybe Text
a} :: Grantee)

-- | Type of grantee
grantee_type :: Lens.Lens' Grantee Type
grantee_type :: (Type -> f Type) -> Grantee -> f Grantee
grantee_type = (Grantee -> Type)
-> (Grantee -> Type -> Grantee) -> Lens Grantee Grantee Type Type
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Grantee' {Type
type' :: Type
$sel:type':Grantee' :: Grantee -> Type
type'} -> Type
type') (\s :: Grantee
s@Grantee' {} Type
a -> Grantee
s {$sel:type':Grantee' :: Type
type' = Type
a} :: Grantee)

instance Core.FromXML Grantee where
  parseXML :: [Node] -> Either String Grantee
parseXML [Node]
x =
    Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Type -> Grantee
Grantee'
      (Maybe Text
 -> Maybe Text -> Maybe Text -> Maybe Text -> Type -> Grantee)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Maybe Text -> Maybe Text -> Type -> Grantee)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"URI")
      Either
  String (Maybe Text -> Maybe Text -> Maybe Text -> Type -> Grantee)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Maybe Text -> Type -> Grantee)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"EmailAddress")
      Either String (Maybe Text -> Maybe Text -> Type -> Grantee)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Type -> Grantee)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"DisplayName")
      Either String (Maybe Text -> Type -> Grantee)
-> Either String (Maybe Text) -> Either String (Type -> Grantee)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ID")
      Either String (Type -> Grantee)
-> Either String Type -> Either String Grantee
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Type
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"xsi:type")

instance Prelude.Hashable Grantee

instance Prelude.NFData Grantee

instance Core.ToXML Grantee where
  toXML :: Grantee -> XML
toXML Grantee' {Maybe Text
Type
type' :: Type
id :: Maybe Text
displayName :: Maybe Text
emailAddress :: Maybe Text
uri :: Maybe Text
$sel:type':Grantee' :: Grantee -> Type
$sel:id:Grantee' :: Grantee -> Maybe Text
$sel:displayName:Grantee' :: Grantee -> Maybe Text
$sel:emailAddress:Grantee' :: Grantee -> Maybe Text
$sel:uri:Grantee' :: Grantee -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"URI" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
uri,
        Name
"EmailAddress" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
emailAddress,
        Name
"DisplayName" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
displayName,
        Name
"ID" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
id,
        Name
"xsi:type" Name -> Type -> XML
forall a. ToText a => Name -> a -> XML
Core.@@= Type
type'
      ]