{-# 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.Forecast.ListDatasets
-- 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 datasets created using the
-- <https://docs.aws.amazon.com/forecast/latest/dg/API_CreateDataset.html CreateDataset>
-- operation. For each dataset, a summary of its properties, including its
-- Amazon Resource Name (ARN), is returned. To retrieve the complete set of
-- properties, use the ARN with the
-- <https://docs.aws.amazon.com/forecast/latest/dg/API_DescribeDataset.html DescribeDataset>
-- operation.
--
-- This operation returns paginated results.
module Amazonka.Forecast.ListDatasets
  ( -- * Creating a Request
    ListDatasets (..),
    newListDatasets,

    -- * Request Lenses
    listDatasets_maxResults,
    listDatasets_nextToken,

    -- * Destructuring the Response
    ListDatasetsResponse (..),
    newListDatasetsResponse,

    -- * Response Lenses
    listDatasetsResponse_datasets,
    listDatasetsResponse_nextToken,
    listDatasetsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListDatasets' smart constructor.
data ListDatasets = ListDatasets'
  { -- | The number of items to return in the response.
    ListDatasets -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | If the result of the previous request was truncated, the response
    -- includes a @NextToken@. To retrieve the next set of results, use the
    -- token in the next request. Tokens expire after 24 hours.
    ListDatasets -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListDatasets -> ListDatasets -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListDatasets -> ListDatasets -> Bool
$c/= :: ListDatasets -> ListDatasets -> Bool
== :: ListDatasets -> ListDatasets -> Bool
$c== :: ListDatasets -> ListDatasets -> Bool
Prelude.Eq, ReadPrec [ListDatasets]
ReadPrec ListDatasets
Int -> ReadS ListDatasets
ReadS [ListDatasets]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListDatasets]
$creadListPrec :: ReadPrec [ListDatasets]
readPrec :: ReadPrec ListDatasets
$creadPrec :: ReadPrec ListDatasets
readList :: ReadS [ListDatasets]
$creadList :: ReadS [ListDatasets]
readsPrec :: Int -> ReadS ListDatasets
$creadsPrec :: Int -> ReadS ListDatasets
Prelude.Read, Int -> ListDatasets -> ShowS
[ListDatasets] -> ShowS
ListDatasets -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDatasets] -> ShowS
$cshowList :: [ListDatasets] -> ShowS
show :: ListDatasets -> String
$cshow :: ListDatasets -> String
showsPrec :: Int -> ListDatasets -> ShowS
$cshowsPrec :: Int -> ListDatasets -> ShowS
Prelude.Show, forall x. Rep ListDatasets x -> ListDatasets
forall x. ListDatasets -> Rep ListDatasets x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListDatasets x -> ListDatasets
$cfrom :: forall x. ListDatasets -> Rep ListDatasets x
Prelude.Generic)

-- |
-- Create a value of 'ListDatasets' 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', 'listDatasets_maxResults' - The number of items to return in the response.
--
-- 'nextToken', 'listDatasets_nextToken' - If the result of the previous request was truncated, the response
-- includes a @NextToken@. To retrieve the next set of results, use the
-- token in the next request. Tokens expire after 24 hours.
newListDatasets ::
  ListDatasets
