{-# 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.AuditManager.Types.Role
-- 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.AuditManager.Types.Role where

import Amazonka.AuditManager.Types.RoleType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The wrapper that contains the Audit Manager role information of the
-- current user, such as the role type and IAM Amazon Resource Name (ARN).
--
-- /See:/ 'newRole' smart constructor.
data Role = Role'
  { -- | The type of customer persona.
    --
    -- In @CreateAssessment@, @roleType@ can only be @PROCESS_OWNER@.
    --
    -- In @UpdateSettings@, @roleType@ can only be @PROCESS_OWNER@.
    --
    -- In @BatchCreateDelegationByAssessment@, @roleType@ can only be
    -- @RESOURCE_OWNER@.
    Role -> Maybe RoleType
roleType :: Prelude.Maybe RoleType,
    -- | The Amazon Resource Name (ARN) of the IAM role.
    Role -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text
  }
  deriving (Role -> Role -> Bool
(Role -> Role -> Bool) -> (Role -> Role -> Bool) -> Eq Role
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Role -> Role -> Bool
$c/= :: Role -> Role -> Bool
== :: Role -> Role -> Bool
$c== :: Role -> Role -> Bool
Prelude.Eq, ReadPrec [Role]
ReadPrec Role
Int -> ReadS Role
ReadS [Role]
(Int -> ReadS Role)
-> ReadS [Role] -> ReadPrec Role -> ReadPrec [Role] -> Read Role
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Role]
$creadListPrec :: ReadPrec [Role]
readPrec :: ReadPrec Role
$creadPrec :: ReadPrec Role
readList :: ReadS [Role]
$creadList :: ReadS [Role]
readsPrec :: Int -> ReadS Role
$creadsPrec :: Int -> ReadS Role
Prelude.Read, Int -> Role -> ShowS
[Role] -> ShowS
Role -> String
(Int -> Role -> ShowS)
-> (Role -> String) -> ([Role] -> ShowS) -> Show Role
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Role] -> ShowS
$cshowList :: [Role] -> ShowS
show :: Role -> String
$cshow :: Role -> String
showsPrec :: Int -> Role -> ShowS
$cshowsPrec :: Int -> Role -> ShowS
Prelude.Show, (forall x. Role -> Rep Role x)
-> (forall x. Rep Role x -> Role) -> Generic Role
forall x. Rep Role x -> Role
forall x. Role -> Rep Role x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Role x -> Role
$cfrom :: forall x. Role -> Rep Role x
Prelude.Generic)

-- |
-- Create a value of 'Role' 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:
--
-- 'roleType', 'role_roleType' - The type of customer persona.
--
-- In @CreateAssessment@, @roleType@ can only be @PROCESS_OWNER@.
--
-- In @UpdateSettings@, @roleType@ can only be @PROCESS_OWNER@.
--
-- In @BatchCreateDelegationByAssessment@, @roleType@ can only be
-- @RESOURCE_OWNER@.
--
-- 'roleArn', 'role_roleArn' - The Amazon Resource Name (ARN) of the IAM role.
newRole ::
  Role
newRole :: Role
newRole =
  Role' :: Maybe RoleType -> Maybe Text -> Role
Role'
    { $sel:roleType:Role' :: Maybe RoleType
roleType = Maybe RoleType
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:Role' :: Maybe Text
roleArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The type of customer persona.
--
-- In @CreateAssessment@, @roleType@ can only be @PROCESS_OWNER@.
--
-- In @UpdateSettings@, @roleType@ can only be @PROCESS_OWNER@.
--
-- In @BatchCreateDelegationByAssessment@, @roleType@ can only be
-- @RESOURCE_OWNER@.
role_roleType :: Lens.Lens' Role (Prelude.Maybe RoleType)
role_roleType :: (Maybe RoleType -> f (Maybe RoleType)) -> Role -> f Role
role_roleType = (Role -> Maybe RoleType)
-> (Role -> Maybe RoleType -> Role)
-> Lens Role Role (Maybe RoleType) (Maybe RoleType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Role' {Maybe RoleType
roleType :: Maybe RoleType
$sel:roleType:Role' :: Role -> Maybe RoleType
roleType} -> Maybe RoleType
roleType) (\s :: Role
s@Role' {} Maybe RoleType
a -> Role
s {$sel:roleType:Role' :: Maybe RoleType
roleType = Maybe RoleType
a} :: Role)

-- | The Amazon Resource Name (ARN) of the IAM role.
role_roleArn :: Lens.Lens' Role (Prelude.Maybe Prelude.Text)
role_roleArn :: (Maybe Text -> f (Maybe Text)) -> Role -> f Role
role_roleArn = (Role -> Maybe Text)
-> (Role -> Maybe Text -> Role)
-> Lens Role Role (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Role' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:Role' :: Role -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: Role
s@Role' {} Maybe Text
a -> Role
s {$sel:roleArn:Role' :: Maybe Text
roleArn = Maybe Text
a} :: Role)

instance Core.FromJSON Role where
  parseJSON :: Value -> Parser Role
parseJSON =
    String -> (Object -> Parser Role) -> Value -> Parser Role
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Role"
      ( \Object
x ->
          Maybe RoleType -> Maybe Text -> Role
Role'
            (Maybe RoleType -> Maybe Text -> Role)
-> Parser (Maybe RoleType) -> Parser (Maybe Text -> Role)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe RoleType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"roleType")
            Parser (Maybe Text -> Role) -> Parser (Maybe Text) -> Parser Role
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"roleArn")
      )

instance Prelude.Hashable Role

instance Prelude.NFData Role

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