{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Organizations.Types.EffectivePolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 time of the last update to this policy.
    EffectivePolicy -> Maybe POSIX
lastUpdatedTimestamp :: Prelude.Maybe Data.POSIX,
    -- | The text content of the policy.
    EffectivePolicy -> Maybe Text
policyContent :: Prelude.Maybe Prelude.Text,
    -- | The policy type.
    EffectivePolicy -> Maybe EffectivePolicyType
policyType :: Prelude.Maybe EffectivePolicyType,
    -- | The account ID of the policy target.
    EffectivePolicy -> Maybe Text
targetId :: Prelude.Maybe Prelude.Text
  }
  deriving (EffectivePolicy -> EffectivePolicy -> Bool
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]
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
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. 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:
--
-- 'lastUpdatedTimestamp', 'effectivePolicy_lastUpdatedTimestamp' - The time of the last update to this policy.
--
-- 'policyContent', 'effectivePolicy_policyContent' - The text content of the policy.
--
-- 'policyType', 'effectivePolicy_policyType' - The policy type.
--
-- 'targetId', 'effectivePolicy_targetId' - The account ID of the policy target.
newEffectivePolicy ::
  EffectivePolicy
newEffectivePolicy :: EffectivePolicy
newEffectivePolicy =
  EffectivePolicy'
    { $sel:lastUpdatedTimestamp:EffectivePolicy' :: Maybe POSIX
lastUpdatedTimestamp =
        forall a. Maybe a
Prelude.Nothing,
      $sel:policyContent:EffectivePolicy' :: Maybe Text
policyContent = forall a. Maybe a
Prelude.Nothing,
      $sel:policyType:EffectivePolicy' :: Maybe EffectivePolicyType
policyType = forall a. Maybe a
Prelude.Nothing,
      $sel:targetId:EffectivePolicy' :: Maybe Text
targetId = forall a. Maybe a
Prelude.Nothing
    }

-- | The time of the last update to this policy.
effectivePolicy_lastUpdatedTimestamp :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.UTCTime)
effectivePolicy_lastUpdatedTimestamp :: Lens' EffectivePolicy (Maybe UTCTime)
effectivePolicy_lastUpdatedTimestamp = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The text content of the policy.
effectivePolicy_policyContent :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.Text)
effectivePolicy_policyContent :: Lens' EffectivePolicy (Maybe Text)
effectivePolicy_policyContent = 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)

-- | The policy type.
effectivePolicy_policyType :: Lens.Lens' EffectivePolicy (Prelude.Maybe EffectivePolicyType)
effectivePolicy_policyType :: Lens' EffectivePolicy (Maybe EffectivePolicyType)
effectivePolicy_policyType = 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 account ID of the policy target.
effectivePolicy_targetId :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.Text)
effectivePolicy_targetId :: Lens' EffectivePolicy (Maybe Text)
effectivePolicy_targetId = 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)

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

instance Prelude.Hashable EffectivePolicy where
  hashWithSalt :: Int -> EffectivePolicy -> Int
hashWithSalt Int
_salt EffectivePolicy' {Maybe Text
Maybe POSIX
Maybe EffectivePolicyType
targetId :: Maybe Text
policyType :: Maybe EffectivePolicyType
policyContent :: Maybe Text
lastUpdatedTimestamp :: Maybe POSIX
$sel:targetId:EffectivePolicy' :: EffectivePolicy -> Maybe Text
$sel:policyType:EffectivePolicy' :: EffectivePolicy -> Maybe EffectivePolicyType
$sel:policyContent:EffectivePolicy' :: EffectivePolicy -> Maybe Text
$sel:lastUpdatedTimestamp:EffectivePolicy' :: EffectivePolicy -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
lastUpdatedTimestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyContent
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EffectivePolicyType
policyType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
targetId

instance Prelude.NFData EffectivePolicy where
  rnf :: EffectivePolicy -> ()
rnf EffectivePolicy' {Maybe Text
Maybe POSIX
Maybe EffectivePolicyType
targetId :: Maybe Text
policyType :: Maybe EffectivePolicyType
policyContent :: Maybe Text
lastUpdatedTimestamp :: Maybe POSIX
$sel:targetId:EffectivePolicy' :: EffectivePolicy -> Maybe Text
$sel:policyType:EffectivePolicy' :: EffectivePolicy -> Maybe EffectivePolicyType
$sel:policyContent:EffectivePolicy' :: EffectivePolicy -> Maybe Text
$sel:lastUpdatedTimestamp:EffectivePolicy' :: EffectivePolicy -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
lastUpdatedTimestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyContent
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EffectivePolicyType
policyType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
targetId