{-# 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.DevOpsGuru.Types.NotificationChannelConfig
-- 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.DevOpsGuru.Types.NotificationChannelConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DevOpsGuru.Types.NotificationFilterConfig
import Amazonka.DevOpsGuru.Types.SnsChannelConfig
import qualified Amazonka.Prelude as Prelude

-- | Information about notification channels you have configured with DevOps
-- Guru. The one supported notification channel is Amazon Simple
-- Notification Service (Amazon SNS).
--
-- /See:/ 'newNotificationChannelConfig' smart constructor.
data NotificationChannelConfig = NotificationChannelConfig'
  { -- | The filter configurations for the Amazon SNS notification topic you use
    -- with DevOps Guru. If you do not provide filter configurations, the
    -- default configurations are to receive notifications for all message
    -- types of @High@ or @Medium@ severity.
    NotificationChannelConfig -> Maybe NotificationFilterConfig
filters :: Prelude.Maybe NotificationFilterConfig,
    -- | Information about a notification channel configured in DevOps Guru to
    -- send notifications when insights are created.
    --
    -- If you use an Amazon SNS topic in another account, you must attach a
    -- policy to it that grants DevOps Guru permission to it notifications.
    -- DevOps Guru adds the required policy on your behalf to send
    -- notifications using Amazon SNS in your account. DevOps Guru only
    -- supports standard SNS topics. For more information, see
    -- <https://docs.aws.amazon.com/devops-guru/latest/userguide/sns-required-permissions.html Permissions for cross account Amazon SNS topics>.
    --
    -- If you use an Amazon SNS topic in another account, you must attach a
    -- policy to it that grants DevOps Guru permission to it notifications.
    -- DevOps Guru adds the required policy on your behalf to send
    -- notifications using Amazon SNS in your account. For more information,
    -- see Permissions for cross account Amazon SNS topics.
    --
    -- If you use an Amazon SNS topic that is encrypted by an Amazon Web
    -- Services Key Management Service customer-managed key (CMK), then you
    -- must add permissions to the CMK. For more information, see
    -- <https://docs.aws.amazon.com/devops-guru/latest/userguide/sns-kms-permissions.html Permissions for Amazon Web Services KMS–encrypted Amazon SNS topics>.
    NotificationChannelConfig -> SnsChannelConfig
sns :: SnsChannelConfig
  }
  deriving (NotificationChannelConfig -> NotificationChannelConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NotificationChannelConfig -> NotificationChannelConfig -> Bool
$c/= :: NotificationChannelConfig -> NotificationChannelConfig -> Bool
== :: NotificationChannelConfig -> NotificationChannelConfig -> Bool
$c== :: NotificationChannelConfig -> NotificationChannelConfig -> Bool
Prelude.Eq, ReadPrec [NotificationChannelConfig]
ReadPrec NotificationChannelConfig
Int -> ReadS NotificationChannelConfig
ReadS [NotificationChannelConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NotificationChannelConfig]
$creadListPrec :: ReadPrec [NotificationChannelConfig]
readPrec :: ReadPrec NotificationChannelConfig
$creadPrec :: ReadPrec NotificationChannelConfig
readList :: ReadS [NotificationChannelConfig]
$creadList :: ReadS [NotificationChannelConfig]
readsPrec :: Int -> ReadS NotificationChannelConfig
$creadsPrec :: Int -> ReadS NotificationChannelConfig
Prelude.Read, Int -> NotificationChannelConfig -> ShowS
[NotificationChannelConfig] -> ShowS
NotificationChannelConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NotificationChannelConfig] -> ShowS
$cshowList :: [NotificationChannelConfig] -> ShowS
show :: NotificationChannelConfig -> String
$cshow :: NotificationChannelConfig -> String
showsPrec :: Int -> NotificationChannelConfig -> ShowS
$cshowsPrec :: Int -> NotificationChannelConfig -> ShowS
Prelude.Show, forall x.
Rep NotificationChannelConfig x -> NotificationChannelConfig
forall x.
NotificationChannelConfig -> Rep NotificationChannelConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep NotificationChannelConfig x -> NotificationChannelConfig
$cfrom :: forall x.
NotificationChannelConfig -> Rep NotificationChannelConfig x
Prelude.Generic)

