{-# 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.Glacier.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.Glacier.Types.Grant where

import qualified Amazonka.Core as Core
import Amazonka.Glacier.Types.Grantee
import Amazonka.Glacier.Types.Permission
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about a grant.
--
-- /See:/ 'newGrant' smart constructor.
data Grant = Grant'
  { -- | Specifies the permission given to the grantee.
    Grant -> Maybe Permission
permission :: Prelude.Maybe Permission,
    -- | The grantee.
    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 grantee.
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 grantee.
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.FromJSON Grant where
  parseJSON :: Value -> Parser Grant
parseJSON =
    String -> (Object -> Parser Grant) -> Value -> Parser Grant
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Grant"
      ( \Object
x ->
          Maybe Permission -> Maybe Grantee -> Grant
Grant'
            (Maybe Permission -> Maybe Grantee -> Grant)
-> Parser (Maybe Permission) -> Parser (Maybe Grantee -> Grant)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Permission)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Permission")
            Parser (Maybe Grantee -> Grant)
-> Parser (Maybe Grantee) -> Parser Grant
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Grantee)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Grantee")
      )

instance Prelude.Hashable Grant

instance Prelude.NFData Grant

instance Core.ToJSON Grant where
  toJSON :: Grant -> Value
toJSON Grant' {Maybe Permission
Maybe Grantee
grantee :: Maybe Grantee
permission :: Maybe Permission
$sel:grantee:Grant' :: Grant -> Maybe Grantee
$sel:permission:Grant' :: Grant -> Maybe Permission
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Permission" Text -> Permission -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Permission -> Pair) -> Maybe Permission -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Permission
permission,
            (Text
"Grantee" Text -> Grantee -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Grantee -> Pair) -> Maybe Grantee -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Grantee
grantee
          ]
      )