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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WorkDocs.Types.PermissionInfo
import Amazonka.WorkDocs.Types.PrincipalType

-- | Describes a resource.
--
-- /See:/ 'newPrincipal' smart constructor.
data Principal = Principal'
  { -- | The permission information for the resource.
    Principal -> Maybe [PermissionInfo]
roles :: Prelude.Maybe [PermissionInfo],
    -- | The ID of the resource.
    Principal -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The type of resource.
    Principal -> Maybe PrincipalType
type' :: Prelude.Maybe PrincipalType
  }
  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:
--
-- 'roles', 'principal_roles' - The permission information for the resource.
--
-- 'id', 'principal_id' - The ID of the resource.
--
-- 'type'', 'principal_type' - The type of resource.
newPrincipal ::
  Principal
newPrincipal :: Principal
newPrincipal =
  Principal' :: Maybe [PermissionInfo]
-> Maybe Text -> Maybe PrincipalType -> Principal
Principal'
    { $sel:roles:Principal' :: Maybe [PermissionInfo]
roles = Maybe [PermissionInfo]
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Principal' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Principal' :: Maybe PrincipalType
type' = Maybe PrincipalType
forall a. Maybe a
Prelude.Nothing
    }

-- | The permission information for the resource.
principal_roles :: Lens.Lens' Principal (Prelude.Maybe [PermissionInfo])
principal_roles :: (Maybe [PermissionInfo] -> f (Maybe [PermissionInfo]))
-> Principal -> f Principal
principal_roles = (Principal -> Maybe [PermissionInfo])
-> (Principal -> Maybe [PermissionInfo] -> Principal)
-> Lens
     Principal
     Principal
     (Maybe [PermissionInfo])
     (Maybe [PermissionInfo])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Maybe [PermissionInfo]
roles :: Maybe [PermissionInfo]
$sel:roles:Principal' :: Principal -> Maybe [PermissionInfo]
roles} -> Maybe [PermissionInfo]
roles) (\s :: Principal
s@Principal' {} Maybe [PermissionInfo]
a -> Principal
s {$sel:roles:Principal' :: Maybe [PermissionInfo]
roles = Maybe [PermissionInfo]
a} :: Principal) ((Maybe [PermissionInfo] -> f (Maybe [PermissionInfo]))
 -> Principal -> f Principal)
-> ((Maybe [PermissionInfo] -> f (Maybe [PermissionInfo]))
    -> Maybe [PermissionInfo] -> f (Maybe [PermissionInfo]))
-> (Maybe [PermissionInfo] -> f (Maybe [PermissionInfo]))
-> Principal
-> f Principal
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PermissionInfo] [PermissionInfo] [PermissionInfo] [PermissionInfo]
-> Iso
     (Maybe [PermissionInfo])
     (Maybe [PermissionInfo])
     (Maybe [PermissionInfo])
     (Maybe [PermissionInfo])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [PermissionInfo] [PermissionInfo] [PermissionInfo] [PermissionInfo]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the resource.
principal_id :: Lens.Lens' Principal (Prelude.Maybe Prelude.Text)
principal_id :: (Maybe Text -> f (Maybe Text)) -> Principal -> f Principal
principal_id = (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
id :: Maybe Text
$sel:id:Principal' :: Principal -> Maybe Text
id} -> Maybe Text
id) (\s :: Principal
s@Principal' {} Maybe Text
a -> Principal
s {$sel:id:Principal' :: Maybe Text
id = Maybe Text
a} :: Principal)

-- | The type of resource.
principal_type :: Lens.Lens' Principal (Prelude.Maybe PrincipalType)
principal_type :: (Maybe PrincipalType -> f (Maybe PrincipalType))
-> Principal -> f Principal
principal_type = (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
type' :: Maybe PrincipalType
$sel:type':Principal' :: Principal -> Maybe PrincipalType
type'} -> Maybe PrincipalType
type') (\s :: Principal
s@Principal' {} Maybe PrincipalType
a -> Principal
s {$sel:type':Principal' :: Maybe PrincipalType
type' = Maybe PrincipalType
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 [PermissionInfo]
-> Maybe Text -> Maybe PrincipalType -> Principal
Principal'
            (Maybe [PermissionInfo]
 -> Maybe Text -> Maybe PrincipalType -> Principal)
-> Parser (Maybe [PermissionInfo])
-> Parser (Maybe Text -> Maybe PrincipalType -> Principal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [PermissionInfo]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Roles" Parser (Maybe (Maybe [PermissionInfo]))
-> Maybe [PermissionInfo] -> Parser (Maybe [PermissionInfo])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [PermissionInfo]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> Maybe PrincipalType -> Principal)
-> Parser (Maybe Text) -> Parser (Maybe PrincipalType -> 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
"Id")
            Parser (Maybe PrincipalType -> Principal)
-> Parser (Maybe PrincipalType) -> Parser Principal
forall (f :: * -> *) a b. Applicative f => 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
"Type")
      )

instance Prelude.Hashable Principal

instance Prelude.NFData Principal