{-# 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.AppSync.ListFunctions
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- List multiple functions.
--
-- This operation returns paginated results.
module Amazonka.AppSync.ListFunctions
  ( -- * Creating a Request
    ListFunctions (..),
    newListFunctions,

    -- * Request Lenses
    listFunctions_maxResults,
    listFunctions_nextToken,
    listFunctions_apiId,

    -- * Destructuring the Response
    ListFunctionsResponse (..),
    newListFunctionsResponse,

    -- * Response Lenses
    listFunctionsResponse_functions,
    listFunctionsResponse_nextToken,
    listFunctionsResponse_httpStatus,
  )
where

import Amazonka.AppSync.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

-- | /See:/ 'newListFunctions' smart constructor.
data ListFunctions = ListFunctions'
  { -- | The maximum number of results that you want the request to return.
    ListFunctions -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | An identifier that was returned from the previous call to this
    -- operation, which you can use to return the next set of items in the
    -- list.
    ListFunctions -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The GraphQL API ID.
    ListFunctions -> Text
apiId :: Prelude.Text
  }
  deriving (ListFunctions -> ListFunctions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListFunctions -> ListFunctions -> Bool
$c/= :: ListFunctions -> ListFunctions -> Bool
== :: ListFunctions -> ListFunctions -> Bool
$c== :: ListFunctions -> ListFunctions -> Bool
Prelude.Eq, ReadPrec [ListFunctions]
ReadPrec ListFunctions
Int -> ReadS ListFunctions
ReadS [ListFunctions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListFunctions]
$creadListPrec :: ReadPrec [ListFunctions]
readPrec :: ReadPrec ListFunctions
$creadPrec :: ReadPrec ListFunctions
readList :: ReadS [ListFunctions]
$creadList :: ReadS [ListFunctions]
readsPrec :: Int -> ReadS ListFunctions
$creadsPrec :: Int -> ReadS ListFunctions
Prelude.Read, Int -> ListFunctions -> ShowS
[ListFunctions] -> ShowS
ListFunctions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListFunctions] -> ShowS
$cshowList :: [ListFunctions] -> ShowS
show :: ListFunctions -> String
$cshow :: ListFunctions -> String
showsPrec :: Int -> ListFunctions -> ShowS
$cshowsPrec :: Int -> ListFunctions -> ShowS
Prelude.Show, forall x. Rep ListFunctions x -> ListFunctions
forall x. ListFunctions -> Rep ListFunctions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListFunctions x -> ListFunctions
$cfrom :: forall x. ListFunctions -> Rep ListFunctions x
Prelude.Generic)

-- |
-- Create a value of 'ListFunctions' 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', 'listFunctions_maxResults' - The maximum number of results that you want the request to return.
--
-- 'nextToken', 'listFunctions_nextToken' - An identifier that was returned from the previous call to this
-- operation, which you can use to return the next set of items in the
-- list.
--
-- 'apiId', 'listFunctions_apiId' - The GraphQL API ID.
newListFunctions ::
  -- | 'apiId'
  Prelude.Text ->
  ListFunctions
newListFunctions :: Text -> ListFunctions
newListFunctions Text
pApiId_ =
  ListFunctions'
    { $sel:maxResults:ListFunctions' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListFunctions' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:apiId:ListFunctions' :: Text
apiId = Text
pApiId_
    }

-- | The maximum number of results that you want the request to return.
listFunctions_maxResults :: Lens.Lens' ListFunctions (Prelude.Maybe Prelude.Natural)
listFunctions_maxResults :: Lens' ListFunctions (Maybe Natural)
listFunctions_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFunctions' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListFunctions' :: ListFunctions -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListFunctions
s@ListFunctions' {} Maybe Natural
a -> ListFunctions
s {$sel:maxResults:ListFunctions' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListFunctions)

-- | An identifier that was returned from the previous call to this
-- operation, which you can use to return the next set of items in the
-- list.
listFunctions_nextToken :: Lens.Lens' ListFunctions (Prelude.Maybe Prelude.Text)
listFunctions_nextToken :: Lens' ListFunctions (Maybe Text)
listFunctions_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFunctions' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListFunctions' :: ListFunctions -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListFunctions
s@ListFunctions' {} Maybe Text
a -> ListFunctions
s {$sel:nextToken:ListFunctions' :: Maybe Text
nextToken = Maybe Text
a} :: ListFunctions)

