{-# 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.AccessAnalyzer.Types.PolicyGeneration
-- 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.AccessAnalyzer.Types.PolicyGeneration where

import Amazonka.AccessAnalyzer.Types.JobStatus
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains details about the policy generation status and properties.
--
-- /See:/ 'newPolicyGeneration' smart constructor.
data PolicyGeneration = PolicyGeneration'
  { -- | A timestamp of when the policy generation was completed.
    PolicyGeneration -> Maybe POSIX
completedOn :: Prelude.Maybe Core.POSIX,
    -- | The @JobId@ that is returned by the @StartPolicyGeneration@ operation.
    -- The @JobId@ can be used with @GetGeneratedPolicy@ to retrieve the
    -- generated policies or used with @CancelPolicyGeneration@ to cancel the
    -- policy generation request.
    PolicyGeneration -> Text
jobId :: Prelude.Text,
    -- | The ARN of the IAM entity (user or role) for which you are generating a
    -- policy.
    PolicyGeneration -> Text
principalArn :: Prelude.Text,
    -- | A timestamp of when the policy generation started.
    PolicyGeneration -> POSIX
startedOn :: Core.POSIX,
    -- | The status of the policy generation request.
    PolicyGeneration -> JobStatus
status :: JobStatus
  }
  deriving (PolicyGeneration -> PolicyGeneration -> Bool
(PolicyGeneration -> PolicyGeneration -> Bool)
-> (PolicyGeneration -> PolicyGeneration -> Bool)
-> Eq PolicyGeneration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PolicyGeneration -> PolicyGeneration -> Bool
$c/= :: PolicyGeneration -> PolicyGeneration -> Bool
== :: PolicyGeneration -> PolicyGeneration -> Bool
$c== :: PolicyGeneration -> PolicyGeneration -> Bool
Prelude.Eq, ReadPrec [PolicyGeneration]
ReadPrec PolicyGeneration
Int -> ReadS PolicyGeneration
ReadS [PolicyGeneration]
(Int -> ReadS PolicyGeneration)
-> ReadS [PolicyGeneration]
-> ReadPrec PolicyGeneration
-> ReadPrec [PolicyGeneration]
-> Read PolicyGeneration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PolicyGeneration]
$creadListPrec :: ReadPrec [PolicyGeneration]
readPrec :: ReadPrec PolicyGeneration
$creadPrec :: ReadPrec PolicyGeneration
readList :: ReadS [PolicyGeneration]
$creadList :: ReadS [PolicyGeneration]
readsPrec :: Int -> ReadS PolicyGeneration
$creadsPrec :: Int -> ReadS PolicyGeneration
Prelude.Read, Int -> PolicyGeneration -> ShowS
[PolicyGeneration] -> ShowS
PolicyGeneration -> String
(Int -> PolicyGeneration -> ShowS)
-> (PolicyGeneration -> String)
-> ([PolicyGeneration] -> ShowS)
-> Show PolicyGeneration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PolicyGeneration] -> ShowS
$cshowList :: [PolicyGeneration] -> ShowS
show :: PolicyGeneration -> String
$cshow :: PolicyGeneration -> String
showsPrec :: Int -> PolicyGeneration -> ShowS
$cshowsPrec :: Int -> PolicyGeneration -> ShowS
Prelude.Show, (forall x. PolicyGeneration -> Rep PolicyGeneration x)
-> (forall x. Rep PolicyGeneration x -> PolicyGeneration)
-> Generic PolicyGeneration
forall x. Rep PolicyGeneration x -> PolicyGeneration
forall x. PolicyGeneration -> Rep PolicyGeneration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PolicyGeneration x -> PolicyGeneration
$cfrom :: forall x. PolicyGeneration -> Rep PolicyGeneration x
Prelude.Generic)

