{-# 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.Policy
-- 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.Policy 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.PolicySummary
import qualified Amazonka.Prelude as Prelude

-- | Contains rules to be applied to the affected accounts. Policies can be
-- attached directly to accounts, or to roots and OUs to affect all
-- accounts in those hierarchies.
--
-- /See:/ 'newPolicy' smart constructor.
data Policy = Policy'
  { -- | The text content of the policy.
    Policy -> Maybe Text
content :: Prelude.Maybe Prelude.Text,
    -- | A structure that contains additional details about the policy.
    Policy -> Maybe PolicySummary
policySummary :: Prelude.Maybe PolicySummary
  }
  deriving (Policy -> Policy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Policy -> Policy -> Bool
$c/= :: Policy -> Policy -> Bool
== :: Policy -> Policy -> Bool
$c== :: Policy -> Policy -> Bool
Prelude.Eq, ReadPrec [Policy]
ReadPrec Policy
Int -> ReadS Policy
ReadS [Policy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Policy]
$creadListPrec :: ReadPrec [Policy]
readPrec :: ReadPrec Policy
$creadPrec :: ReadPrec Policy
readList :: ReadS [Policy]
$creadList :: ReadS [Policy]
readsPrec :: Int -> ReadS Policy
$creadsPrec :: Int -> ReadS Policy
Prelude.Read, Int -> Policy -> ShowS
[Policy] -> ShowS
Policy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Policy] -> ShowS
$cshowList :: [Policy] -> ShowS
show :: Policy -> String
$cshow :: Policy -> String
showsPrec :: Int -> Policy -> ShowS
$cshowsPrec :: Int -> Policy -> ShowS
Prelude.Show, forall x. Rep Policy x -> Policy
forall x. Policy -> Rep Policy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Policy x -> Policy
$cfrom :: forall x. Policy -> Rep Policy x
Prelude.Generic)

-- |
-- Create a value of 'Policy' 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:
--
-- 'content', 'policy_content' - The text content of the policy.
--
-- 'policySummary', 'policy_policySummary' - A structure that contains additional details about the policy.
newPolicy ::
  Policy
newPolicy :: Policy
newPolicy =
  Policy'
    { $sel:content:Policy' :: Maybe Text
content = forall a. Maybe a
Prelude.Nothing,
      $sel:policySummary:Policy' :: Maybe PolicySummary
policySummary = forall a. Maybe a
Prelude.Nothing
    }

-- | The text content of the policy.
policy_content :: Lens.Lens' Policy (Prelude.Maybe Prelude.Text)
policy_content :: Lens' Policy (Maybe Text)
policy_content = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Policy' {Maybe Text
content :: Maybe Text
$sel:content:Policy' :: Policy -> Maybe Text
content} -> Maybe Text
content) (\s :: Policy
s@Policy' {} Maybe Text
a -> Policy
s {$sel:content:Policy' :: Maybe Text
content = Maybe Text
a} :: Policy)

-- | A structure that contains additional details about the policy.
policy_policySummary :: Lens.Lens' Policy (Prelude.Maybe PolicySummary)
policy_policySummary :: Lens' Policy (Maybe PolicySummary)
policy_policySummary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Policy' {Maybe PolicySummary
policySummary :: Maybe PolicySummary
$sel:policySummary:Policy' :: Policy -> Maybe PolicySummary
policySummary} -> Maybe PolicySummary
policySummary) (\s :: Policy
s@Policy' {} Maybe PolicySummary
a -> Policy
s {$sel:policySummary:Policy' :: Maybe PolicySummary
policySummary = Maybe PolicySummary
a} :: Policy)

instance Data.FromJSON Policy where
  parseJSON :: Value -> Parser Policy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Policy"
      ( \Object
x ->
          Maybe Text -> Maybe PolicySummary -> Policy
Policy'
            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
"Content")
            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
"PolicySummary")
      )

instance Prelude.Hashable Policy where
  hashWithSalt :: Int -> Policy -> Int
hashWithSalt Int
_salt Policy' {Maybe Text
Maybe PolicySummary
policySummary :: Maybe PolicySummary
content :: Maybe Text
$sel:policySummary:Policy' :: Policy -> Maybe PolicySummary
$sel:content:Policy' :: Policy -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
content
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PolicySummary
policySummary

instance Prelude.NFData Policy where
  rnf :: Policy -> ()
rnf Policy' {Maybe Text
Maybe PolicySummary
policySummary :: Maybe PolicySummary
content :: Maybe Text
$sel:policySummary:Policy' :: Policy -> Maybe PolicySummary
$sel:content:Policy' :: Policy -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
content
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PolicySummary
policySummary