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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The policy that has the effect on the authorization results.
--
-- /See:/ 'newEffectivePolicy' smart constructor.
data EffectivePolicy = EffectivePolicy'
  { -- | The policy name.
    EffectivePolicy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text,
    -- | The IAM policy document.
    EffectivePolicy -> Maybe Text
policyDocument :: Prelude.Maybe Prelude.Text,
    -- | The policy ARN.
    EffectivePolicy -> Maybe Text
policyArn :: 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:
--
-- 'policyName', 'effectivePolicy_policyName' - The policy name.
--
-- 'policyDocument', 'effectivePolicy_policyDocument' - The IAM policy document.
--
-- 'policyArn', 'effectivePolicy_policyArn' - The policy ARN.
newEffectivePolicy ::
  EffectivePolicy
newEffectivePolicy :: EffectivePolicy
newEffectivePolicy =
  EffectivePolicy' :: Maybe Text -> Maybe Text -> Maybe Text -> EffectivePolicy
EffectivePolicy'
    { $sel:policyName:EffectivePolicy' :: Maybe Text
policyName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyDocument:EffectivePolicy' :: Maybe Text
policyDocument = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyArn:EffectivePolicy' :: Maybe Text
policyArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The policy name.
effectivePolicy_policyName :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.Text)
effectivePolicy_policyName :: (Maybe Text -> f (Maybe Text))
-> EffectivePolicy -> f EffectivePolicy
effectivePolicy_policyName = (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
policyName :: Maybe Text
$sel:policyName:EffectivePolicy' :: EffectivePolicy -> Maybe Text
policyName} -> Maybe Text
policyName) (\s :: EffectivePolicy
s@EffectivePolicy' {} Maybe Text
a -> EffectivePolicy
s {$sel:policyName:EffectivePolicy' :: Maybe Text
policyName = Maybe Text
a} :: EffectivePolicy)

-- | The IAM policy document.
effectivePolicy_policyDocument :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.Text)
effectivePolicy_policyDocument :: (Maybe Text -> f (Maybe Text))
-> EffectivePolicy -> f EffectivePolicy
effectivePolicy_policyDocument = (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
policyDocument :: Maybe Text
$sel:policyDocument:EffectivePolicy' :: EffectivePolicy -> Maybe Text
policyDocument} -> Maybe Text
policyDocument) (\s :: EffectivePolicy
s@EffectivePolicy' {} Maybe Text
a -> EffectivePolicy
s {$sel:policyDocument:EffectivePolicy' :: Maybe Text
policyDocument = Maybe Text
a} :: EffectivePolicy)

-- | The policy ARN.
effectivePolicy_policyArn :: Lens.Lens' EffectivePolicy (Prelude.Maybe Prelude.Text)
effectivePolicy_policyArn :: (Maybe Text -> f (Maybe Text))
-> EffectivePolicy -> f EffectivePolicy
effectivePolicy_policyArn = (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
policyArn :: Maybe Text
$sel:policyArn:EffectivePolicy' :: EffectivePolicy -> Maybe Text
policyArn} -> Maybe Text
policyArn) (\s :: EffectivePolicy
s@EffectivePolicy' {} Maybe Text
a -> EffectivePolicy
s {$sel:policyArn:EffectivePolicy' :: Maybe Text
policyArn = 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 Text -> Maybe Text -> EffectivePolicy
EffectivePolicy'
            (Maybe Text -> Maybe Text -> Maybe Text -> EffectivePolicy)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> 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
"policyName")
            Parser (Maybe Text -> Maybe Text -> EffectivePolicy)
-> Parser (Maybe Text) -> Parser (Maybe Text -> 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
"policyDocument")
            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
"policyArn")
      )

instance Prelude.Hashable EffectivePolicy

instance Prelude.NFData EffectivePolicy