{-# 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.ServiceCatalog.Types.Principal
-- 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.ServiceCatalog.Types.Principal where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.ServiceCatalog.Types.PrincipalType

-- | Information about a principal.
--
-- /See:/ 'newPrincipal' smart constructor.
data Principal = Principal'
  { -- | The ARN of the principal (IAM user, role, or group). This field allows
    -- for an ARN with no @accountID@ if the @PrincipalType@ is an
    -- @IAM_PATTERN@.
    Principal -> Maybe Text
principalARN :: Prelude.Maybe Prelude.Text,
    -- | The principal type. The supported value is @IAM@ if you use a fully
    -- defined ARN, or @IAM_PATTERN@ if you use an ARN with no @accountID@.
    Principal -> Maybe PrincipalType
principalType :: Prelude.Maybe PrincipalType
  }
  deriving (Principal -> Principal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Principal -> Principal -> Bool
$c/= :: Principal -> Principal -> Bool
== :: Principal -> Principal -> Bool
$c== :: Principal -> Principal -> Bool
Prelude.Eq, ReadPrec [Principal]
ReadPrec Principal
Int -> ReadS Principal
ReadS [Principal]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Principal]
$creadListPrec :: ReadPrec [Principal]
readPrec :: ReadPrec Principal
$creadPrec :: ReadPrec Principal
readList :: ReadS [Principal]
$creadList :: ReadS [Principal]
readsPrec :: Int -> ReadS Principal
$creadsPrec :: Int -> ReadS Principal
Prelude.Read, Int -> Principal -> ShowS
[Principal] -> ShowS
Principal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Principal] -> ShowS
$cshowList :: [Principal] -> ShowS
show :: Principal -> String
$cshow :: Principal -> String
showsPrec :: Int -> Principal -> ShowS
$cshowsPrec :: Int -> Principal -> ShowS
Prelude.Show, forall x. Rep Principal x -> Principal
forall x. Principal -> Rep Principal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Principal x -> Principal
$cfrom :: forall x. Principal -> Rep Principal x
Prelude.Generic)

-- |
-- Create a value of 'Principal' 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:
--
-- 'principalARN', 'principal_principalARN' - The ARN of the principal (IAM user, role, or group). This field allows
-- for an ARN with no @accountID@ if the @PrincipalType@ is an
-- @IAM_PATTERN@.
--
-- 'principalType', 'principal_principalType' - The principal type. The supported value is @IAM@ if you use a fully
-- defined ARN, or @IAM_PATTERN@ if you use an ARN with no @accountID@.
newPrincipal ::
  Principal
newPrincipal :: Principal
newPrincipal =
  Principal'
    { $sel:principalARN:Principal' :: Maybe Text
principalARN = forall a. Maybe a
Prelude.Nothing,
      $sel:principalType:Principal' :: Maybe PrincipalType
principalType = forall a. Maybe a
Prelude.Nothing
    }

-- | The ARN of the principal (IAM user, role, or group). This field allows
-- for an ARN with no @accountID@ if the @PrincipalType@ is an
-- @IAM_PATTERN@.
principal_principalARN :: Lens.Lens' Principal (Prelude.Maybe Prelude.Text)
principal_principalARN :: Lens' Principal (Maybe Text)
principal_principalARN = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Maybe Text
principalARN :: Maybe Text
$sel:principalARN:Principal' :: Principal -> Maybe Text
principalARN} -> Maybe Text
principalARN) (\s :: Principal
s@Principal' {} Maybe Text
a -> Principal
s {$sel:principalARN:Principal' :: Maybe Text
principalARN = Maybe Text
a} :: Principal)

-- | The principal type. The supported value is @IAM@ if you use a fully
-- defined ARN, or @IAM_PATTERN@ if you use an ARN with no @accountID@.
principal_principalType :: Lens.Lens' Principal (Prelude.Maybe PrincipalType)
principal_principalType :: Lens' Principal (Maybe PrincipalType)
principal_principalType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Maybe PrincipalType
principalType :: Maybe PrincipalType
$sel:principalType:Principal' :: Principal -> Maybe PrincipalType
principalType} -> Maybe PrincipalType
principalType) (\s :: Principal
s@Principal' {} Maybe PrincipalType
a -> Principal
s {$sel:principalType:Principal' :: Maybe PrincipalType
principalType = Maybe PrincipalType
a} :: Principal)

instance Data.FromJSON Principal where
  parseJSON :: Value -> Parser Principal
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Principal"
      ( \Object
x ->
          Maybe Text -> Maybe PrincipalType -> Principal
Principal'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PrincipalARN")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PrincipalType")
      )

instance Prelude.Hashable Principal where
  hashWithSalt :: Int -> Principal -> Int
hashWithSalt Int
_salt Principal' {Maybe Text
Maybe PrincipalType
principalType :: Maybe PrincipalType
principalARN :: Maybe Text
$sel:principalType:Principal' :: Principal -> Maybe PrincipalType
$sel:principalARN:Principal' :: Principal -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
principalARN
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PrincipalType
principalType

instance Prelude.NFData Principal where
  rnf :: Principal -> ()
rnf Principal' {Maybe Text
Maybe PrincipalType
principalType :: Maybe PrincipalType
principalARN :: Maybe Text
$sel:principalType:Principal' :: Principal -> Maybe PrincipalType
$sel:principalARN:Principal' :: Principal -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
principalARN
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PrincipalType
principalType