-- | The GraphQL API ID.
listFunctions_apiId :: Lens.Lens' ListFunctions Prelude.Text
listFunctions_apiId :: Lens' ListFunctions Text
listFunctions_apiId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFunctions' {Text
apiId :: Text
$sel:apiId:ListFunctions' :: ListFunctions -> Text
apiId} -> Text
apiId) (\s :: ListFunctions
s@ListFunctions' {} Text
a -> ListFunctions
s {$sel:apiId:ListFunctions' :: Text
apiId = Text
a} :: ListFunctions)

instance Core.AWSPager ListFunctions where
  page :: ListFunctions -> AWSResponse ListFunctions -> Maybe ListFunctions
page ListFunctions
rq AWSResponse ListFunctions
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListFunctions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFunctionsResponse (Maybe Text)
listFunctionsResponse_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 ListFunctions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFunctionsResponse (Maybe [FunctionConfiguration])
listFunctionsResponse_functions
            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.$ ListFunctions
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListFunctions (Maybe Text)
listFunctions_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListFunctions
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFunctionsResponse (Maybe Text)
listFunctionsResponse_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 ListFunctions where
  type
    AWSResponse ListFunctions =
      ListFunctionsResponse
  request :: (Service -> Service) -> ListFunctions -> Request ListFunctions
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 ListFunctions
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListFunctions)))
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 [FunctionConfiguration]
-> Maybe Text -> Int -> ListFunctionsResponse
ListFunctionsResponse'
            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
"functions" 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 ListFunctions where
  hashWithSalt :: Int -> ListFunctions -> Int
hashWithSalt Int
_salt ListFunctions' {Maybe Natural
Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:apiId:ListFunctions' :: ListFunctions -> Text
$sel:nextToken:ListFunctions' :: ListFunctions -> Maybe Text
$sel:maxResults:ListFunctions' :: ListFunctions -> 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
apiId

instance Prelude.NFData ListFunctions where
  rnf :: ListFunctions -> ()
rnf ListFunctions' {Maybe Natural
Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:apiId:ListFunctions' :: ListFunctions -> Text
$sel:nextToken:ListFunctions' :: ListFunctions -> Maybe Text
$sel:maxResults:ListFunctions' :: ListFunctions -> 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
apiId

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

instance Data.ToQuery ListFunctions where
  toQuery :: ListFunctions -> QueryString
toQuery ListFunctions' {Maybe Natural
Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:apiId:ListFunctions' :: ListFunctions -> Text
$sel:nextToken:ListFunctions' :: ListFunctions -> Maybe Text
$sel:maxResults:ListFunctions' :: ListFunctions -> 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
      ]

