{-# 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.LakeFormation.Types.PrincipalPermissions
-- 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.LakeFormation.Types.PrincipalPermissions where

import qualified Amazonka.Core as Core
import Amazonka.LakeFormation.Types.DataLakePrincipal
import Amazonka.LakeFormation.Types.Permission
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Permissions granted to a principal.
--
-- /See:/ 'newPrincipalPermissions' smart constructor.
data PrincipalPermissions = PrincipalPermissions'
  { -- | The principal who is granted permissions.
    PrincipalPermissions -> Maybe DataLakePrincipal
principal :: Prelude.Maybe DataLakePrincipal,
    -- | The permissions that are granted to the principal.
    PrincipalPermissions -> Maybe [Permission]
permissions :: Prelude.Maybe [Permission]
  }
  deriving (PrincipalPermissions -> PrincipalPermissions -> Bool
(PrincipalPermissions -> PrincipalPermissions -> Bool)
-> (PrincipalPermissions -> PrincipalPermissions -> Bool)
-> Eq PrincipalPermissions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrincipalPermissions -> PrincipalPermissions -> Bool
$c/= :: PrincipalPermissions -> PrincipalPermissions -> Bool
== :: PrincipalPermissions -> PrincipalPermissions -> Bool
$c== :: PrincipalPermissions -> PrincipalPermissions -> Bool
Prelude.Eq, ReadPrec [PrincipalPermissions]
ReadPrec PrincipalPermissions
Int -> ReadS PrincipalPermissions
ReadS [PrincipalPermissions]
(Int -> ReadS PrincipalPermissions)
-> ReadS [PrincipalPermissions]
-> ReadPrec PrincipalPermissions
-> ReadPrec [PrincipalPermissions]
-> Read PrincipalPermissions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PrincipalPermissions]
$creadListPrec :: ReadPrec [PrincipalPermissions]
readPrec :: ReadPrec PrincipalPermissions
$creadPrec :: ReadPrec PrincipalPermissions
readList :: ReadS [PrincipalPermissions]
$creadList :: ReadS [PrincipalPermissions]
readsPrec :: Int -> ReadS PrincipalPermissions
$creadsPrec :: Int -> ReadS PrincipalPermissions
Prelude.Read, Int -> PrincipalPermissions -> ShowS
[PrincipalPermissions] -> ShowS
PrincipalPermissions -> String
(Int -> PrincipalPermissions -> ShowS)
-> (PrincipalPermissions -> String)
-> ([PrincipalPermissions] -> ShowS)
-> Show PrincipalPermissions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrincipalPermissions] -> ShowS
$cshowList :: [PrincipalPermissions] -> ShowS
show :: PrincipalPermissions -> String
$cshow :: PrincipalPermissions -> String
showsPrec :: Int -> PrincipalPermissions -> ShowS
$cshowsPrec :: Int -> PrincipalPermissions -> ShowS
Prelude.Show, (forall x. PrincipalPermissions -> Rep PrincipalPermissions x)
-> (forall x. Rep PrincipalPermissions x -> PrincipalPermissions)
-> Generic PrincipalPermissions
forall x. Rep PrincipalPermissions x -> PrincipalPermissions
forall x. PrincipalPermissions -> Rep PrincipalPermissions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PrincipalPermissions x -> PrincipalPermissions
$cfrom :: forall x. PrincipalPermissions -> Rep PrincipalPermissions x
Prelude.Generic)

-- |
-- Create a value of 'PrincipalPermissions' 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:
--
-- 'principal', 'principalPermissions_principal' - The principal who is granted permissions.
--
-- 'permissions', 'principalPermissions_permissions' - The permissions that are granted to the principal.
newPrincipalPermissions ::
  PrincipalPermissions
newPrincipalPermissions :: PrincipalPermissions
newPrincipalPermissions =
  PrincipalPermissions' :: Maybe DataLakePrincipal
