{-# 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.AccessAnalyzer.Types.SnsTopicConfiguration
-- 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.AccessAnalyzer.Types.SnsTopicConfiguration where

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

-- | The proposed access control configuration for an Amazon SNS topic. You
-- can propose a configuration for a new Amazon SNS topic or an existing
-- Amazon SNS topic that you own by specifying the policy. If the
-- configuration is for an existing Amazon SNS topic and you do not specify
-- the Amazon SNS policy, then the access preview uses the existing Amazon
-- SNS policy for the topic. If the access preview is for a new resource
-- and you do not specify the policy, then the access preview assumes an
-- Amazon SNS topic without a policy. To propose deletion of an existing
-- Amazon SNS topic policy, you can specify an empty string for the Amazon
-- SNS policy. For more information, see
-- <https://docs.aws.amazon.com/sns/latest/api/API_Topic.html Topic>.
--
-- /See:/ 'newSnsTopicConfiguration' smart constructor.
data SnsTopicConfiguration = SnsTopicConfiguration'
  { -- | The JSON policy text that defines who can access an Amazon SNS topic.
    -- For more information, see
    -- <https://docs.aws.amazon.com/sns/latest/dg/sns-access-policy-use-cases.html Example cases for Amazon SNS access control>
    -- in the /Amazon SNS Developer Guide/.
    SnsTopicConfiguration -> Maybe Text
topicPolicy :: Prelude.Maybe Prelude.Text
  }
  deriving (SnsTopicConfiguration -> SnsTopicConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SnsTopicConfiguration -> SnsTopicConfiguration -> Bool
$c/= :: SnsTopicConfiguration -> SnsTopicConfiguration -> Bool
== :: SnsTopicConfiguration -> SnsTopicConfiguration -> Bool
$c== :: SnsTopicConfiguration -> SnsTopicConfiguration -> Bool
Prelude.Eq, ReadPrec [SnsTopicConfiguration]
ReadPrec SnsTopicConfiguration
Int -> ReadS SnsTopicConfiguration
ReadS [SnsTopicConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SnsTopicConfiguration]
$creadListPrec :: ReadPrec [SnsTopicConfiguration]
readPrec :: ReadPrec SnsTopicConfiguration
$creadPrec :: ReadPrec SnsTopicConfiguration
readList :: ReadS [SnsTopicConfiguration]
$creadList :: ReadS [SnsTopicConfiguration]
readsPrec :: Int -> ReadS SnsTopicConfiguration
$creadsPrec :: Int -> ReadS SnsTopicConfiguration
Prelude.Read, Int -> SnsTopicConfiguration -> ShowS
[SnsTopicConfiguration] -> ShowS
SnsTopicConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SnsTopicConfiguration] -> ShowS
$cshowList :: [SnsTopicConfiguration] -> ShowS
show :: SnsTopicConfiguration -> String
$cshow :: SnsTopicConfiguration -> String
showsPrec :: Int -> SnsTopicConfiguration -> ShowS
$cshowsPrec :: Int -> SnsTopicConfiguration -> ShowS
Prelude.Show, forall x. Rep SnsTopicConfiguration x -> SnsTopicConfiguration
forall x. SnsTopicConfiguration -> Rep SnsTopicConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SnsTopicConfiguration x -> SnsTopicConfiguration
$cfrom :: forall x. SnsTopicConfiguration -> Rep SnsTopicConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'SnsTopicConfiguration' 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:
--
-- 'topicPolicy', 'snsTopicConfiguration_topicPolicy' - The JSON policy text that defines who can access an Amazon SNS topic.
-- For more information, see
-- <https://docs.aws.amazon.com/sns/latest/dg/sns-access-policy-use-cases.html Example cases for Amazon SNS access control>
-- in the /Amazon SNS Developer Guide/.
newSnsTopicConfiguration ::
  SnsTopicConfiguration
newSnsTopicConfiguration :: SnsTopicConfiguration
newSnsTopicConfiguration =
  SnsTopicConfiguration'
    { $sel:topicPolicy:SnsTopicConfiguration' :: Maybe Text
topicPolicy =
        forall a. Maybe a
Prelude.Nothing
    }

-- | The JSON policy text that defines who can access an Amazon SNS topic.
-- For more information, see
-- <https://docs.aws.amazon.com/sns/latest/dg/sns-access-policy-use-cases.html Example cases for Amazon SNS access control>
-- in the /Amazon SNS Developer Guide/.
snsTopicConfiguration_topicPolicy :: Lens.Lens' SnsTopicConfiguration (Prelude.Maybe Prelude.Text)
snsTopicConfiguration_topicPolicy :: Lens' SnsTopicConfiguration (Maybe Text)
snsTopicConfiguration_topicPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SnsTopicConfiguration' {Maybe Text
topicPolicy :: Maybe Text
$sel:topicPolicy:SnsTopicConfiguration' :: SnsTopicConfiguration -> Maybe Text
topicPolicy} -> Maybe Text
topicPolicy) (\s :: SnsTopicConfiguration
s@SnsTopicConfiguration' {} Maybe Text
a -> SnsTopicConfiguration
s {$sel:topicPolicy:SnsTopicConfiguration' :: Maybe Text
topicPolicy = Maybe Text
a} :: SnsTopicConfiguration)

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

instance Prelude.Hashable SnsTopicConfiguration where
  hashWithSalt :: Int -> SnsTopicConfiguration -> Int
hashWithSalt Int
_salt SnsTopicConfiguration' {Maybe Text
topicPolicy :: Maybe Text
$sel:topicPolicy:SnsTopicConfiguration' :: SnsTopicConfiguration -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
topicPolicy

instance Prelude.NFData SnsTopicConfiguration where
  rnf :: SnsTopicConfiguration -> ()
rnf SnsTopicConfiguration' {Maybe Text
topicPolicy :: Maybe Text
$sel:topicPolicy:SnsTopicConfiguration' :: SnsTopicConfiguration -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
topicPolicy

instance Data.ToJSON SnsTopicConfiguration where
  toJSON :: SnsTopicConfiguration -> Value
toJSON SnsTopicConfiguration' {Maybe Text
topicPolicy :: Maybe Text
$sel:topicPolicy:SnsTopicConfiguration' :: SnsTopicConfiguration -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"topicPolicy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
topicPolicy]
      )