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

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

-- | Information about a principal.
--
-- /See:/ 'newPrincipal' smart constructor.
data Principal = Principal'
  { -- | The principal type. The supported value is @IAM@.
    Principal -> Maybe PrincipalType
principalType :: Prelude.Maybe PrincipalType,
    -- | The ARN of the principal (IAM user, role, or group).
    Principal -> Maybe Text
principalARN :: Prelude.Maybe Prelude.Text
  }
  deriving (Principal -> Principal -> Bool
(Principal -> Principal -> Bool)
-> (Principal -> Principal -> Bool) -> Eq Principal
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]
(Int -> ReadS Principal)
-> ReadS [Principal]
-> ReadPrec Principal
-> ReadPrec [Principal]
-> Read 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
(Int -> Principal -> ShowS)
-> (Principal -> String)
-> ([Principal] -> ShowS)
-> Show Principal
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. Principal -> Rep Principal x)
-> (forall x. Rep Principal x -> Principal) -> Generic Principal
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:
--
-- 'principalType', 'principal_principalType' - The principal type. The supported value is @IAM@.
--
-- 'principalARN', 'principal_principalARN' - The ARN of the principal (IAM user, role, or group).
newPrincipal ::
  Principal
newPrincipal :: Principal
newPrincipal =
  Principal' :: Maybe PrincipalType -> Maybe Text -> Principal
Principal'
    { $sel:principalType:Principal' :: Maybe PrincipalType
principalType = Maybe PrincipalType
forall a. Maybe a
Prelude.Nothing,
      $sel:principalARN:Principal' :: Maybe Text
principalARN = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The principal type. The supported value is @IAM@.
principal_principalType :: Lens.Lens' Principal (Prelude.Maybe PrincipalType)
principal_principalType :: (Maybe PrincipalType -> f (Maybe PrincipalType))
-> Principal -> f Principal
principal_principalType = (Principal -> Maybe PrincipalType)
-> (Principal -> Maybe PrincipalType -> Principal)
-> Lens
     Principal Principal (Maybe PrincipalType) (Maybe 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)

-- | The ARN of the principal (IAM user, role, or group).
principal_principalARN :: Lens.Lens' Principal (Prelude.Maybe Prelude.Text)
principal_principalARN :: (Maybe Text -> f (Maybe Text)) -> Principal -> f Principal
principal_principalARN = (Principal -> Maybe Text)
-> (Principal -> Maybe Text -> Principal)
-> Lens Principal Principal (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON Principal where
  parseJSON :: Value -> Parser Principal
parseJSON =
    String -> (Object -> Parser Principal) -> Value -> Parser Principal
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Principal"
      ( \Object
x ->
          Maybe PrincipalType -> Maybe Text -> Principal
Principal'
            (Maybe PrincipalType -> Maybe Text -> Principal)
-> Parser (Maybe PrincipalType) -> Parser (Maybe Text -> Principal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe PrincipalType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PrincipalType")
            Parser (Maybe Text -> Principal)
-> Parser (Maybe Text) -> Parser Principal
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
"PrincipalARN")
      )

instance Prelude.Hashable Principal

instance Prelude.NFData Principal