{-# 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.Amplify.ListWebhooks
-- 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 webhooks for an Amplify app.
module Amazonka.Amplify.ListWebhooks
  ( -- * Creating a Request
    ListWebhooks (..),
    newListWebhooks,

    -- * Request Lenses
    listWebhooks_maxResults,
    listWebhooks_nextToken,
    listWebhooks_appId,

    -- * Destructuring the Response
    ListWebhooksResponse (..),
    newListWebhooksResponse,

    -- * Response Lenses
    listWebhooksResponse_nextToken,
    listWebhooksResponse_httpStatus,
    listWebhooksResponse_webhooks,
  )
where

import Amazonka.Amplify.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | The request structure for the list webhooks request.
--
-- /See:/ 'newListWebhooks' smart constructor.
data ListWebhooks = ListWebhooks'
  { -- | The maximum number of records to list in a single response.
    ListWebhooks -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A pagination token. Set to null to start listing webhooks from the
    -- start. If non-null,the pagination token is returned in a result. Pass
    -- its value in here to list more webhooks.
    ListWebhooks -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The unique ID for an Amplify app.
    ListWebhooks -> Text
appId :: Prelude.Text
  }
  deriving (ListWebhooks -> ListWebhooks -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListWebhooks -> ListWebhooks -> Bool
$c/= :: ListWebhooks -> ListWebhooks -> Bool
== :: ListWebhooks -> ListWebhooks -> Bool
$c== :: ListWebhooks -> ListWebhooks -> Bool
Prelude.Eq, ReadPrec [ListWebhooks]
ReadPrec ListWebhooks
Int -> ReadS ListWebhooks
ReadS [ListWebhooks]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListWebhooks]
$creadListPrec :: ReadPrec [ListWebhooks]
readPrec :: ReadPrec ListWebhooks
$creadPrec :: ReadPrec ListWebhooks
readList :: ReadS [ListWebhooks]
$creadList :: ReadS [ListWebhooks]
readsPrec :: Int -> ReadS ListWebhooks
$creadsPrec :: Int -> ReadS ListWebhooks
Prelude.Read, Int -> ListWebhooks -> ShowS
[ListWebhooks] -> ShowS
ListWebhooks -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListWebhooks] -> ShowS
$cshowList :: [ListWebhooks] -> ShowS
show :: ListWebhooks -> String
$cshow :: ListWebhooks -> String
showsPrec :: Int -> ListWebhooks -> ShowS
$cshowsPrec :: Int -> ListWebhooks -> ShowS
Prelude.Show, forall x. Rep ListWebhooks x -> ListWebhooks
forall x. ListWebhooks -> Rep ListWebhooks x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListWebhooks x -> ListWebhooks
$cfrom :: forall x. ListWebhooks -> Rep ListWebhooks x
Prelude.Generic)

-- |
-- Create a value of 'ListWebhooks' 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:
--
-- 'maxResults', 'listWebhooks_maxResults' - The maximum number of records to list in a single response.
--
-- 'nextToken', 'listWebhooks_nextToken' - A pagination token. Set to null to start listing webhooks from the
-- start. If non-null,the pagination token is returned in a result. Pass
-- its value in here to list more webhooks.
--
-- 'appId', 'listWebhooks_appId' - The unique ID for an Amplify app.
newListWebhooks ::
  -- | 'appId'
  Prelude.Text ->
  ListWebhooks
newListWebhooks :: Text -> ListWebhooks
newListWebhooks Text
pAppId_ =
  ListWebhooks'
    { $sel:maxResults:ListWebhooks' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListWebhooks' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:appId:ListWebhooks' :: Text
appId = Text
pAppId_
    }

-- | The maximum number of records to list in a single response.
listWebhooks_maxResults :: Lens.Lens' ListWebhooks (Prelude.Maybe Prelude.Natural)
listWebhooks_maxResults :: Lens' ListWebhooks (Maybe Natural)
listWebhooks_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooks' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListWebhooks
s@ListWebhooks' {} Maybe Natural
a -> ListWebhooks
s {$sel:maxResults:ListWebhooks' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListWebhooks)

-- | A pagination token. Set to null to start listing webhooks from the
-- start. If non-null,the pagination token is returned in a result. Pass
-- its value in here to list more webhooks.
listWebhooks_nextToken :: Lens.Lens' ListWebhooks (Prelude.Maybe Prelude.Text)
listWebhooks_nextToken :: Lens' ListWebhooks (Maybe Text)
listWebhooks_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooks' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListWebhooks
s@ListWebhooks' {} Maybe Text
a -> ListWebhooks
s {$sel:nextToken:ListWebhooks' :: Maybe Text
nextToken = Maybe Text
a} :: ListWebhooks)

-- | The unique ID for an Amplify app.
listWebhooks_appId :: Lens.Lens' ListWebhooks Prelude.Text
listWebhooks_appId :: Lens' ListWebhooks Text
listWebhooks_appId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooks' {Text
appId :: Text
$sel:appId:ListWebhooks' :: ListWebhooks -> Text
appId} -> Text
appId) (\s :: ListWebhooks
s@ListWebhooks' {} Text
a -> ListWebhooks
s {$sel:appId:ListWebhooks' :: Text
appId = Text
a} :: ListWebhooks)

instance Core.AWSRequest ListWebhooks where
  type AWSResponse ListWebhooks = ListWebhooksResponse
  request :: (Service -> Service) -> ListWebhooks -> Request ListWebhooks
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListWebhooks
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListWebhooks)))
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 Text -> Int -> [Webhook] -> ListWebhooksResponse
ListWebhooksResponse'
            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
"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))
            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
"webhooks" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

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

instance Prelude.NFData ListWebhooks where
  rnf :: ListWebhooks -> ()