-- |
-- Create a value of 'PolicyGeneration' 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:
--
-- 'completedOn', 'policyGeneration_completedOn' - A timestamp of when the policy generation was completed.
--
-- 'jobId', 'policyGeneration_jobId' - The @JobId@ that is returned by the @StartPolicyGeneration@ operation.
-- The @JobId@ can be used with @GetGeneratedPolicy@ to retrieve the
-- generated policies or used with @CancelPolicyGeneration@ to cancel the
-- policy generation request.
--
-- 'principalArn', 'policyGeneration_principalArn' - The ARN of the IAM entity (user or role) for which you are generating a
-- policy.
--
-- 'startedOn', 'policyGeneration_startedOn' - A timestamp of when the policy generation started.
--
-- 'status', 'policyGeneration_status' - The status of the policy generation request.
newPolicyGeneration ::
  -- | 'jobId'
  Prelude.Text ->
  -- | 'principalArn'
  Prelude.Text ->
  -- | 'startedOn'
  Prelude.UTCTime ->
  -- | 'status'
  JobStatus ->
  PolicyGeneration
newPolicyGeneration :: Text -> Text -> UTCTime -> JobStatus -> PolicyGeneration
newPolicyGeneration
  Text
pJobId_
  Text
pPrincipalArn_
  UTCTime
pStartedOn_
  JobStatus
pStatus_ =
    PolicyGeneration' :: Maybe POSIX
-> Text -> Text -> POSIX -> JobStatus -> PolicyGeneration
PolicyGeneration'
      { $sel:completedOn:PolicyGeneration' :: Maybe POSIX
completedOn = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
        $sel:jobId:PolicyGeneration' :: Text
jobId = Text
pJobId_,
        $sel:principalArn:PolicyGeneration' :: Text
principalArn = Text
pPrincipalArn_,
        $sel:startedOn:PolicyGeneration' :: POSIX
startedOn = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pStartedOn_,
        $sel:status:PolicyGeneration' :: JobStatus
status = JobStatus
pStatus_
      }

-- | A timestamp of when the policy generation was completed.
policyGeneration_completedOn :: Lens.Lens' PolicyGeneration (Prelude.Maybe Prelude.UTCTime)
policyGeneration_completedOn :: (Maybe UTCTime -> f (Maybe UTCTime))
-> PolicyGeneration -> f PolicyGeneration
policyGeneration_completedOn = (PolicyGeneration -> Maybe POSIX)
-> (PolicyGeneration -> Maybe POSIX -> PolicyGeneration)
-> Lens
     PolicyGeneration PolicyGeneration (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyGeneration' {Maybe POSIX
completedOn :: Maybe POSIX
$sel:completedOn:PolicyGeneration' :: PolicyGeneration -> Maybe POSIX
completedOn} -> Maybe POSIX
completedOn) (\s :: PolicyGeneration
s@PolicyGeneration' {} Maybe POSIX
a -> PolicyGeneration
s {$sel:completedOn:PolicyGeneration' :: Maybe POSIX
completedOn = Maybe POSIX
a} :: PolicyGeneration) ((Maybe POSIX -> f (Maybe POSIX))
 -> PolicyGeneration -> f PolicyGeneration)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> PolicyGeneration
-> f PolicyGeneration
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 @JobId@ that is returned by the @StartPolicyGeneration@ operation.
-- The @JobId@ can be used with @GetGeneratedPolicy@ to retrieve the
-- generated policies or used with @CancelPolicyGeneration@ to cancel the
-- policy generation request.
policyGeneration_jobId :: Lens.Lens' PolicyGeneration Prelude.Text
policyGeneration_jobId :: (Text -> f Text) -> PolicyGeneration -> f PolicyGeneration
policyGeneration_jobId = (PolicyGeneration -> Text)
-> (PolicyGeneration -> Text -> PolicyGeneration)
-> Lens PolicyGeneration PolicyGeneration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyGeneration' {Text
jobId :: Text
$sel:jobId:PolicyGeneration' :: PolicyGeneration -> Text
jobId} -> Text
jobId) (\s :: PolicyGeneration
s@PolicyGeneration' {} Text
a -> PolicyGeneration
s {$sel:jobId:PolicyGeneration' :: Text
jobId = Text
a} :: PolicyGeneration)