-- | /See:/ 'newListFunctionsResponse' smart constructor.
data ListFunctionsResponse = ListFunctionsResponse'
  { -- | A list of @Function@ objects.
    ListFunctionsResponse -> Maybe [FunctionConfiguration]
functions :: Prelude.Maybe [FunctionConfiguration],
    -- | An identifier that was returned from the previous call to this
    -- operation, which you can use to return the next set of items in the
    -- list.
    ListFunctionsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListFunctionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListFunctionsResponse -> ListFunctionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListFunctionsResponse -> ListFunctionsResponse -> Bool
$c/= :: ListFunctionsResponse -> ListFunctionsResponse -> Bool
== :: ListFunctionsResponse -> ListFunctionsResponse -> Bool
$c== :: ListFunctionsResponse -> ListFunctionsResponse -> Bool
Prelude.Eq, ReadPrec [ListFunctionsResponse]
ReadPrec ListFunctionsResponse
Int -> ReadS ListFunctionsResponse
ReadS [ListFunctionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListFunctionsResponse]
$creadListPrec :: ReadPrec [ListFunctionsResponse]
readPrec :: ReadPrec ListFunctionsResponse
$creadPrec :: ReadPrec ListFunctionsResponse
readList :: ReadS [ListFunctionsResponse]
$creadList :: ReadS [ListFunctionsResponse]
readsPrec :: Int -> ReadS ListFunctionsResponse
$creadsPrec :: Int -> ReadS ListFunctionsResponse
Prelude.Read, Int -> ListFunctionsResponse -> ShowS
[ListFunctionsResponse] -> ShowS
ListFunctionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListFunctionsResponse] -> ShowS
$cshowList :: [ListFunctionsResponse] -> ShowS
show :: ListFunctionsResponse -> String
$cshow :: ListFunctionsResponse -> String
showsPrec :: Int -> ListFunctionsResponse -> ShowS
$cshowsPrec :: Int -> ListFunctionsResponse -> ShowS
Prelude.Show, forall x. Rep ListFunctionsResponse x -> ListFunctionsResponse
forall x. ListFunctionsResponse -> Rep ListFunctionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListFunctionsResponse x -> ListFunctionsResponse
$cfrom :: forall x. ListFunctionsResponse -> Rep ListFunctionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListFunctionsResponse' 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:
--
-- 'functions', 'listFunctionsResponse_functions' - A list of @Function@ objects.
--
-- 'nextToken', 'listFunctionsResponse_nextToken' - An identifier that was returned from the previous call to this
-- operation, which you can use to return the next set of items in the
-- list.
--
-- 'httpStatus', 'listFunctionsResponse_httpStatus' - The response's http status code.
newListFunctionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListFunctionsResponse
newListFunctionsResponse :: Int -> ListFunctionsResponse
newListFunctionsResponse Int
pHttpStatus_ =
  ListFunctionsResponse'
    { $sel:functions:ListFunctionsResponse' :: Maybe [FunctionConfiguration]
functions = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListFunctionsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListFunctionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of @Function@ objects.
listFunctionsResponse_functions :: Lens.Lens' ListFunctionsResponse (Prelude.Maybe [FunctionConfiguration])
listFunctionsResponse_functions :: Lens' ListFunctionsResponse (Maybe [FunctionConfiguration])
listFunctionsResponse_functions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFunctionsResponse' {Maybe [FunctionConfiguration]
functions :: Maybe [FunctionConfiguration]
$sel:functions:ListFunctionsResponse' :: ListFunctionsResponse -> Maybe [FunctionConfiguration]
functions} -> Maybe [FunctionConfiguration]
functions) (\s :: ListFunctionsResponse
s@ListFunctionsResponse' {} Maybe [FunctionConfiguration]
a -> ListFunctionsResponse
s {$sel:functions:ListFunctionsResponse' :: Maybe [FunctionConfiguration]
functions = Maybe [FunctionConfiguration]
a} :: ListFunctionsResponse) 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

-- | An identifier that was returned from the previous call to this
-- operation, which you can use to return the next set of items in the
-- list.
listFunctionsResponse_nextToken :: Lens.Lens' ListFunctionsResponse (Prelude.Maybe Prelude.Text)
listFunctionsResponse_nextToken :: Lens' ListFunctionsResponse (Maybe Text)
listFunctionsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFunctionsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListFunctionsResponse' :: ListFunctionsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListFunctionsResponse
s@ListFunctionsResponse' {} Maybe Text
a -> ListFunctionsResponse
s {$sel:nextToken:ListFunctionsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListFunctionsResponse)

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

instance Prelude.NFData ListFunctionsResponse where
  rnf :: ListFunctionsResponse -> ()
rnf ListFunctionsResponse' {Int
Maybe [FunctionConfiguration]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
functions :: Maybe [FunctionConfiguration]
$sel:httpStatus:ListFunctionsResponse' :: ListFunctionsResponse -> Int
$sel:nextToken:ListFunctionsResponse' :: ListFunctionsResponse -> Maybe Text
$sel:functions:ListFunctionsResponse' :: ListFunctionsResponse -> Maybe [FunctionConfiguration]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [FunctionConfiguration]
functions
      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