-- |
-- Create a value of 'NotificationChannelConfig' 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:
--
-- 'filters', 'notificationChannelConfig_filters' - The filter configurations for the Amazon SNS notification topic you use
-- with DevOps Guru. If you do not provide filter configurations, the
-- default configurations are to receive notifications for all message
-- types of @High@ or @Medium@ severity.
--
-- 'sns', 'notificationChannelConfig_sns' - Information about a notification channel configured in DevOps Guru to
-- send notifications when insights are created.
--
-- If you use an Amazon SNS topic in another account, you must attach a
-- policy to it that grants DevOps Guru permission to it notifications.
-- DevOps Guru adds the required policy on your behalf to send
-- notifications using Amazon SNS in your account. DevOps Guru only
-- supports standard SNS topics. For more information, see
-- <https://docs.aws.amazon.com/devops-guru/latest/userguide/sns-required-permissions.html Permissions for cross account Amazon SNS topics>.
--
-- If you use an Amazon SNS topic in another account, you must attach a
-- policy to it that grants DevOps Guru permission to it notifications.
-- DevOps Guru adds the required policy on your behalf to send
-- notifications using Amazon SNS in your account. For more information,
-- see Permissions for cross account Amazon SNS topics.
--
-- If you use an Amazon SNS topic that is encrypted by an Amazon Web
-- Services Key Management Service customer-managed key (CMK), then you
-- must add permissions to the CMK. For more information, see
-- <https://docs.aws.amazon.com/devops-guru/latest/userguide/sns-kms-permissions.html Permissions for Amazon Web Services KMS–encrypted Amazon SNS topics>.
newNotificationChannelConfig ::
  -- | 'sns'
  SnsChannelConfig ->
  NotificationChannelConfig
newNotificationChannelConfig :: SnsChannelConfig -> NotificationChannelConfig
newNotificationChannelConfig SnsChannelConfig
pSns_ =
  NotificationChannelConfig'
    { $sel:filters:NotificationChannelConfig' :: Maybe NotificationFilterConfig
filters =
        forall a. Maybe a
Prelude.Nothing,
      $sel:sns:NotificationChannelConfig' :: SnsChannelConfig
sns = SnsChannelConfig
pSns_
    }

-- | The filter configurations for the Amazon SNS notification topic you use
-- with DevOps Guru. If you do not provide filter configurations, the
-- default configurations are to receive notifications for all message
-- types of @High@ or @Medium@ severity.
notificationChannelConfig_filters :: Lens.Lens' NotificationChannelConfig (Prelude.Maybe NotificationFilterConfig)
notificationChannelConfig_filters :: Lens' NotificationChannelConfig (Maybe NotificationFilterConfig)
notificationChannelConfig_filters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationChannelConfig' {Maybe NotificationFilterConfig
filters :: Maybe NotificationFilterConfig
$sel:filters:NotificationChannelConfig' :: NotificationChannelConfig -> Maybe NotificationFilterConfig
filters} -> Maybe NotificationFilterConfig
filters) (\s :: NotificationChannelConfig
s@NotificationChannelConfig' {} Maybe NotificationFilterConfig
a -> NotificationChannelConfig
s {$sel:filters:NotificationChannelConfig' :: Maybe NotificationFilterConfig
filters = Maybe NotificationFilterConfig
a} :: NotificationChannelConfig)

