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

import qualified Amazonka.Core as Core
import Amazonka.DevOpsGuru.Types.SnsChannelConfig
import qualified Amazonka.Lens as Lens
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'
  { -- | 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. 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 that is encrypted by an AWS 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 AWS KMS–encrypted Amazon SNS topics>.
    NotificationChannelConfig -> SnsChannelConfig
sns :: SnsChannelConfig
  }
  deriving (NotificationChannelConfig -> NotificationChannelConfig -> Bool
(NotificationChannelConfig -> NotificationChannelConfig -> Bool)
-> (NotificationChannelConfig -> NotificationChannelConfig -> Bool)
-> Eq NotificationChannelConfig
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]
(Int -> ReadS NotificationChannelConfig)
-> ReadS [NotificationChannelConfig]
-> ReadPrec NotificationChannelConfig
-> ReadPrec [NotificationChannelConfig]
-> Read 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
(Int -> NotificationChannelConfig -> ShowS)
-> (NotificationChannelConfig -> String)
-> ([NotificationChannelConfig] -> ShowS)
-> Show NotificationChannelConfig
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.
 NotificationChannelConfig -> Rep NotificationChannelConfig x)
-> (forall x.
    Rep NotificationChannelConfig x -> NotificationChannelConfig)
-> Generic NotificationChannelConfig
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:
--
-- '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. 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 that is encrypted by an AWS 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 AWS KMS–encrypted Amazon SNS topics>.
newNotificationChannelConfig ::
  -- | 'sns'
  SnsChannelConfig ->
  NotificationChannelConfig
newNotificationChannelConfig :: SnsChannelConfig -> NotificationChannelConfig
newNotificationChannelConfig SnsChannelConfig
pSns_ =
  NotificationChannelConfig' :: SnsChannelConfig -> NotificationChannelConfig
NotificationChannelConfig' {$sel:sns:NotificationChannelConfig' :: SnsChannelConfig
sns = SnsChannelConfig
pSns_}

-- | 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. 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 that is encrypted by an AWS 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 AWS KMS–encrypted Amazon SNS topics>.
notificationChannelConfig_sns :: Lens.Lens' NotificationChannelConfig SnsChannelConfig
notificationChannelConfig_sns :: (SnsChannelConfig -> f SnsChannelConfig)
-> NotificationChannelConfig -> f NotificationChannelConfig
notificationChannelConfig_sns = (NotificationChannelConfig -> SnsChannelConfig)
-> (NotificationChannelConfig
    -> SnsChannelConfig -> NotificationChannelConfig)
-> Lens
     NotificationChannelConfig
     NotificationChannelConfig
     SnsChannelConfig
     SnsChannelConfig
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 Core.FromJSON NotificationChannelConfig where
  parseJSON :: Value -> Parser NotificationChannelConfig
parseJSON =
    String
-> (Object -> Parser NotificationChannelConfig)
-> Value
-> Parser NotificationChannelConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NotificationChannelConfig"
      ( \Object
x ->
          SnsChannelConfig -> NotificationChannelConfig
NotificationChannelConfig'
            (SnsChannelConfig -> NotificationChannelConfig)
-> Parser SnsChannelConfig -> Parser NotificationChannelConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser SnsChannelConfig
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Sns")
      )

instance Prelude.Hashable NotificationChannelConfig

instance Prelude.NFData NotificationChannelConfig

instance Core.ToJSON NotificationChannelConfig where
  toJSON :: NotificationChannelConfig -> Value
toJSON NotificationChannelConfig' {SnsChannelConfig
sns :: SnsChannelConfig
$sel:sns:NotificationChannelConfig' :: NotificationChannelConfig -> SnsChannelConfig
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Sns" Text -> SnsChannelConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SnsChannelConfig
sns)]
      )