{-# 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.ListNotificationChannels
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns a list of notification channels configured for DevOps Guru. Each
-- notification channel is used to notify you when DevOps Guru generates an
-- insight that contains information about how to improve your operations.
-- The one supported notification channel is Amazon Simple Notification
-- Service (Amazon SNS).
--
-- This operation returns paginated results.
module Amazonka.DevOpsGuru.ListNotificationChannels
  ( -- * Creating a Request
    ListNotificationChannels (..),
    newListNotificationChannels,

    -- * Request Lenses
    listNotificationChannels_nextToken,

    -- * Destructuring the Response
    ListNotificationChannelsResponse (..),
    newListNotificationChannelsResponse,

    -- * Response Lenses
    listNotificationChannelsResponse_channels,
    listNotificationChannelsResponse_nextToken,
    listNotificationChannelsResponse_httpStatus,
  )
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:/ 'newListNotificationChannels' smart constructor.
data ListNotificationChannels = ListNotificationChannels'
  { -- | The pagination token to use to retrieve the next page of results for
    -- this operation. If this value is null, it retrieves the first page.
    ListNotificationChannels -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListNotificationChannels -> ListNotificationChannels -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListNotificationChannels -> ListNotificationChannels -> Bool
$c/= :: ListNotificationChannels -> ListNotificationChannels -> Bool
== :: ListNotificationChannels -> ListNotificationChannels -> Bool
$c== :: ListNotificationChannels -> ListNotificationChannels -> Bool
Prelude.Eq, ReadPrec [ListNotificationChannels]
ReadPrec ListNotificationChannels
Int -> ReadS ListNotificationChannels
ReadS [ListNotificationChannels]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListNotificationChannels]
$creadListPrec :: ReadPrec [ListNotificationChannels]
readPrec :: ReadPrec ListNotificationChannels
$creadPrec :: ReadPrec ListNotificationChannels
readList :: ReadS [ListNotificationChannels]
$creadList :: ReadS [ListNotificationChannels]
readsPrec :: Int -> ReadS ListNotificationChannels
$creadsPrec :: Int -> ReadS ListNotificationChannels
Prelude.Read, Int -> ListNotificationChannels -> ShowS
[ListNotificationChannels] -> ShowS
ListNotificationChannels -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListNotificationChannels] -> ShowS
$cshowList :: [ListNotificationChannels] -> ShowS
show :: ListNotificationChannels -> String
$cshow :: ListNotificationChannels -> String
showsPrec :: Int -> ListNotificationChannels -> ShowS
$cshowsPrec :: Int -> ListNotificationChannels -> ShowS
Prelude.Show, forall x.
Rep ListNotificationChannels x -> ListNotificationChannels
forall x.
ListNotificationChannels -> Rep ListNotificationChannels x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListNotificationChannels x -> ListNotificationChannels
$cfrom :: forall x.
ListNotificationChannels -> Rep ListNotificationChannels x
Prelude.Generic)

-- |
-- Create a value of 'ListNotificationChannels' 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:
--
-- 'nextToken', 'listNotificationChannels_nextToken' - The pagination token to use to retrieve the next page of results for
-- this operation. If this value is null, it retrieves the first page.
newListNotificationChannels ::
  ListNotificationChannels
newListNotificationChannels :: ListNotificationChannels
newListNotificationChannels =
  ListNotificationChannels'
    { $sel:nextToken:ListNotificationChannels' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing
    }

-- | The pagination token to use to retrieve the next page of results for
-- this operation. If this value is null, it retrieves the first page.
listNotificationChannels_nextToken :: Lens.Lens' ListNotificationChannels (Prelude.Maybe Prelude.Text)
listNotificationChannels_nextToken :: Lens' ListNotificationChannels (Maybe Text)
listNotificationChannels_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListNotificationChannels' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListNotificationChannels' :: ListNotificationChannels -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListNotificationChannels
s@ListNotificationChannels' {} Maybe Text
a -> ListNotificationChannels
s {$sel:nextToken:ListNotificationChannels' :: Maybe Text
nextToken = Maybe Text
a} :: ListNotificationChannels)

instance Core.AWSPager ListNotificationChannels where
  page :: ListNotificationChannels
-> AWSResponse ListNotificationChannels
-> Maybe ListNotificationChannels
page ListNotificationChannels
rq AWSResponse ListNotificationChannels
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListNotificationChannels
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListNotificationChannelsResponse (Maybe Text)
listNotificationChannelsResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListNotificationChannels
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens'
  ListNotificationChannelsResponse (Maybe [NotificationChannel])
listNotificationChannelsResponse_channels
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListNotificationChannels
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListNotificationChannels (Maybe Text)
listNotificationChannels_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListNotificationChannels
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListNotificationChannelsResponse (Maybe Text)
listNotificationChannelsResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListNotificationChannels where
  type
    AWSResponse ListNotificationChannels =
      ListNotificationChannelsResponse
  request :: (Service -> Service)
-> ListNotificationChannels -> Request ListNotificationChannels
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListNotificationChannels
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListNotificationChannels)))
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 ->
          Maybe [NotificationChannel]
-> Maybe Text -> Int -> ListNotificationChannelsResponse
ListNotificationChannelsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Channels" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextToken")
            forall (f :: * -> *) a b. Applicative f => 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))
      )

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

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

instance Data.ToHeaders ListNotificationChannels where
  toHeaders :: ListNotificationChannels -> 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 ListNotificationChannels where
  toJSON :: ListNotificationChannels -> Value
toJSON ListNotificationChannels' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListNotificationChannels' :: ListNotificationChannels -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"NextToken" 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
nextToken]
      )

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

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

