{-# 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-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.Policy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Policy -> Policy -> Bool)
-> (Policy -> Policy -> Bool) -> Eq Policy
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]
(Int -> ReadS Policy)
-> ReadS [Policy]
-> ReadPrec Policy
-> ReadPrec [Policy]
-> Read 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
(Int -> Policy -> ShowS)
-> (Policy -> String) -> ([Policy] -> ShowS) -> Show Policy
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. Policy -> Rep Policy x)
-> (forall x. Rep Policy x -> Policy) -> Generic Policy
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' :: Maybe Text -> Maybe PolicySummary -> Policy
Policy'
    { $sel:content:Policy' :: Maybe Text
content = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policySummary:Policy' :: Maybe PolicySummary
policySummary = Maybe PolicySummary
forall a. Maybe a
Prelude.Nothing
    }

-- | The text content of the policy.
policy_content :: Lens.Lens' Policy (Prelude.Maybe Prelude.Text)
policy_content :: (Maybe Text -> f (Maybe Text)) -> Policy -> f Policy
policy_content = (Policy -> Maybe Text)
-> (Policy -> Maybe Text -> Policy)
-> Lens Policy Policy (Maybe Text) (Maybe Text)
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 :: (Maybe PolicySummary -> f (Maybe PolicySummary))
-> Policy -> f Policy
policy_policySummary = (Policy -> Maybe PolicySummary)
-> (Policy -> Maybe PolicySummary -> Policy)
-> Lens Policy Policy (Maybe PolicySummary) (Maybe 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 Core.FromJSON Policy where
  parseJSON :: Value -> Parser Policy
parseJSON =
    String -> (Object -> Parser Policy) -> Value -> Parser Policy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Policy"
      ( \Object
x ->
          Maybe Text -> Maybe PolicySummary -> Policy
Policy'
            (Maybe Text -> Maybe PolicySummary -> Policy)
-> Parser (Maybe Text) -> Parser (Maybe PolicySummary -> Policy)
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
"Content")
            Parser (Maybe PolicySummary -> Policy)
-> Parser (Maybe PolicySummary) -> Parser Policy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe PolicySummary)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PolicySummary")
      )

instance Prelude.Hashable Policy

instance Prelude.NFData Policy