rnf ListWebhooks' {Maybe Natural
Maybe Text
Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:appId:ListWebhooks' :: ListWebhooks -> Text
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      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 Text
appId

instance Data.ToHeaders ListWebhooks where
  toHeaders :: ListWebhooks -> 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.ToPath ListWebhooks where
  toPath :: ListWebhooks -> ByteString
toPath ListWebhooks' {Maybe Natural
Maybe Text
Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:appId:ListWebhooks' :: ListWebhooks -> Text
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/apps/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
appId, ByteString
"/webhooks"]

instance Data.ToQuery ListWebhooks where
  toQuery :: ListWebhooks -> QueryString
toQuery ListWebhooks' {Maybe Natural
Maybe Text
Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:appId:ListWebhooks' :: ListWebhooks -> Text
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"maxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxResults,
        ByteString
"nextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | The result structure for the list webhooks request.
--
-- /See:/ 'newListWebhooksResponse' smart constructor.
data ListWebhooksResponse = ListWebhooksResponse'
  { -- | A pagination token. If non-null, the pagination token is returned in a
    -- result. Pass its value in another request to retrieve more entries.
    ListWebhooksResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListWebhooksResponse -> Int
httpStatus :: Prelude.Int,
    -- | A list of webhooks.
    ListWebhooksResponse -> [Webhook]
webhooks :: [Webhook]
  }
  deriving (ListWebhooksResponse -> ListWebhooksResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
$c/= :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
== :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
$c== :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
Prelude.Eq, ReadPrec [ListWebhooksResponse]
ReadPrec ListWebhooksResponse
Int -> ReadS ListWebhooksResponse
ReadS [ListWebhooksResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListWebhooksResponse]
$creadListPrec :: ReadPrec [ListWebhooksResponse]
readPrec :: ReadPrec ListWebhooksResponse
$creadPrec :: ReadPrec ListWebhooksResponse
readList :: ReadS [ListWebhooksResponse]
$creadList :: ReadS [ListWebhooksResponse]
readsPrec :: Int -> ReadS ListWebhooksResponse
$creadsPrec :: Int -> ReadS ListWebhooksResponse
Prelude.Read, Int -> ListWebhooksResponse -> ShowS
[ListWebhooksResponse] -> ShowS
ListWebhooksResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListWebhooksResponse] -> ShowS
$cshowList :: [ListWebhooksResponse] -> ShowS
show :: ListWebhooksResponse -> String
$cshow :: ListWebhooksResponse -> String
showsPrec :: Int -> ListWebhooksResponse -> ShowS
$cshowsPrec :: Int -> ListWebhooksResponse -> ShowS
Prelude.Show, forall x. Rep ListWebhooksResponse x -> ListWebhooksResponse
forall x. ListWebhooksResponse -> Rep ListWebhooksResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListWebhooksResponse x -> ListWebhooksResponse
$cfrom :: forall x. ListWebhooksResponse -> Rep ListWebhooksResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListWebhooksResponse' 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', 'listWebhooksResponse_nextToken' - A pagination token. If non-null, the pagination token is returned in a
-- result. Pass its value in another request to retrieve more entries.
--
-- 'httpStatus', 'listWebhooksResponse_httpStatus' - The response's http status code.
--
-- 'webhooks', 'listWebhooksResponse_webhooks' - A list of webhooks.
newListWebhooksResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListWebhooksResponse
newListWebhooksResponse :: Int -> ListWebhooksResponse
newListWebhooksResponse Int
pHttpStatus_ =
  ListWebhooksResponse'
    { $sel:nextToken:ListWebhooksResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListWebhooksResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:webhooks:ListWebhooksResponse' :: [Webhook]
webhooks = forall a. Monoid a => a
Prelude.mempty
    }

-- | A pagination token. If non-null, the pagination token is returned in a
-- result. Pass its value in another request to retrieve more entries.
listWebhooksResponse_nextToken :: Lens.Lens' ListWebhooksResponse (Prelude.Maybe Prelude.Text)
listWebhooksResponse_nextToken :: Lens' ListWebhooksResponse (Maybe Text)
listWebhooksResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooksResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListWebhooksResponse' :: ListWebhooksResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListWebhooksResponse
s@ListWebhooksResponse' {} Maybe Text
a -> ListWebhooksResponse
s {$sel:nextToken:ListWebhooksResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListWebhooksResponse)

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

-- | A list of webhooks.
listWebhooksResponse_webhooks :: Lens.Lens' ListWebhooksResponse [Webhook]
listWebhooksResponse_webhooks :: Lens' ListWebhooksResponse [Webhook]
listWebhooksResponse_webhooks = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooksResponse' {[Webhook]
webhooks :: [Webhook]
$sel:webhooks:ListWebhooksResponse' :: ListWebhooksResponse -> [Webhook]
webhooks} -> [Webhook]
webhooks) (\s :: ListWebhooksResponse
s@ListWebhooksResponse' {} [Webhook]
a -> ListWebhooksResponse
s {$sel:webhooks:ListWebhooksResponse' :: [Webhook]
webhooks = [Webhook]
a} :: ListWebhooksResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData ListWebhooksResponse where
  rnf :: ListWebhooksResponse -> ()
rnf ListWebhooksResponse' {Int
[Webhook]
Maybe Text
webhooks :: [Webhook]
httpStatus :: Int
nextToken :: Maybe Text
$sel:webhooks:ListWebhooksResponse' :: ListWebhooksResponse -> [Webhook]
$sel:httpStatus:ListWebhooksResponse' :: ListWebhooksResponse -> Int
$sel:nextToken:ListWebhooksResponse' :: ListWebhooksResponse -> Maybe Text
..} =
    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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Webhook]
webhooks