{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.AddNotificationChannel
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds a notification channel to DevOps Guru. A notification channel is
-- used to notify you about important DevOps Guru events, such as when an
-- insight is generated.
--
-- 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>.
module Amazonka.DevOpsGuru.AddNotificationChannel
  ( -- * Creating a Request
    AddNotificationChannel (..),
    newAddNotificationChannel,

    -- * Request Lenses
    addNotificationChannel_config,

    -- * Destructuring the Response
    AddNotificationChannelResponse (..),
    newAddNotificationChannelResponse,

    -- * Response Lenses
    addNotificationChannelResponse_httpStatus,
    addNotificationChannelResponse_id,
  )
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
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAddNotificationChannel' smart constructor.
data AddNotificationChannel = AddNotificationChannel'
  { -- | A @NotificationChannelConfig@ object that specifies what type of
    -- notification channel to add. The one supported notification channel is
    -- Amazon Simple Notification Service (Amazon SNS).
    AddNotificationChannel -> NotificationChannelConfig
config :: NotificationChannelConfig
  }
  deriving (AddNotificationChannel -> AddNotificationChannel -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddNotificationChannel -> AddNotificationChannel -> Bool
$c/= :: AddNotificationChannel -> AddNotificationChannel -> Bool
== :: AddNotificationChannel -> AddNotificationChannel -> Bool
$c== :: AddNotificationChannel -> AddNotificationChannel -> Bool
Prelude.Eq, ReadPrec [AddNotificationChannel]
ReadPrec AddNotificationChannel
Int -> ReadS AddNotificationChannel
ReadS [AddNotificationChannel]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddNotificationChannel]
$creadListPrec :: ReadPrec [AddNotificationChannel]
readPrec :: ReadPrec AddNotificationChannel
$creadPrec :: ReadPrec AddNotificationChannel
readList :: ReadS [AddNotificationChannel]
$creadList :: ReadS [AddNotificationChannel]
readsPrec :: Int -> ReadS AddNotificationChannel
$creadsPrec :: Int -> ReadS AddNotificationChannel
Prelude.Read, Int -> AddNotificationChannel -> ShowS
[AddNotificationChannel] -> ShowS
AddNotificationChannel -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddNotificationChannel] -> ShowS
$cshowList :: [AddNotificationChannel] -> ShowS
show :: AddNotificationChannel -> String
$cshow :: AddNotificationChannel -> String
showsPrec :: Int -> AddNotificationChannel -> ShowS
$cshowsPrec :: Int -> AddNotificationChannel -> ShowS
Prelude.Show, forall x. Rep AddNotificationChannel x -> AddNotificationChannel
forall x. AddNotificationChannel -> Rep AddNotificationChannel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddNotificationChannel x -> AddNotificationChannel
$cfrom :: forall x. AddNotificationChannel -> Rep AddNotificationChannel x
Prelude.Generic)

-- |
-- Create a value of 'AddNotificationChannel' 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:
--
-- 'config', 'addNotificationChannel_config' - A @NotificationChannelConfig@ object that specifies what type of
-- notification channel to add. The one supported notification channel is
-- Amazon Simple Notification Service (Amazon SNS).
newAddNotificationChannel ::
  -- | 'config'
  NotificationChannelConfig ->
  AddNotificationChannel
newAddNotificationChannel :: NotificationChannelConfig -> AddNotificationChannel
newAddNotificationChannel NotificationChannelConfig
pConfig_ =
  AddNotificationChannel' {$sel:config:AddNotificationChannel' :: NotificationChannelConfig
config = NotificationChannelConfig
pConfig_}

-- | A @NotificationChannelConfig@ object that specifies what type of
-- notification channel to add. The one supported notification channel is
-- Amazon Simple Notification Service (Amazon SNS).
addNotificationChannel_config :: Lens.Lens' AddNotificationChannel NotificationChannelConfig
addNotificationChannel_config :: Lens' AddNotificationChannel NotificationChannelConfig
addNotificationChannel_config = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddNotificationChannel' {NotificationChannelConfig
config :: NotificationChannelConfig
$sel:config:AddNotificationChannel' :: AddNotificationChannel -> NotificationChannelConfig
config} -> NotificationChannelConfig
config) (\s :: AddNotificationChannel
s@AddNotificationChannel' {} NotificationChannelConfig
a -> AddNotificationChannel
s {$sel:config:AddNotificationChannel' :: NotificationChannelConfig
config = NotificationChannelConfig
a} :: AddNotificationChannel)

instance Core.AWSRequest AddNotificationChannel where
  type
    AWSResponse AddNotificationChannel =
      AddNotificationChannelResponse
  request :: (Service -> Service)
-> AddNotificationChannel -> Request AddNotificationChannel
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AddNotificationChannel
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddNotificationChannel)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> AddNotificationChannelResponse
AddNotificationChannelResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"Id")
      )

instance Prelude.Hashable AddNotificationChannel where
  hashWithSalt :: Int -> AddNotificationChannel -> Int
hashWithSalt Int
_salt AddNotificationChannel' {NotificationChannelConfig
config :: NotificationChannelConfig
$sel:config:AddNotificationChannel' :: AddNotificationChannel -> NotificationChannelConfig
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NotificationChannelConfig
config

instance Prelude.NFData AddNotificationChannel where
  rnf :: AddNotificationChannel -> ()
rnf AddNotificationChannel' {NotificationChannelConfig
config :: NotificationChannelConfig
$sel:config:AddNotificationChannel' :: AddNotificationChannel -> NotificationChannelConfig
..} = forall a. NFData a => a -> ()
Prelude.rnf NotificationChannelConfig
config

