{-# 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.Grafana.Types.PermissionEntry
-- 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.Grafana.Types.PermissionEntry where

import qualified Amazonka.Core as Core
import Amazonka.Grafana.Types.Role
import Amazonka.Grafana.Types.User
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A structure containing the identity of one user or group and the @Admin@
-- or @Editor@ role that they have.
--
-- /See:/ 'newPermissionEntry' smart constructor.
data PermissionEntry = PermissionEntry'
  { -- | Specifies whether the user or group has the @Admin@ or @Editor@ role.
    PermissionEntry -> Role
role' :: Role,
    -- | A structure with the ID of the user or group with this role.
    PermissionEntry -> User
user :: User
  }
  deriving (PermissionEntry -> PermissionEntry -> Bool
(PermissionEntry -> PermissionEntry -> Bool)
-> (PermissionEntry -> PermissionEntry -> Bool)
-> Eq PermissionEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PermissionEntry -> PermissionEntry -> Bool
$c/= :: PermissionEntry -> PermissionEntry -> Bool
== :: PermissionEntry -> PermissionEntry -> Bool
$c== :: PermissionEntry -> PermissionEntry -> Bool
Prelude.Eq, ReadPrec [PermissionEntry]
ReadPrec PermissionEntry
Int -> ReadS PermissionEntry
ReadS [PermissionEntry]
(Int -> ReadS PermissionEntry)
-> ReadS [PermissionEntry]
-> ReadPrec PermissionEntry
-> ReadPrec [PermissionEntry]
-> Read PermissionEntry
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PermissionEntry]
$creadListPrec :: ReadPrec [PermissionEntry]
readPrec :: ReadPrec PermissionEntry
$creadPrec :: ReadPrec PermissionEntry
readList :: ReadS [PermissionEntry]
$creadList :: ReadS [PermissionEntry]
readsPrec :: Int -> ReadS PermissionEntry
$creadsPrec :: Int -> ReadS PermissionEntry
Prelude.Read, Int -> PermissionEntry -> ShowS
[PermissionEntry] -> ShowS
PermissionEntry -> String
(Int -> PermissionEntry -> ShowS)
-> (PermissionEntry -> String)
-> ([PermissionEntry] -> ShowS)
-> Show PermissionEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PermissionEntry] -> ShowS
$cshowList :: [PermissionEntry] -> ShowS
show :: PermissionEntry -> String
$cshow :: PermissionEntry -> String
showsPrec :: Int -> PermissionEntry -> ShowS
$cshowsPrec :: Int -> PermissionEntry -> ShowS
Prelude.Show, (forall x. PermissionEntry -> Rep PermissionEntry x)
-> (forall x. Rep PermissionEntry x -> PermissionEntry)
-> Generic PermissionEntry
forall x. Rep PermissionEntry x -> PermissionEntry
forall x. PermissionEntry -> Rep PermissionEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PermissionEntry x -> PermissionEntry
$cfrom :: forall x. PermissionEntry -> Rep PermissionEntry x
Prelude.Generic)

-- |
-- Create a value of 'PermissionEntry' 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:
--
-- 'role'', 'permissionEntry_role' - Specifies whether the user or group has the @Admin@ or @Editor@ role.
--
-- 'user', 'permissionEntry_user' - A structure with the ID of the user or group with this role.
newPermissionEntry ::
  -- | 'role''
  Role ->
  -- | 'user'
  User ->
  PermissionEntry
newPermissionEntry :: Role -> User -> PermissionEntry
newPermissionEntry Role
pRole_ User
pUser_ =
  PermissionEntry' :: Role -> User -> PermissionEntry
PermissionEntry' {$sel:role':PermissionEntry' :: Role
role' = Role
pRole_, $sel:user:PermissionEntry' :: User
user = User
pUser_}

-- | Specifies whether the user or group has the @Admin@ or @Editor@ role.
permissionEntry_role :: Lens.Lens' PermissionEntry Role
permissionEntry_role :: (Role -> f Role) -> PermissionEntry -> f PermissionEntry
permissionEntry_role = (PermissionEntry -> Role)
-> (PermissionEntry -> Role -> PermissionEntry)
-> Lens PermissionEntry PermissionEntry Role Role
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PermissionEntry' {Role
role' :: Role
$sel:role':PermissionEntry' :: PermissionEntry -> Role
role'} -> Role
role') (\s :: PermissionEntry
s@PermissionEntry' {} Role
a -> PermissionEntry
s {$sel:role':PermissionEntry' :: Role
role' = Role
a} :: PermissionEntry)

-- | A structure with the ID of the user or group with this role.
permissionEntry_user :: Lens.Lens' PermissionEntry User
permissionEntry_user :: (User -> f User) -> PermissionEntry -> f PermissionEntry
permissionEntry_user = (PermissionEntry -> User)
-> (PermissionEntry -> User -> PermissionEntry)
-> Lens PermissionEntry PermissionEntry User User
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PermissionEntry' {User
user :: User
$sel:user:PermissionEntry' :: PermissionEntry -> User
user} -> User
user) (\s :: PermissionEntry
s@PermissionEntry' {} User
a -> PermissionEntry
s {$sel:user:PermissionEntry' :: User
user = User
a} :: PermissionEntry)

instance Core.FromJSON PermissionEntry where
  parseJSON :: Value -> Parser PermissionEntry
parseJSON =
    String
-> (Object -> Parser PermissionEntry)
-> Value
-> Parser PermissionEntry
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PermissionEntry"
      ( \Object
x ->
          Role -> User -> PermissionEntry
PermissionEntry'
            (Role -> User -> PermissionEntry)
-> Parser Role -> Parser (User -> PermissionEntry)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Role
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"role") Parser (User -> PermissionEntry)
-> Parser User -> Parser PermissionEntry
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser User
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"user")
      )

instance Prelude.Hashable PermissionEntry

instance Prelude.NFData PermissionEntry