{-# 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.ListDataSources
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the data sources for a given API.
--
-- This operation returns paginated results.
module Amazonka.AppSync.ListDataSources
  ( -- * Creating a Request
    ListDataSources (..),
    newListDataSources,

    -- * Request Lenses
    listDataSources_maxResults,
    listDataSources_nextToken,
    listDataSources_apiId,

    -- * Destructuring the Response
    ListDataSourcesResponse (..),
    newListDataSourcesResponse,

    -- * Response Lenses
    listDataSourcesResponse_dataSources,
    listDataSourcesResponse_nextToken,
    listDataSourcesResponse_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:/ 'newListDataSources' smart constructor.
data ListDataSources = ListDataSources'
  { -- | The maximum number of results that you want the request to return.
    ListDataSources -> 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.
    ListDataSources -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The API ID.
    ListDataSources -> Text
apiId :: Prelude.Text
  }
  deriving (ListDataSources -> ListDataSources -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListDataSources -> ListDataSources -> Bool
$c/= :: ListDataSources -> ListDataSources -> Bool
== :: ListDataSources -> ListDataSources -> Bool
$c== :: ListDataSources -> ListDataSources -> Bool
Prelude.Eq, ReadPrec [ListDataSources]
ReadPrec ListDataSources
Int -> ReadS ListDataSources
ReadS [ListDataSources]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListDataSources]
$creadListPrec :: ReadPrec [ListDataSources]
readPrec :: ReadPrec ListDataSources
$creadPrec :: ReadPrec ListDataSources
readList :: ReadS [ListDataSources]
$creadList :: ReadS [ListDataSources]
readsPrec :: Int -> ReadS ListDataSources
$creadsPrec :: Int -> ReadS ListDataSources
Prelude.Read, Int -> ListDataSources -> ShowS
[ListDataSources] -> ShowS
ListDataSources -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDataSources] -> ShowS
$cshowList :: [ListDataSources] -> ShowS
show :: ListDataSources -> String
$cshow :: ListDataSources -> String
showsPrec :: Int -> ListDataSources -> ShowS
$cshowsPrec :: Int -> ListDataSources -> ShowS
Prelude.Show, forall x. Rep ListDataSources x -> ListDataSources
forall x. ListDataSources -> Rep ListDataSources x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListDataSources x -> ListDataSources
$cfrom :: forall x. ListDataSources -> Rep ListDataSources x
Prelude.Generic)

-- |
-- Create a value of 'ListDataSources' 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', 'listDataSources_maxResults' - The maximum number of results that you want the request to return.
--
-- 'nextToken', 'listDataSources_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', 'listDataSources_apiId' - The API ID.
newListDataSources ::
  -- | 'apiId'
  Prelude.Text ->
  ListDataSources
newListDataSources :: Text -> ListDataSources
newListDataSources Text
pApiId_ =
  ListDataSources'
    { $sel:maxResults:ListDataSources' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListDataSources' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:apiId:ListDataSources' :: Text
apiId = Text
pApiId_
    }

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

-- | 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.
listDataSources_nextToken :: Lens.Lens' ListDataSources (Prelude.Maybe Prelude.Text)
listDataSources_nextToken :: Lens' ListDataSources (Maybe Text)
listDataSources_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDataSources' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListDataSources' :: ListDataSources -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListDataSources
s@ListDataSources' {} Maybe Text
a -> ListDataSources
s {$sel:nextToken:ListDataSources' :: Maybe Text
nextToken = Maybe Text
a} :: ListDataSources)

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

instance Core.AWSPager ListDataSources where
  page :: ListDataSources
-> AWSResponse ListDataSources -> Maybe ListDataSources
page ListDataSources
rq AWSResponse ListDataSources
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListDataSources
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListDataSourcesResponse (Maybe Text)
listDataSourcesResponse_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 ListDataSources
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListDataSourcesResponse (Maybe [DataSource])
listDataSourcesResponse_dataSources
            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.$ ListDataSources
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListDataSources (Maybe Text)
listDataSources_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListDataSources
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListDataSourcesResponse (Maybe Text)
listDataSourcesResponse_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 ListDataSources where
  type
    AWSResponse ListDataSources =
      ListDataSourcesResponse
  request :: (Service -> Service) -> ListDataSources -> Request ListDataSources
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 ListDataSources
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListDataSources)))
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 [DataSource] -> Maybe Text -> Int -> ListDataSourcesResponse
ListDataSourcesResponse'
            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
"dataSources" 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 ListDataSources where
  hashWithSalt :: Int -> ListDataSources -> Int
hashWithSalt Int
_salt ListDataSources' {Maybe Natural
Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:apiId:ListDataSources' :: ListDataSources -> Text
$sel:nextToken:ListDataSources' :: ListDataSources -> Maybe Text
$sel:maxResults:ListDataSources' :: ListDataSources -> 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 ListDataSources where
  rnf :: ListDataSources -> ()
rnf ListDataSources' {Maybe Natural
Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:apiId:ListDataSources' :: ListDataSources -> Text
$sel:nextToken:ListDataSources' :: ListDataSources -> Maybe Text
$sel:maxResults:ListDataSources' :: ListDataSources -> 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 ListDataSources where
  toHeaders :: ListDataSources -> 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 ListDataSources where
  toPath :: ListDataSources -> ByteString
