{-# 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.Grant
-- 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.Grant 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.Grantee
import Amazonka.S3.Types.Permission

-- | Container for grant information.
--
-- /See:/ 'newGrant' smart constructor.
data Grant = Grant'
  { -- | Specifies the permission given to the grantee.
    Grant -> Maybe Permission
permission :: Prelude.Maybe Permission,
    -- | The person being granted permissions.
    Grant -> Maybe Grantee
grantee :: Prelude.Maybe Grantee
  }
  deriving (Grant -> Grant -> Bool
(Grant -> Grant -> Bool) -> (Grant -> Grant -> Bool) -> Eq Grant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Grant -> Grant -> Bool
$c/= :: Grant -> Grant -> Bool
== :: Grant -> Grant -> Bool
$c== :: Grant -> Grant -> Bool
Prelude.Eq, ReadPrec [Grant]
ReadPrec Grant
Int -> ReadS Grant
ReadS [Grant]
(Int -> ReadS Grant)
-> ReadS [Grant]
-> ReadPrec Grant
-> ReadPrec [Grant]
-> Read Grant
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Grant]
$creadListPrec :: ReadPrec [Grant]
readPrec :: ReadPrec Grant
$creadPrec :: ReadPrec Grant
readList :: ReadS [Grant]
$creadList :: ReadS [Grant]
readsPrec :: Int -> ReadS Grant
$creadsPrec :: Int -> ReadS Grant
Prelude.Read, Int -> Grant -> ShowS
[Grant] -> ShowS
Grant -> String
(Int -> Grant -> ShowS)
-> (Grant -> String) -> ([Grant] -> ShowS) -> Show Grant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Grant] -> ShowS
$cshowList :: [Grant] -> ShowS
show :: Grant -> String
$cshow :: Grant -> String
showsPrec :: Int -> Grant -> ShowS
$cshowsPrec :: Int -> Grant -> ShowS
Prelude.Show, (forall x. Grant -> Rep Grant x)
-> (forall x. Rep Grant x -> Grant) -> Generic Grant
forall x. Rep Grant x -> Grant
forall x. Grant -> Rep Grant x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Grant x -> Grant
$cfrom :: forall x. Grant -> Rep Grant x
Prelude.Generic)

-- |
-- Create a value of 'Grant' 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:
--
-- 'permission', 'grant_permission' - Specifies the permission given to the grantee.
--
-- 'grantee', 'grant_grantee' - The person being granted permissions.
newGrant ::
  Grant
newGrant :: Grant
newGrant =
  Grant' :: Maybe Permission -> Maybe Grantee -> Grant
Grant'
    { $sel:permission:Grant' :: Maybe Permission
permission = Maybe Permission
forall a. Maybe a
Prelude.Nothing,
      $sel:grantee:Grant' :: Maybe Grantee
grantee = Maybe Grantee
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the permission given to the grantee.
grant_permission :: Lens.Lens' Grant (Prelude.Maybe Permission)
grant_permission :: (Maybe Permission -> f (Maybe Permission)) -> Grant -> f Grant
grant_permission = (Grant -> Maybe Permission)
-> (Grant -> Maybe Permission -> Grant)
-> Lens Grant Grant (Maybe Permission) (Maybe Permission)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Grant' {Maybe Permission
permission :: Maybe Permission
$sel:permission:Grant' :: Grant -> Maybe Permission
permission} -> Maybe Permission
permission) (\s :: Grant
s@Grant' {} Maybe Permission
a -> Grant
s {$sel:permission:Grant' :: Maybe Permission
permission = Maybe Permission
a} :: Grant)

-- | The person being granted permissions.
grant_grantee :: Lens.Lens' Grant (Prelude.Maybe Grantee)
grant_grantee :: (Maybe Grantee -> f (Maybe Grantee)) -> Grant -> f Grant
grant_grantee = (Grant -> Maybe Grantee)
-> (Grant -> Maybe Grantee -> Grant)
-> Lens Grant Grant (Maybe Grantee) (Maybe Grantee)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Grant' {Maybe Grantee
grantee :: Maybe Grantee
$sel:grantee:Grant' :: Grant -> Maybe Grantee
grantee} -> Maybe Grantee
grantee) (\s :: Grant
s@Grant' {} Maybe Grantee
a -> Grant
s {$sel:grantee:Grant' :: Maybe Grantee
grantee = Maybe Grantee
a} :: Grant)

instance Core.FromXML Grant where
  parseXML :: [Node] -> Either String Grant
parseXML [Node]
x =
    Maybe Permission -> Maybe Grantee -> Grant
Grant'
      (Maybe Permission -> Maybe Grantee -> Grant)
-> Either String (Maybe Permission)
-> Either String (Maybe Grantee -> Grant)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Permission)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Permission")
      Either String (Maybe Grantee -> Grant)
-> Either String (Maybe Grantee) -> Either String Grant
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Grantee)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Grantee")

instance Prelude.Hashable Grant

instance Prelude.NFData Grant

instance Core.ToXML Grant where
  toXML :: Grant -> XML
toXML Grant' {Maybe Permission
Maybe Grantee
grantee :: Maybe Grantee
permission :: Maybe Permission
$sel:grantee:Grant' :: Grant -> Maybe Grantee
$sel:permission:Grant' :: Grant -> Maybe Permission
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Permission" Name -> Maybe Permission -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Permission
permission,
        Name
"Grantee" Name -> Maybe Grantee -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Grantee
grantee
      ]