-- | Information about a notification channel configured in DevOps Guru to
-- send notifications when insights are created.
--
-- If you use an Amazon SNS topic in another account, you must attach a
-- policy to it that grants DevOps Guru permission to it notifications.
-- DevOps Guru adds the required policy on your behalf to send
-- notifications using Amazon SNS in your account. DevOps Guru only
-- supports standard SNS topics. For more information, see
-- <https://docs.aws.amazon.com/devops-guru/latest/userguide/sns-required-permissions.html Permissions for cross account Amazon SNS topics>.
--
-- If you use an Amazon SNS topic in another account, you must attach a
-- policy to it that grants DevOps Guru permission to it notifications.
-- DevOps Guru adds the required policy on your behalf to send
-- notifications using Amazon SNS in your account. For more information,
-- see Permissions for cross account Amazon SNS topics.
--
-- If you use an Amazon SNS topic that is encrypted by an Amazon Web
-- Services Key Management Service customer-managed key (CMK), then you
-- must add permissions to the CMK. For more information, see
-- <https://docs.aws.amazon.com/devops-guru/latest/userguide/sns-kms-permissions.html Permissions for Amazon Web Services KMS–encrypted Amazon SNS topics>.
notificationChannelConfig_sns :: Lens.Lens' NotificationChannelConfig SnsChannelConfig
notificationChannelConfig_sns :: Lens' NotificationChannelConfig SnsChannelConfig
notificationChannelConfig_sns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationChannelConfig' {SnsChannelConfig
sns :: SnsChannelConfig
$sel:sns:NotificationChannelConfig' :: NotificationChannelConfig -> SnsChannelConfig
sns} -> SnsChannelConfig
sns) (\s :: NotificationChannelConfig
s@NotificationChannelConfig' {} SnsChannelConfig
a -> NotificationChannelConfig
s {$sel:sns:NotificationChannelConfig' :: SnsChannelConfig
sns = SnsChannelConfig
a} :: NotificationChannelConfig)

instance Data.FromJSON NotificationChannelConfig where
  parseJSON :: Value -> Parser NotificationChannelConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"NotificationChannelConfig"
      ( \Object
x ->
          Maybe NotificationFilterConfig
-> SnsChannelConfig -> NotificationChannelConfig
NotificationChannelConfig'
            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
"Filters")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Sns")
      )

instance Prelude.Hashable NotificationChannelConfig where
  hashWithSalt :: Int -> NotificationChannelConfig -> Int
hashWithSalt Int
_salt NotificationChannelConfig' {Maybe NotificationFilterConfig
SnsChannelConfig
sns :: SnsChannelConfig
filters :: Maybe NotificationFilterConfig
$sel:sns:NotificationChannelConfig' :: NotificationChannelConfig -> SnsChannelConfig
$sel:filters:NotificationChannelConfig' :: NotificationChannelConfig -> Maybe NotificationFilterConfig
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe NotificationFilterConfig
filters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SnsChannelConfig
sns

instance Prelude.NFData NotificationChannelConfig where
  rnf :: NotificationChannelConfig -> ()
rnf NotificationChannelConfig' {Maybe NotificationFilterConfig
SnsChannelConfig
sns :: SnsChannelConfig
filters :: Maybe NotificationFilterConfig
$sel:sns:NotificationChannelConfig' :: NotificationChannelConfig -> SnsChannelConfig
$sel:filters:NotificationChannelConfig' :: NotificationChannelConfig -> Maybe NotificationFilterConfig
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe NotificationFilterConfig
filters seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SnsChannelConfig
sns

instance Data.ToJSON NotificationChannelConfig where
  toJSON :: NotificationChannelConfig -> Value
toJSON NotificationChannelConfig' {Maybe NotificationFilterConfig
SnsChannelConfig
sns :: SnsChannelConfig
filters :: Maybe NotificationFilterConfig
$sel:sns:NotificationChannelConfig' :: NotificationChannelConfig -> SnsChannelConfig
$sel:filters:NotificationChannelConfig' :: NotificationChannelConfig -> Maybe NotificationFilterConfig
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Filters" 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 NotificationFilterConfig
filters,
            forall a. a -> Maybe a
Prelude.Just (Key
"Sns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SnsChannelConfig
sns)
          ]
      )