-- | /See:/ 'newListNotificationChannelsResponse' smart constructor.
data ListNotificationChannelsResponse = ListNotificationChannelsResponse'
  { -- | An array that contains the requested notification channels.
    ListNotificationChannelsResponse -> Maybe [NotificationChannel]
channels :: Prelude.Maybe [NotificationChannel],
    -- | The pagination token to use to retrieve the next page of results for
    -- this operation. If there are no more pages, this value is null.
    ListNotificationChannelsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListNotificationChannelsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListNotificationChannelsResponse
-> ListNotificationChannelsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListNotificationChannelsResponse
-> ListNotificationChannelsResponse -> Bool
$c/= :: ListNotificationChannelsResponse
-> ListNotificationChannelsResponse -> Bool
== :: ListNotificationChannelsResponse
-> ListNotificationChannelsResponse -> Bool
$c== :: ListNotificationChannelsResponse
-> ListNotificationChannelsResponse -> Bool
Prelude.Eq, ReadPrec [ListNotificationChannelsResponse]
ReadPrec ListNotificationChannelsResponse
Int -> ReadS ListNotificationChannelsResponse
ReadS [ListNotificationChannelsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListNotificationChannelsResponse]
$creadListPrec :: ReadPrec [ListNotificationChannelsResponse]
readPrec :: ReadPrec ListNotificationChannelsResponse
$creadPrec :: ReadPrec ListNotificationChannelsResponse
readList :: ReadS [ListNotificationChannelsResponse]
$creadList :: ReadS [ListNotificationChannelsResponse]
readsPrec :: Int -> ReadS ListNotificationChannelsResponse
$creadsPrec :: Int -> ReadS ListNotificationChannelsResponse
Prelude.Read, Int -> ListNotificationChannelsResponse -> ShowS
[ListNotificationChannelsResponse] -> ShowS
ListNotificationChannelsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListNotificationChannelsResponse] -> ShowS
$cshowList :: [ListNotificationChannelsResponse] -> ShowS
show :: ListNotificationChannelsResponse -> String
$cshow :: ListNotificationChannelsResponse -> String
showsPrec :: Int -> ListNotificationChannelsResponse -> ShowS
$cshowsPrec :: Int -> ListNotificationChannelsResponse -> ShowS
Prelude.Show, forall x.
Rep ListNotificationChannelsResponse x
-> ListNotificationChannelsResponse
forall x.
ListNotificationChannelsResponse
-> Rep ListNotificationChannelsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListNotificationChannelsResponse x
-> ListNotificationChannelsResponse
$cfrom :: forall x.
ListNotificationChannelsResponse
-> Rep ListNotificationChannelsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListNotificationChannelsResponse' 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:
--
-- 'channels', 'listNotificationChannelsResponse_channels' - An array that contains the requested notification channels.
--
-- 'nextToken', 'listNotificationChannelsResponse_nextToken' - The pagination token to use to retrieve the next page of results for
-- this operation. If there are no more pages, this value is null.
--
-- 'httpStatus', 'listNotificationChannelsResponse_httpStatus' - The response's http status code.
newListNotificationChannelsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListNotificationChannelsResponse
newListNotificationChannelsResponse :: Int -> ListNotificationChannelsResponse
newListNotificationChannelsResponse Int
pHttpStatus_ =
  ListNotificationChannelsResponse'
    { $sel:channels:ListNotificationChannelsResponse' :: Maybe [NotificationChannel]
channels =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListNotificationChannelsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListNotificationChannelsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array that contains the requested notification channels.
listNotificationChannelsResponse_channels :: Lens.Lens' ListNotificationChannelsResponse (Prelude.Maybe [NotificationChannel])
listNotificationChannelsResponse_channels :: Lens'
  ListNotificationChannelsResponse (Maybe [NotificationChannel])
listNotificationChannelsResponse_channels = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListNotificationChannelsResponse' {Maybe [NotificationChannel]
channels :: Maybe [NotificationChannel]
$sel:channels:ListNotificationChannelsResponse' :: ListNotificationChannelsResponse -> Maybe [NotificationChannel]
channels} -> Maybe [NotificationChannel]
channels) (\s :: ListNotificationChannelsResponse
s@ListNotificationChannelsResponse' {} Maybe [NotificationChannel]
a -> ListNotificationChannelsResponse
s {$sel:channels:ListNotificationChannelsResponse' :: Maybe [NotificationChannel]
channels = Maybe [NotificationChannel]
a} :: ListNotificationChannelsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The pagination token to use to retrieve the next page of results for
-- this operation. If there are no more pages, this value is null.
listNotificationChannelsResponse_nextToken :: Lens.Lens' ListNotificationChannelsResponse (Prelude.Maybe Prelude.Text)
listNotificationChannelsResponse_nextToken :: Lens' ListNotificationChannelsResponse (Maybe Text)
listNotificationChannelsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListNotificationChannelsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListNotificationChannelsResponse' :: ListNotificationChannelsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListNotificationChannelsResponse
s@ListNotificationChannelsResponse' {} Maybe Text
a -> ListNotificationChannelsResponse
s {$sel:nextToken:ListNotificationChannelsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListNotificationChannelsResponse)

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

instance
  Prelude.NFData
    ListNotificationChannelsResponse
  where
  rnf :: ListNotificationChannelsResponse -> ()
rnf ListNotificationChannelsResponse' {Int
Maybe [NotificationChannel]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
channels :: Maybe [NotificationChannel]
$sel:httpStatus:ListNotificationChannelsResponse' :: ListNotificationChannelsResponse -> Int
$sel:nextToken:ListNotificationChannelsResponse' :: ListNotificationChannelsResponse -> Maybe Text
$sel:channels:ListNotificationChannelsResponse' :: ListNotificationChannelsResponse -> Maybe [NotificationChannel]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [NotificationChannel]
channels
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus