{-# 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.Inspector2.Types.Permission
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Inspector2.Types.Permission where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Inspector2.Types.Operation
import Amazonka.Inspector2.Types.Service
import qualified Amazonka.Prelude as Prelude

-- | Contains information on the permissions an account has within Amazon
-- Inspector.
--
-- /See:/ 'newPermission' smart constructor.
data Permission = Permission'
  { -- | The operations that can be performed with the given permissions.
    Permission -> Operation
operation :: Operation,
    -- | The services that the permissions allow an account to perform the given
    -- operations for.
    Permission -> Service
service :: Service
  }
  deriving (Permission -> Permission -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Permission -> Permission -> Bool
$c/= :: Permission -> Permission -> Bool
== :: Permission -> Permission -> Bool
$c== :: Permission -> Permission -> Bool
Prelude.Eq, ReadPrec [Permission]
ReadPrec Permission
Int -> ReadS Permission
ReadS [Permission]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Permission]
$creadListPrec :: ReadPrec [Permission]
readPrec :: ReadPrec Permission
$creadPrec :: ReadPrec Permission
readList :: ReadS [Permission]
$creadList :: ReadS [Permission]
readsPrec :: Int -> ReadS Permission
$creadsPrec :: Int -> ReadS Permission
Prelude.Read, Int -> Permission -> ShowS
[Permission] -> ShowS
Permission -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Permission] -> ShowS
$cshowList :: [Permission] -> ShowS
show :: Permission -> String
$cshow :: Permission -> String
showsPrec :: Int -> Permission -> ShowS
$cshowsPrec :: Int -> Permission -> ShowS
Prelude.Show, forall x. Rep Permission x -> Permission
forall x. Permission -> Rep Permission x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Permission x -> Permission
$cfrom :: forall x. Permission -> Rep Permission x
Prelude.Generic)

-- |
-- Create a value of 'Permission' 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:
--
-- 'operation', 'permission_operation' - The operations that can be performed with the given permissions.
--
-- 'service', 'permission_service' - The services that the permissions allow an account to perform the given
-- operations for.
newPermission ::
  -- | 'operation'
  Operation ->
  -- | 'service'
  Service ->
  Permission
newPermission :: Operation -> Service -> Permission
newPermission Operation
pOperation_ Service
pService_ =
  Permission'
    { $sel:operation:Permission' :: Operation
operation = Operation
pOperation_,
      $sel:service:Permission' :: Service
service = Service
pService_
    }

-- | The operations that can be performed with the given permissions.
permission_operation :: Lens.Lens' Permission Operation
permission_operation :: Lens' Permission Operation
permission_operation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Operation
operation :: Operation
$sel:operation:Permission' :: Permission -> Operation
operation} -> Operation
operation) (\s :: Permission
s@Permission' {} Operation
a -> Permission
s {$sel:operation:Permission' :: Operation
operation = Operation
a} :: Permission)

-- | The services that the permissions allow an account to perform the given
-- operations for.
permission_service :: Lens.Lens' Permission Service
permission_service :: Lens' Permission Service
permission_service = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Permission' {Service
service :: Service
$sel:service:Permission' :: Permission -> Service
service} -> Service
service) (\s :: Permission
s@Permission' {} Service
a -> Permission
s {$sel:service:Permission' :: Service
service = Service
a} :: Permission)

instance Data.FromJSON Permission where
  parseJSON :: Value -> Parser Permission
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Permission"
      ( \Object
x ->
          Operation -> Service -> Permission
Permission'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"operation")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"service")
      )

instance Prelude.Hashable Permission where
  hashWithSalt :: Int -> Permission -> Int
hashWithSalt Int
_salt Permission' {Operation
Service
service :: Service
operation :: Operation
$sel:service:Permission' :: Permission -> Service
$sel:operation:Permission' :: Permission -> Operation
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Operation
operation
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Service
service

instance Prelude.NFData Permission where
  rnf :: Permission -> ()
rnf Permission' {Operation
Service
service :: Service
operation :: Operation
$sel:service:Permission' :: Permission -> Service
$sel:operation:Permission' :: Permission -> Operation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Operation
operation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Service
service