instance Data.ToHeaders AddNotificationChannel where
  toHeaders :: AddNotificationChannel -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON AddNotificationChannel where
  toJSON :: AddNotificationChannel -> Value
toJSON AddNotificationChannel' {NotificationChannelConfig
config :: NotificationChannelConfig
$sel:config:AddNotificationChannel' :: AddNotificationChannel -> NotificationChannelConfig
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Config" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NotificationChannelConfig
config)]
      )

instance Data.ToPath AddNotificationChannel where
  toPath :: AddNotificationChannel -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/channels"

instance Data.ToQuery AddNotificationChannel where
  toQuery :: AddNotificationChannel -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newAddNotificationChannelResponse' smart constructor.
data AddNotificationChannelResponse = AddNotificationChannelResponse'
  { -- | The response's http status code.
    AddNotificationChannelResponse -> Int
httpStatus :: Prelude.Int,
    -- | The ID of the added notification channel.
    AddNotificationChannelResponse -> Text
id :: Prelude.Text
  }
  deriving (AddNotificationChannelResponse
-> AddNotificationChannelResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddNotificationChannelResponse
-> AddNotificationChannelResponse -> Bool
$c/= :: AddNotificationChannelResponse
-> AddNotificationChannelResponse -> Bool
== :: AddNotificationChannelResponse
-> AddNotificationChannelResponse -> Bool
$c== :: AddNotificationChannelResponse
-> AddNotificationChannelResponse -> Bool
Prelude.Eq, ReadPrec [AddNotificationChannelResponse]
ReadPrec AddNotificationChannelResponse
Int -> ReadS AddNotificationChannelResponse
ReadS [AddNotificationChannelResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddNotificationChannelResponse]
$creadListPrec :: ReadPrec [AddNotificationChannelResponse]
readPrec :: ReadPrec AddNotificationChannelResponse
$creadPrec :: ReadPrec AddNotificationChannelResponse
readList :: ReadS [AddNotificationChannelResponse]
$creadList :: ReadS [AddNotificationChannelResponse]
readsPrec :: Int -> ReadS AddNotificationChannelResponse
$creadsPrec :: Int -> ReadS AddNotificationChannelResponse
Prelude.Read, Int -> AddNotificationChannelResponse -> ShowS
[AddNotificationChannelResponse] -> ShowS
AddNotificationChannelResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddNotificationChannelResponse] -> ShowS
$cshowList :: [AddNotificationChannelResponse] -> ShowS
show :: AddNotificationChannelResponse -> String
$cshow :: AddNotificationChannelResponse -> String
showsPrec :: Int -> AddNotificationChannelResponse -> ShowS
$cshowsPrec :: Int -> AddNotificationChannelResponse -> ShowS
Prelude.Show, forall x.
Rep AddNotificationChannelResponse x
-> AddNotificationChannelResponse
forall x.
AddNotificationChannelResponse
-> Rep AddNotificationChannelResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AddNotificationChannelResponse x
-> AddNotificationChannelResponse
$cfrom :: forall x.
AddNotificationChannelResponse
-> Rep AddNotificationChannelResponse x
Prelude.Generic)

-- |
-- Create a value of 'AddNotificationChannelResponse' 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:
--
-- 'httpStatus', 'addNotificationChannelResponse_httpStatus' - The response's http status code.
--
-- 'id', 'addNotificationChannelResponse_id' - The ID of the added notification channel.
newAddNotificationChannelResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'id'
  Prelude.Text ->
  AddNotificationChannelResponse
newAddNotificationChannelResponse :: Int -> Text -> AddNotificationChannelResponse
newAddNotificationChannelResponse Int
pHttpStatus_ Text
pId_ =
  AddNotificationChannelResponse'
    { $sel:httpStatus:AddNotificationChannelResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:id:AddNotificationChannelResponse' :: Text
id = Text
pId_
    }

-- | The response's http status code.
addNotificationChannelResponse_httpStatus :: Lens.Lens' AddNotificationChannelResponse Prelude.Int
addNotificationChannelResponse_httpStatus :: Lens' AddNotificationChannelResponse Int
addNotificationChannelResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddNotificationChannelResponse' {Int
httpStatus :: Int
$sel:httpStatus:AddNotificationChannelResponse' :: AddNotificationChannelResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AddNotificationChannelResponse
s@AddNotificationChannelResponse' {} Int
a -> AddNotificationChannelResponse
s {$sel:httpStatus:AddNotificationChannelResponse' :: Int
httpStatus = Int
a} :: AddNotificationChannelResponse)

-- | The ID of the added notification channel.
addNotificationChannelResponse_id :: Lens.Lens' AddNotificationChannelResponse Prelude.Text
addNotificationChannelResponse_id :: Lens' AddNotificationChannelResponse Text
addNotificationChannelResponse_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddNotificationChannelResponse' {Text
id :: Text
$sel:id:AddNotificationChannelResponse' :: AddNotificationChannelResponse -> Text
id} -> Text
id) (\s :: AddNotificationChannelResponse
s@AddNotificationChannelResponse' {} Text
a -> AddNotificationChannelResponse
s {$sel:id:AddNotificationChannelResponse' :: Text
id = Text
a} :: AddNotificationChannelResponse)

instance
  Prelude.NFData
    AddNotificationChannelResponse
  where
  rnf :: AddNotificationChannelResponse -> ()
rnf AddNotificationChannelResponse' {Int
Text
id :: Text
httpStatus :: Int
$sel:id:AddNotificationChannelResponse' :: AddNotificationChannelResponse -> Text
$sel:httpStatus:AddNotificationChannelResponse' :: AddNotificationChannelResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id