{-# 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.Organizations.Types.EffectivePolicy
-- 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.Organizations.Types.EffectivePolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Organizations.Types.EffectivePolicyType
import qualified Amazonka.Prelude as Prelude

-- | Contains rules to be applied to the affected accounts. The effective
-- policy is the aggregation of any policies the account inherits, plus any
-- policy directly attached to the account.
--
-- /See:/ 'newEffectivePolicy' smart constructor.
data EffectivePolicy = EffectivePolicy'
  { -- | The account ID of the policy target.
    EffectivePolicy -> Maybe Text
targetId :: Prelude.Maybe Prelude.Text,
    -- | The policy type.
    EffectivePolicy -> Maybe EffectivePolicyType
policyType :: Prelude.Maybe EffectivePolicyType,
    -- | The time of the last update to this policy.
    EffectivePolicy -> Maybe POSIX
lastUpdatedTimestamp :: Prelude.Maybe Core.POSIX,
    -- | The text content of the policy.
    EffectivePolicy -> Maybe Text
policyContent :: Prelude.Maybe Prelude.Text
  }
  deriving (EffectivePolicy -> EffectivePolicy -> Bool
(EffectivePolicy -> EffectivePolicy -> Bool)
-> (EffectivePolicy -> EffectivePolicy -> Bool)
-> Eq EffectivePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EffectivePolicy -> EffectivePolicy -> Bool
$c/= :: EffectivePolicy -> EffectivePolicy -> Bool
== :: EffectivePolicy -> EffectivePolicy -> Bool
$c== :: EffectivePolicy -> EffectivePolicy -> Bool
Prelude.Eq, ReadPrec [EffectivePolicy]
ReadPrec EffectivePolicy
Int -> ReadS EffectivePolicy
ReadS [EffectivePolicy]
(Int -> ReadS EffectivePolicy)
-> ReadS [EffectivePolicy]
-> ReadPrec EffectivePolicy
-> ReadPrec [EffectivePolicy]
-> Read EffectivePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EffectivePolicy]
$creadListPrec :: ReadPrec [EffectivePolicy]
readPrec :: ReadPrec EffectivePolicy
$creadPrec :: ReadPrec EffectivePolicy
readList :: ReadS [EffectivePolicy]
$creadList :: ReadS [EffectivePolicy]
readsPrec :: Int -> ReadS EffectivePolicy
$creadsPrec :: Int -> ReadS EffectivePolicy
Prelude.Read, Int -> EffectivePolicy -> ShowS
[EffectivePolicy] -> ShowS
EffectivePolicy -> String
(Int -> EffectivePolicy -> ShowS)
-> (EffectivePolicy -> String)
-> ([EffectivePolicy] -> ShowS)
-> Show EffectivePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EffectivePolicy] -> ShowS
$cshowList :: [EffectivePolicy] -> ShowS
show :: EffectivePolicy -> String
$cshow :: EffectivePolicy -> String
showsPrec :: Int -> EffectivePolicy -> ShowS
$cshowsPrec :: Int -> EffectivePolicy -> ShowS
Prelude.Show, (forall x. EffectivePolicy -> Rep EffectivePolicy x)
-> (forall x. Rep EffectivePolicy x -> EffectivePolicy)
-> Generic EffectivePolicy
forall x. Rep EffectivePolicy x -> EffectivePolicy
forall x. EffectivePolicy -> Rep EffectivePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EffectivePolicy x -> EffectivePolicy
$cfrom :: forall x. EffectivePolicy -> Rep EffectivePolicy x
Prelude.Generic)

-- |
-- Create a value of 'EffectivePolicy' 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:
--
-- 'targetId', 'effectivePolicy_targetId' - The account ID of the policy target.
--
-- 'policyType', 'effectivePolicy_policyType' - The policy type.
--
-- 'lastUpdatedTimestamp', 'effectivePolicy_lastUpdatedTimestamp' - The time of the last update to this policy.
--
-- 'policyContent', 'effectivePolicy_policyContent' - The text content of the policy.
newEffectivePolicy ::
  EffectivePolicy
newEffectivePolicy :: EffectivePolicy
newEffectivePolicy =
  EffectivePolicy' :: Maybe Text
-> Maybe EffectivePolicyType
-> Maybe POSIX
-> Maybe Text
-> EffectivePolicy
EffectivePolicy'
    { $sel:targetId:EffectivePolicy' :: Maybe Text
targetId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyType:EffectivePolicy' :: Maybe EffectivePolicyType
policyType = Maybe EffectivePolicyType
forall a. Maybe a
Prelude.Nothing,
      $sel:lastUpdatedTimestamp:EffectivePolicy' :: Maybe POSIX
lastUpdatedTimestamp = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:policyContent:EffectivePolicy' :: Maybe Text
policyContent = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The account ID of the policy target.
effectivePolicy_targetId :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.Text)
effectivePolicy_targetId :: (Maybe Text -> f (Maybe Text))
-> EffectivePolicy -> f EffectivePolicy
effectivePolicy_targetId = (EffectivePolicy -> Maybe Text)
-> (EffectivePolicy -> Maybe Text -> EffectivePolicy)
-> Lens EffectivePolicy EffectivePolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EffectivePolicy' {Maybe Text
targetId :: Maybe Text
$sel:targetId:EffectivePolicy' :: EffectivePolicy -> Maybe Text
targetId} -> Maybe Text
targetId) (\s :: EffectivePolicy
s@EffectivePolicy' {} Maybe Text
a -> EffectivePolicy
s {$sel:targetId:EffectivePolicy' :: Maybe Text
targetId = Maybe Text
a} :: EffectivePolicy)