toPath ListDataSources' {Maybe Natural
Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:apiId:ListDataSources' :: ListDataSources -> Text
$sel:nextToken:ListDataSources' :: ListDataSources -> Maybe Text
$sel:maxResults:ListDataSources' :: ListDataSources -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/apis/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
apiId, ByteString
"/datasources"]

instance Data.ToQuery ListDataSources where
  toQuery :: ListDataSources -> QueryString
toQuery ListDataSources' {Maybe Natural
Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:apiId:ListDataSources' :: ListDataSources -> Text
$sel:nextToken:ListDataSources' :: ListDataSources -> Maybe Text
$sel:maxResults:ListDataSources' :: ListDataSources -> 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:/ 'newListDataSourcesResponse' smart constructor.
data ListDataSourcesResponse = ListDataSourcesResponse'
  { -- | The @DataSource@ objects.
    ListDataSourcesResponse -> Maybe [DataSource]
dataSources :: Prelude.Maybe [DataSource],
    -- | An identifier to pass in the next request to this operation to return
    -- the next set of items in the list.
    ListDataSourcesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListDataSourcesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListDataSourcesResponse -> ListDataSourcesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListDataSourcesResponse -> ListDataSourcesResponse -> Bool
$c/= :: ListDataSourcesResponse -> ListDataSourcesResponse -> Bool
== :: ListDataSourcesResponse -> ListDataSourcesResponse -> Bool
$c== :: ListDataSourcesResponse -> ListDataSourcesResponse -> Bool
Prelude.Eq, ReadPrec [ListDataSourcesResponse]
ReadPrec ListDataSourcesResponse
Int -> ReadS ListDataSourcesResponse
ReadS [ListDataSourcesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListDataSourcesResponse]
$creadListPrec :: ReadPrec [ListDataSourcesResponse]
readPrec :: ReadPrec ListDataSourcesResponse
$creadPrec :: ReadPrec ListDataSourcesResponse
readList :: ReadS [ListDataSourcesResponse]
$creadList :: ReadS [ListDataSourcesResponse]
readsPrec :: Int -> ReadS ListDataSourcesResponse
$creadsPrec :: Int -> ReadS ListDataSourcesResponse
Prelude.Read, Int -> ListDataSourcesResponse -> ShowS
[ListDataSourcesResponse] -> ShowS
ListDataSourcesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDataSourcesResponse] -> ShowS
$cshowList :: [ListDataSourcesResponse] -> ShowS
show :: ListDataSourcesResponse -> String
$cshow :: ListDataSourcesResponse -> String
showsPrec :: Int -> ListDataSourcesResponse -> ShowS
$cshowsPrec :: Int -> ListDataSourcesResponse -> ShowS
Prelude.Show, forall x. Rep ListDataSourcesResponse x -> ListDataSourcesResponse
forall x. ListDataSourcesResponse -> Rep ListDataSourcesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListDataSourcesResponse x -> ListDataSourcesResponse
$cfrom :: forall x. ListDataSourcesResponse -> Rep ListDataSourcesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListDataSourcesResponse' 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:
--
-- 'dataSources', 'listDataSourcesResponse_dataSources' - The @DataSource@ objects.
--
-- 'nextToken', 'listDataSourcesResponse_nextToken' - An identifier to pass in the next request to this operation to return
-- the next set of items in the list.
--
-- 'httpStatus', 'listDataSourcesResponse_httpStatus' - The response's http status code.
newListDataSourcesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListDataSourcesResponse
newListDataSourcesResponse :: Int -> ListDataSourcesResponse
newListDataSourcesResponse Int
pHttpStatus_ =
  ListDataSourcesResponse'
    { $sel:dataSources:ListDataSourcesResponse' :: Maybe [DataSource]
dataSources =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListDataSourcesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListDataSourcesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @DataSource@ objects.
listDataSourcesResponse_dataSources :: Lens.Lens' ListDataSourcesResponse (Prelude.Maybe [DataSource])
listDataSourcesResponse_dataSources :: Lens' ListDataSourcesResponse (Maybe [DataSource])
listDataSourcesResponse_dataSources = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDataSourcesResponse' {Maybe [DataSource]
dataSources :: Maybe [DataSource]
$sel:dataSources:ListDataSourcesResponse' :: ListDataSourcesResponse -> Maybe [DataSource]
dataSources} -> Maybe [DataSource]
dataSources) (\s :: ListDataSourcesResponse
s@ListDataSourcesResponse' {} Maybe [DataSource]
a -> ListDataSourcesResponse
s {$sel:dataSources:ListDataSourcesResponse' :: Maybe [DataSource]
dataSources = Maybe [DataSource]
a} :: ListDataSourcesResponse) 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 to pass in the next request to this operation to return
-- the next set of items in the list.
listDataSourcesResponse_nextToken :: Lens.Lens' ListDataSourcesResponse (Prelude.Maybe Prelude.Text)
listDataSourcesResponse_nextToken :: Lens' ListDataSourcesResponse (Maybe Text)
listDataSourcesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDataSourcesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListDataSourcesResponse' :: ListDataSourcesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListDataSourcesResponse
s@ListDataSourcesResponse' {} Maybe Text
a -> ListDataSourcesResponse
s {$sel:nextToken:ListDataSourcesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListDataSourcesResponse)

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

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