{-# 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-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)
--
-- 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. 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>.
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 Amazonka.DevOpsGuru.Types
import qualified Amazonka.Lens as Lens
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
(AddNotificationChannel -> AddNotificationChannel -> Bool)
-> (AddNotificationChannel -> AddNotificationChannel -> Bool)
-> Eq AddNotificationChannel
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]
(Int -> ReadS AddNotificationChannel)
-> ReadS [AddNotificationChannel]
-> ReadPrec AddNotificationChannel
-> ReadPrec [AddNotificationChannel]
-> Read 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
(Int -> AddNotificationChannel -> ShowS)
-> (AddNotificationChannel -> String)
-> ([AddNotificationChannel] -> ShowS)
-> Show AddNotificationChannel
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. AddNotificationChannel -> Rep AddNotificationChannel x)
-> (forall x.
    Rep AddNotificationChannel x -> AddNotificationChannel)
-> Generic AddNotificationChannel
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' :: NotificationChannelConfig -> AddNotificationChannel
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 :: (NotificationChannelConfig -> f NotificationChannelConfig)
-> AddNotificationChannel -> f AddNotificationChannel
addNotificationChannel_config = (AddNotificationChannel -> NotificationChannelConfig)
-> (AddNotificationChannel
    -> NotificationChannelConfig -> AddNotificationChannel)
-> Lens
     AddNotificationChannel
     AddNotificationChannel
     NotificationChannelConfig
     NotificationChannelConfig
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 :: AddNotificationChannel -> Request AddNotificationChannel
request = Service -> AddNotificationChannel -> Request AddNotificationChannel
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AddNotificationChannel
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddNotificationChannel)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AddNotificationChannel))
-> Logger
-> Service
-> Proxy AddNotificationChannel
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddNotificationChannel)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> AddNotificationChannelResponse
AddNotificationChannelResponse'
            (Int -> Text -> AddNotificationChannelResponse)
-> Either String Int
-> Either String (Text -> AddNotificationChannelResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (Text -> AddNotificationChannelResponse)
-> Either String Text
-> Either String AddNotificationChannelResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"Id")
      )

instance Prelude.Hashable AddNotificationChannel

instance Prelude.NFData AddNotificationChannel

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

instance Core.ToJSON AddNotificationChannel where
  toJSON :: AddNotificationChannel -> Value
toJSON AddNotificationChannel' {NotificationChannelConfig
config :: NotificationChannelConfig
$sel:config:AddNotificationChannel' :: AddNotificationChannel -> NotificationChannelConfig
..} =
    [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
"Config" Text -> NotificationChannelConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NotificationChannelConfig
config)]
      )

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

instance Core.ToQuery AddNotificationChannel where
  toQuery :: AddNotificationChannel -> QueryString
toQuery = QueryString -> AddNotificationChannel -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(AddNotificationChannelResponse
 -> AddNotificationChannelResponse -> Bool)
-> (AddNotificationChannelResponse
    -> AddNotificationChannelResponse -> Bool)
-> Eq AddNotificationChannelResponse
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]
(Int -> ReadS AddNotificationChannelResponse)
-> ReadS [AddNotificationChannelResponse]
-> ReadPrec AddNotificationChannelResponse
-> ReadPrec [AddNotificationChannelResponse]
-> Read 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
(Int -> AddNotificationChannelResponse -> ShowS)
-> (AddNotificationChannelResponse -> String)
-> ([AddNotificationChannelResponse] -> ShowS)
-> Show AddNotificationChannelResponse
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.
 AddNotificationChannelResponse
 -> Rep AddNotificationChannelResponse x)
-> (forall x.
    Rep AddNotificationChannelResponse x
    -> AddNotificationChannelResponse)
-> Generic AddNotificationChannelResponse
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' :: Int -> Text -> AddNotificationChannelResponse
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 :: (Int -> f Int)
-> AddNotificationChannelResponse
-> f AddNotificationChannelResponse
addNotificationChannelResponse_httpStatus = (AddNotificationChannelResponse -> Int)
-> (AddNotificationChannelResponse
    -> Int -> AddNotificationChannelResponse)
-> Lens
     AddNotificationChannelResponse
     AddNotificationChannelResponse
     Int
     Int
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 :: (Text -> f Text)
-> AddNotificationChannelResponse
-> f AddNotificationChannelResponse
addNotificationChannelResponse_id = (AddNotificationChannelResponse -> Text)
-> (AddNotificationChannelResponse
    -> Text -> AddNotificationChannelResponse)
-> Lens
     AddNotificationChannelResponse
     AddNotificationChannelResponse
     Text
     Text
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