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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a principal for use with Resource Access Manager.
--
-- /See:/ 'newPrincipal' smart constructor.
data Principal = Principal'
  { -- | The time when the principal was associated with the resource share.
    Principal -> Maybe POSIX
creationTime :: Prelude.Maybe Core.POSIX,
    -- | The Amazon Resource Name (ARN) of the resource share.
    Principal -> Maybe Text
resourceShareArn :: Prelude.Maybe Prelude.Text,
    -- | The time when the association was last updated.
    Principal -> Maybe POSIX
lastUpdatedTime :: Prelude.Maybe Core.POSIX,
    -- | Indicates whether the principal belongs to the same organization in
    -- Organizations as the Amazon Web Services account that owns the resource
    -- share.
    Principal -> Maybe Bool
external :: Prelude.Maybe Prelude.Bool,
    -- | The ID of the principal.
    Principal -> Maybe Text
id :: 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:
--
-- 'creationTime', 'principal_creationTime' - The time when the principal was associated with the resource share.
--
-- 'resourceShareArn', 'principal_resourceShareArn' - The Amazon Resource Name (ARN) of the resource share.
--
-- 'lastUpdatedTime', 'principal_lastUpdatedTime' - The time when the association was last updated.
--
-- 'external', 'principal_external' - Indicates whether the principal belongs to the same organization in
-- Organizations as the Amazon Web Services account that owns the resource
-- share.
--
-- 'id', 'principal_id' - The ID of the principal.
newPrincipal ::
  Principal
newPrincipal :: Principal
newPrincipal =
  Principal' :: Maybe POSIX
-> Maybe Text
-> Maybe POSIX
-> Maybe Bool
-> Maybe Text
-> Principal
Principal'
    { $sel:creationTime:Principal' :: Maybe POSIX
creationTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceShareArn:Principal' :: Maybe Text
resourceShareArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastUpdatedTime:Principal' :: Maybe POSIX
lastUpdatedTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:external:Principal' :: Maybe Bool
external = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Principal' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The time when the principal was associated with the resource share.
principal_creationTime :: Lens.Lens' Principal (Prelude.Maybe Prelude.UTCTime)
principal_creationTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Principal -> f Principal
principal_creationTime = (Principal -> Maybe POSIX)
-> (Principal -> Maybe POSIX -> Principal)
-> Lens Principal Principal (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Maybe POSIX
creationTime :: Maybe POSIX
$sel:creationTime:Principal' :: Principal -> Maybe POSIX
creationTime} -> Maybe POSIX
creationTime) (\s :: Principal
s@Principal' {} Maybe POSIX
a -> Principal
s {$sel:creationTime:Principal' :: Maybe POSIX
creationTime = Maybe POSIX
a} :: Principal) ((Maybe POSIX -> f (Maybe POSIX)) -> Principal -> f Principal)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Principal
-> f Principal
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The Amazon Resource Name (ARN) of the resource share.
principal_resourceShareArn :: Lens.Lens' Principal (Prelude.Maybe Prelude.Text)
principal_resourceShareArn :: (Maybe Text -> f (Maybe Text)) -> Principal -> f Principal
principal_resourceShareArn = (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
resourceShareArn :: Maybe Text
$sel:resourceShareArn:Principal' :: Principal -> Maybe Text
resourceShareArn} -> Maybe Text
resourceShareArn) (\s :: Principal
s@Principal' {} Maybe Text
a -> Principal
s {$sel:resourceShareArn:Principal' :: Maybe Text
resourceShareArn = Maybe Text
a} :: Principal)

-- | The time when the association was last updated.
principal_lastUpdatedTime :: Lens.Lens' Principal (Prelude.Maybe Prelude.UTCTime)
principal_lastUpdatedTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Principal -> f Principal
principal_lastUpdatedTime = (Principal -> Maybe POSIX)
-> (Principal -> Maybe POSIX -> Principal)
-> Lens Principal Principal (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Maybe POSIX
lastUpdatedTime :: Maybe POSIX
$sel:lastUpdatedTime:Principal' :: Principal -> Maybe POSIX
lastUpdatedTime} -> Maybe POSIX
lastUpdatedTime) (\s :: Principal
s@Principal' {} Maybe POSIX
a -> Principal
s {$sel:lastUpdatedTime:Principal' :: Maybe POSIX
lastUpdatedTime = Maybe POSIX
a} :: Principal) ((Maybe POSIX -> f (Maybe POSIX)) -> Principal -> f Principal)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Principal
-> f Principal
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | Indicates whether the principal belongs to the same organization in
-- Organizations as the Amazon Web Services account that owns the resource
-- share.
principal_external :: Lens.Lens' Principal (Prelude.Maybe Prelude.Bool)
principal_external :: (Maybe Bool -> f (Maybe Bool)) -> Principal -> f Principal
principal_external = (Principal -> Maybe Bool)
-> (Principal -> Maybe Bool -> Principal)
-> Lens Principal Principal (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Principal' {Maybe Bool
external :: Maybe Bool
$sel:external:Principal' :: Principal -> Maybe Bool
external} -> Maybe Bool
external) (\s :: Principal
s@Principal' {} Maybe Bool
a -> Principal
s {$sel:external:Principal' :: Maybe Bool
external = Maybe Bool
a} :: Principal)

-- | The ID of the principal.
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)

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 POSIX
-> Maybe Text
-> Maybe POSIX
-> Maybe Bool
-> Maybe Text
-> Principal
Principal'
            (Maybe POSIX
 -> Maybe Text
 -> Maybe POSIX
 -> Maybe Bool
 -> Maybe Text
 -> Principal)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe Text
      -> Maybe POSIX -> Maybe Bool -> Maybe Text -> Principal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"creationTime")
            Parser
  (Maybe Text
   -> Maybe POSIX -> Maybe Bool -> Maybe Text -> Principal)
-> Parser (Maybe Text)
-> Parser (Maybe POSIX -> Maybe Bool -> Maybe Text -> 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
"resourceShareArn")
            Parser (Maybe POSIX -> Maybe Bool -> Maybe Text -> Principal)
-> Parser (Maybe POSIX)
-> Parser (Maybe Bool -> Maybe Text -> Principal)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lastUpdatedTime")
            Parser (Maybe Bool -> Maybe Text -> Principal)
-> Parser (Maybe Bool) -> Parser (Maybe Text -> Principal)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"external")
            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
"id")
      )

instance Prelude.Hashable Principal

instance Prelude.NFData Principal