newListDatasets :: ListDatasets
newListDatasets =
  ListDatasets'
    { $sel:maxResults:ListDatasets' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListDatasets' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The number of items to return in the response.
listDatasets_maxResults :: Lens.Lens' ListDatasets (Prelude.Maybe Prelude.Natural)
listDatasets_maxResults :: Lens' ListDatasets (Maybe Natural)
listDatasets_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatasets' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListDatasets' :: ListDatasets -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListDatasets
s@ListDatasets' {} Maybe Natural
a -> ListDatasets
s {$sel:maxResults:ListDatasets' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListDatasets)

-- | If the result of the previous request was truncated, the response
-- includes a @NextToken@. To retrieve the next set of results, use the
-- token in the next request. Tokens expire after 24 hours.
listDatasets_nextToken :: Lens.Lens' ListDatasets (Prelude.Maybe Prelude.Text)
listDatasets_nextToken :: Lens' ListDatasets (Maybe Text)
listDatasets_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatasets' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListDatasets' :: ListDatasets -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListDatasets
s@ListDatasets' {} Maybe Text
a -> ListDatasets
s {$sel:nextToken:ListDatasets' :: Maybe Text
nextToken = Maybe Text
a} :: ListDatasets)

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

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

instance Data.ToHeaders ListDatasets where
  toHeaders :: ListDatasets -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AmazonForecast.ListDatasets" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListDatasets where
  toJSON :: ListDatasets -> Value
toJSON ListDatasets' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListDatasets' :: ListDatasets -> Maybe Text
$sel:maxResults:ListDatasets' :: ListDatasets -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxResults" 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 Natural
maxResults,
            (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 ListDatasets where
  toPath :: ListDatasets -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListDatasetsResponse' smart constructor.
data ListDatasetsResponse = ListDatasetsResponse'
  { -- | An array of objects that summarize each dataset\'s properties.
    ListDatasetsResponse -> Maybe [DatasetSummary]
datasets :: Prelude.Maybe [DatasetSummary],
    -- | If the response is truncated, Amazon Forecast returns this token. To
    -- retrieve the next set of results, use the token in the next request.
    ListDatasetsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListDatasetsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListDatasetsResponse -> ListDatasetsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListDatasetsResponse -> ListDatasetsResponse -> Bool
$c/= :: ListDatasetsResponse -> ListDatasetsResponse -> Bool
== :: ListDatasetsResponse -> ListDatasetsResponse -> Bool
$c== :: ListDatasetsResponse -> ListDatasetsResponse -> Bool
Prelude.Eq, ReadPrec [ListDatasetsResponse]
ReadPrec ListDatasetsResponse
Int -> ReadS ListDatasetsResponse
ReadS [ListDatasetsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListDatasetsResponse]
$creadListPrec :: ReadPrec [ListDatasetsResponse]
readPrec :: ReadPrec ListDatasetsResponse
$creadPrec :: ReadPrec ListDatasetsResponse
readList :: ReadS [ListDatasetsResponse]
$creadList :: ReadS [ListDatasetsResponse]
readsPrec :: Int -> ReadS ListDatasetsResponse
$creadsPrec :: Int -> ReadS ListDatasetsResponse
Prelude.Read, Int -> ListDatasetsResponse -> ShowS
[ListDatasetsResponse] -> ShowS
ListDatasetsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDatasetsResponse] -> ShowS
$cshowList :: [ListDatasetsResponse] -> ShowS
show :: ListDatasetsResponse -> String
$cshow :: ListDatasetsResponse -> String
showsPrec :: Int -> ListDatasetsResponse -> ShowS
$cshowsPrec :: Int -> ListDatasetsResponse -> ShowS
Prelude.Show, forall x. Rep ListDatasetsResponse x -> ListDatasetsResponse
forall x. ListDatasetsResponse -> Rep ListDatasetsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListDatasetsResponse x -> ListDatasetsResponse
$cfrom :: forall x. ListDatasetsResponse -> Rep ListDatasetsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListDatasetsResponse' 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:
--
-- 'datasets', 'listDatasetsResponse_datasets' - An array of objects that summarize each dataset\'s properties.
--
-- 'nextToken', 'listDatasetsResponse_nextToken' - If the response is truncated, Amazon Forecast returns this token. To
-- retrieve the next set of results, use the token in the next request.
--
-- 'httpStatus', 'listDatasetsResponse_httpStatus' - The response's http status code.
newListDatasetsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListDatasetsResponse
newListDatasetsResponse :: Int -> ListDatasetsResponse
newListDatasetsResponse Int
pHttpStatus_ =
  ListDatasetsResponse'
    { $sel:datasets:ListDatasetsResponse' :: Maybe [DatasetSummary]
datasets = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListDatasetsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListDatasetsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that summarize each dataset\'s properties.
listDatasetsResponse_datasets :: Lens.Lens' ListDatasetsResponse (Prelude.Maybe [DatasetSummary])
listDatasetsResponse_datasets :: Lens' ListDatasetsResponse (Maybe [DatasetSummary])
listDatasetsResponse_datasets = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatasetsResponse' {Maybe [DatasetSummary]
datasets :: Maybe [DatasetSummary]
$sel:datasets:ListDatasetsResponse' :: ListDatasetsResponse -> Maybe [DatasetSummary]
datasets} -> Maybe [DatasetSummary]
datasets) (\s :: ListDatasetsResponse
s@ListDatasetsResponse' {} Maybe [DatasetSummary]
a -> ListDatasetsResponse
s {$sel:datasets:ListDatasetsResponse' :: Maybe [DatasetSummary]
datasets = Maybe [DatasetSummary]
a} :: ListDatasetsResponse) 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

-- | If the response is truncated, Amazon Forecast returns this token. To
-- retrieve the next set of results, use the token in the next request.
listDatasetsResponse_nextToken :: Lens.Lens' ListDatasetsResponse (Prelude.Maybe Prelude.Text)
listDatasetsResponse_nextToken :: Lens' ListDatasetsResponse (Maybe Text)
listDatasetsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatasetsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListDatasetsResponse' :: ListDatasetsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListDatasetsResponse
s@ListDatasetsResponse' {} Maybe Text
a -> ListDatasetsResponse
s {$sel:nextToken:ListDatasetsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListDatasetsResponse)

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

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