-- | The ARN of the IAM entity (user or role) for which you are generating a
-- policy.
policyGeneration_principalArn :: Lens.Lens' PolicyGeneration Prelude.Text
policyGeneration_principalArn :: (Text -> f Text) -> PolicyGeneration -> f PolicyGeneration
policyGeneration_principalArn = (PolicyGeneration -> Text)
-> (PolicyGeneration -> Text -> PolicyGeneration)
-> Lens PolicyGeneration PolicyGeneration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyGeneration' {Text
principalArn :: Text
$sel:principalArn:PolicyGeneration' :: PolicyGeneration -> Text
principalArn} -> Text
principalArn) (\s :: PolicyGeneration
s@PolicyGeneration' {} Text
a -> PolicyGeneration
s {$sel:principalArn:PolicyGeneration' :: Text
principalArn = Text
a} :: PolicyGeneration)

-- | A timestamp of when the policy generation started.
policyGeneration_startedOn :: Lens.Lens' PolicyGeneration Prelude.UTCTime
policyGeneration_startedOn :: (UTCTime -> f UTCTime) -> PolicyGeneration -> f PolicyGeneration
policyGeneration_startedOn = (PolicyGeneration -> POSIX)
-> (PolicyGeneration -> POSIX -> PolicyGeneration)
-> Lens PolicyGeneration PolicyGeneration POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyGeneration' {POSIX
startedOn :: POSIX
$sel:startedOn:PolicyGeneration' :: PolicyGeneration -> POSIX
startedOn} -> POSIX
startedOn) (\s :: PolicyGeneration
s@PolicyGeneration' {} POSIX
a -> PolicyGeneration
s {$sel:startedOn:PolicyGeneration' :: POSIX
startedOn = POSIX
a} :: PolicyGeneration) ((POSIX -> f POSIX) -> PolicyGeneration -> f PolicyGeneration)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> PolicyGeneration
-> f PolicyGeneration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The status of the policy generation request.
policyGeneration_status :: Lens.Lens' PolicyGeneration JobStatus
policyGeneration_status :: (JobStatus -> f JobStatus)
-> PolicyGeneration -> f PolicyGeneration
policyGeneration_status = (PolicyGeneration -> JobStatus)
-> (PolicyGeneration -> JobStatus -> PolicyGeneration)
-> Lens PolicyGeneration PolicyGeneration JobStatus JobStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyGeneration' {JobStatus
status :: JobStatus
$sel:status:PolicyGeneration' :: PolicyGeneration -> JobStatus
status} -> JobStatus
status) (\s :: PolicyGeneration
s@PolicyGeneration' {} JobStatus
a -> PolicyGeneration
s {$sel:status:PolicyGeneration' :: JobStatus
status = JobStatus
a} :: PolicyGeneration)

instance Core.FromJSON PolicyGeneration where
  parseJSON :: Value -> Parser PolicyGeneration
parseJSON =
    String
-> (Object -> Parser PolicyGeneration)
-> Value
-> Parser PolicyGeneration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PolicyGeneration"
      ( \Object
x ->
          Maybe POSIX
-> Text -> Text -> POSIX -> JobStatus -> PolicyGeneration
PolicyGeneration'
            (Maybe POSIX
 -> Text -> Text -> POSIX -> JobStatus -> PolicyGeneration)
-> Parser (Maybe POSIX)
-> Parser (Text -> Text -> POSIX -> JobStatus -> PolicyGeneration)
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
"completedOn")
            Parser (Text -> Text -> POSIX -> JobStatus -> PolicyGeneration)
-> Parser Text
-> Parser (Text -> POSIX -> JobStatus -> PolicyGeneration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"jobId")
            Parser (Text -> POSIX -> JobStatus -> PolicyGeneration)
-> Parser Text -> Parser (POSIX -> JobStatus -> PolicyGeneration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"principalArn")
            Parser (POSIX -> JobStatus -> PolicyGeneration)
-> Parser POSIX -> Parser (JobStatus -> PolicyGeneration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"startedOn")
            Parser (JobStatus -> PolicyGeneration)
-> Parser JobStatus -> Parser PolicyGeneration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser JobStatus
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"status")
      )

instance Prelude.Hashable PolicyGeneration

instance Prelude.NFData PolicyGeneration