-> Maybe [Permission] -> PrincipalPermissions
PrincipalPermissions'
    { $sel:principal:PrincipalPermissions' :: Maybe DataLakePrincipal
principal = Maybe DataLakePrincipal
forall a. Maybe a
Prelude.Nothing,
      $sel:permissions:PrincipalPermissions' :: Maybe [Permission]
permissions = Maybe [Permission]
forall a. Maybe a
Prelude.Nothing
    }

-- | The principal who is granted permissions.
principalPermissions_principal :: Lens.Lens' PrincipalPermissions (Prelude.Maybe DataLakePrincipal)
principalPermissions_principal :: (Maybe DataLakePrincipal -> f (Maybe DataLakePrincipal))
-> PrincipalPermissions -> f PrincipalPermissions
principalPermissions_principal = (PrincipalPermissions -> Maybe DataLakePrincipal)
-> (PrincipalPermissions
    -> Maybe DataLakePrincipal -> PrincipalPermissions)
-> Lens
     PrincipalPermissions
     PrincipalPermissions
     (Maybe DataLakePrincipal)
     (Maybe DataLakePrincipal)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrincipalPermissions' {Maybe DataLakePrincipal
principal :: Maybe DataLakePrincipal
$sel:principal:PrincipalPermissions' :: PrincipalPermissions -> Maybe DataLakePrincipal
principal} -> Maybe DataLakePrincipal
principal) (\s :: PrincipalPermissions
s@PrincipalPermissions' {} Maybe DataLakePrincipal
a -> PrincipalPermissions
s {$sel:principal:PrincipalPermissions' :: Maybe DataLakePrincipal
principal = Maybe DataLakePrincipal
a} :: PrincipalPermissions)

-- | The permissions that are granted to the principal.
principalPermissions_permissions :: Lens.Lens' PrincipalPermissions (Prelude.Maybe [Permission])
principalPermissions_permissions :: (Maybe [Permission] -> f (Maybe [Permission]))
-> PrincipalPermissions -> f PrincipalPermissions
principalPermissions_permissions = (PrincipalPermissions -> Maybe [Permission])
-> (PrincipalPermissions
    -> Maybe [Permission] -> PrincipalPermissions)
-> Lens
     PrincipalPermissions
     PrincipalPermissions
     (Maybe [Permission])
     (Maybe [Permission])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrincipalPermissions' {Maybe [Permission]
permissions :: Maybe [Permission]
$sel:permissions:PrincipalPermissions' :: PrincipalPermissions -> Maybe [Permission]
permissions} -> Maybe [Permission]
permissions) (\s :: PrincipalPermissions
s@PrincipalPermissions' {} Maybe [Permission]
a -> PrincipalPermissions
s {$sel:permissions:PrincipalPermissions' :: Maybe [Permission]
permissions = Maybe [Permission]
a} :: PrincipalPermissions) ((Maybe [Permission] -> f (Maybe [Permission]))
 -> PrincipalPermissions -> f PrincipalPermissions)
-> ((Maybe [Permission] -> f (Maybe [Permission]))
    -> Maybe [Permission] -> f (Maybe [Permission]))
-> (Maybe [Permission] -> f (Maybe [Permission]))
-> PrincipalPermissions
-> f PrincipalPermissions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Permission] [Permission] [Permission] [Permission]
-> Iso
     (Maybe [Permission])
     (Maybe [Permission])
     (Maybe [Permission])
     (Maybe [Permission])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Permission] [Permission] [Permission] [Permission]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable PrincipalPermissions

instance Prelude.NFData PrincipalPermissions

instance Core.ToJSON PrincipalPermissions where
  toJSON :: PrincipalPermissions -> Value
toJSON PrincipalPermissions' {Maybe [Permission]
Maybe DataLakePrincipal
permissions :: Maybe [Permission]
principal :: Maybe DataLakePrincipal
$sel:permissions:PrincipalPermissions' :: PrincipalPermissions -> Maybe [Permission]
$sel:principal:PrincipalPermissions' :: PrincipalPermissions -> Maybe DataLakePrincipal
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Principal" Text -> DataLakePrincipal -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (DataLakePrincipal -> Pair)
-> Maybe DataLakePrincipal -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DataLakePrincipal
principal,
            (Text
"Permissions" 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]
permissions
          ]
      )