-- | The policy type.
effectivePolicy_policyType :: Lens.Lens' EffectivePolicy (Prelude.Maybe EffectivePolicyType)
effectivePolicy_policyType :: (Maybe EffectivePolicyType -> f (Maybe EffectivePolicyType))
-> EffectivePolicy -> f EffectivePolicy
effectivePolicy_policyType = (EffectivePolicy -> Maybe EffectivePolicyType)
-> (EffectivePolicy
    -> Maybe EffectivePolicyType -> EffectivePolicy)
-> Lens
     EffectivePolicy
     EffectivePolicy
     (Maybe EffectivePolicyType)
     (Maybe EffectivePolicyType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EffectivePolicy' {Maybe EffectivePolicyType
policyType :: Maybe EffectivePolicyType
$sel:policyType:EffectivePolicy' :: EffectivePolicy -> Maybe EffectivePolicyType
policyType} -> Maybe EffectivePolicyType
policyType) (\s :: EffectivePolicy
s@EffectivePolicy' {} Maybe EffectivePolicyType
a -> EffectivePolicy
s {$sel:policyType:EffectivePolicy' :: Maybe EffectivePolicyType
policyType = Maybe EffectivePolicyType
a} :: EffectivePolicy)

-- | The time of the last update to this policy.
effectivePolicy_lastUpdatedTimestamp :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.UTCTime)
effectivePolicy_lastUpdatedTimestamp :: (Maybe UTCTime -> f (Maybe UTCTime))
-> EffectivePolicy -> f EffectivePolicy
effectivePolicy_lastUpdatedTimestamp = (EffectivePolicy -> Maybe POSIX)
-> (EffectivePolicy -> Maybe POSIX -> EffectivePolicy)
-> Lens EffectivePolicy EffectivePolicy (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EffectivePolicy' {Maybe POSIX
lastUpdatedTimestamp :: Maybe POSIX
$sel:lastUpdatedTimestamp:EffectivePolicy' :: EffectivePolicy -> Maybe POSIX
lastUpdatedTimestamp} -> Maybe POSIX
lastUpdatedTimestamp) (\s :: EffectivePolicy
s@EffectivePolicy' {} Maybe POSIX
a -> EffectivePolicy
s {$sel:lastUpdatedTimestamp:EffectivePolicy' :: Maybe POSIX
lastUpdatedTimestamp = Maybe POSIX
a} :: EffectivePolicy) ((Maybe POSIX -> f (Maybe POSIX))
 -> EffectivePolicy -> f EffectivePolicy)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> EffectivePolicy
-> f EffectivePolicy
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 text content of the policy.
effectivePolicy_policyContent :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.Text)
effectivePolicy_policyContent :: (Maybe Text -> f (Maybe Text))
-> EffectivePolicy -> f EffectivePolicy
effectivePolicy_policyContent = (EffectivePolicy -> Maybe Text)
-> (EffectivePolicy -> Maybe Text -> EffectivePolicy)
-> Lens EffectivePolicy EffectivePolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EffectivePolicy' {Maybe Text
policyContent :: Maybe Text
$sel:policyContent:EffectivePolicy' :: EffectivePolicy -> Maybe Text
policyContent} -> Maybe Text
policyContent) (\s :: EffectivePolicy
s@EffectivePolicy' {} Maybe Text
a -> EffectivePolicy
s {$sel:policyContent:EffectivePolicy' :: Maybe Text
policyContent = Maybe Text
a} :: EffectivePolicy)

instance Core.FromJSON EffectivePolicy where
  parseJSON :: Value -> Parser EffectivePolicy
parseJSON =
    String
-> (Object -> Parser EffectivePolicy)
-> Value
-> Parser EffectivePolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EffectivePolicy"
      ( \Object
x ->
          Maybe Text
-> Maybe EffectivePolicyType
-> Maybe POSIX
-> Maybe Text
-> EffectivePolicy
EffectivePolicy'
            (Maybe Text
 -> Maybe EffectivePolicyType
 -> Maybe POSIX
 -> Maybe Text
 -> EffectivePolicy)
-> Parser (Maybe Text)
-> Parser
     (Maybe EffectivePolicyType
      -> Maybe POSIX -> Maybe Text -> EffectivePolicy)
forall (f :: * -> *) a b. Functor 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
"TargetId")
            Parser
  (Maybe EffectivePolicyType
   -> Maybe POSIX -> Maybe Text -> EffectivePolicy)
-> Parser (Maybe EffectivePolicyType)
-> Parser (Maybe POSIX -> Maybe Text -> EffectivePolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe EffectivePolicyType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PolicyType")
            Parser (Maybe POSIX -> Maybe Text -> EffectivePolicy)
-> Parser (Maybe POSIX) -> Parser (Maybe Text -> EffectivePolicy)
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
"LastUpdatedTimestamp")
            Parser (Maybe Text -> EffectivePolicy)
-> Parser (Maybe Text) -> Parser EffectivePolicy
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
"PolicyContent")
      )

instance Prelude.Hashable EffectivePolicy

instance Prelude.NFData EffectivePolicy