{-# 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.IoT.ListIndices
-- 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 search indices.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions ListIndices>
-- action.
--
-- This operation returns paginated results.
module Amazonka.IoT.ListIndices
  ( -- * Creating a Request
    ListIndices (..),
    newListIndices,

    -- * Request Lenses
    listIndices_maxResults,
    listIndices_nextToken,

    -- * Destructuring the Response
    ListIndicesResponse (..),
    newListIndicesResponse,

    -- * Response Lenses
    listIndicesResponse_indexNames,
    listIndicesResponse_nextToken,
    listIndicesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListIndices' smart constructor.
data ListIndices = ListIndices'
  { -- | The maximum number of results to return at one time.
    ListIndices -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token used to get the next set of results, or @null@ if there are no
    -- additional results.
    ListIndices -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListIndices -> ListIndices -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListIndices -> ListIndices -> Bool
$c/= :: ListIndices -> ListIndices -> Bool
== :: ListIndices -> ListIndices -> Bool
$c== :: ListIndices -> ListIndices -> Bool
Prelude.Eq, ReadPrec [ListIndices]
ReadPrec ListIndices
Int -> ReadS ListIndices
ReadS [ListIndices]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListIndices]
$creadListPrec :: ReadPrec [ListIndices]
readPrec :: ReadPrec ListIndices
$creadPrec :: ReadPrec ListIndices
readList :: ReadS [ListIndices]
$creadList :: ReadS [ListIndices]
readsPrec :: Int -> ReadS ListIndices
$creadsPrec :: Int -> ReadS ListIndices
Prelude.Read, Int -> ListIndices -> ShowS
[ListIndices] -> ShowS
ListIndices -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListIndices] -> ShowS
$cshowList :: [ListIndices] -> ShowS
show :: ListIndices -> String
$cshow :: ListIndices -> String
showsPrec :: Int -> ListIndices -> ShowS
$cshowsPrec :: Int -> ListIndices -> ShowS
Prelude.Show, forall x. Rep ListIndices x -> ListIndices
forall x. ListIndices -> Rep ListIndices x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListIndices x -> ListIndices
$cfrom :: forall x. ListIndices -> Rep ListIndices x
Prelude.Generic)

-- |
-- Create a value of 'ListIndices' 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', 'listIndices_maxResults' - The maximum number of results to return at one time.
--
-- 'nextToken', 'listIndices_nextToken' - The token used to get the next set of results, or @null@ if there are no
-- additional results.
newListIndices ::
  ListIndices
newListIndices :: ListIndices
newListIndices =
  ListIndices'
    { $sel:maxResults:ListIndices' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListIndices' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of results to return at one time.
listIndices_maxResults :: Lens.Lens' ListIndices (Prelude.Maybe Prelude.Natural)
listIndices_maxResults :: Lens' ListIndices (Maybe Natural)
listIndices_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIndices' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListIndices' :: ListIndices -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListIndices
s@ListIndices' {} Maybe Natural
a -> ListIndices
s {$sel:maxResults:ListIndices' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListIndices)

-- | The token used to get the next set of results, or @null@ if there are no
-- additional results.
listIndices_nextToken :: Lens.Lens' ListIndices (Prelude.Maybe Prelude.Text)
listIndices_nextToken :: Lens' ListIndices (Maybe Text)
listIndices_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIndices' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListIndices' :: ListIndices -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListIndices
s@ListIndices' {} Maybe Text
a -> ListIndices
s {$sel:nextToken:ListIndices' :: Maybe Text
nextToken = Maybe Text
a} :: ListIndices)

instance Core.AWSPager ListIndices where
  page :: ListIndices -> AWSResponse ListIndices -> Maybe ListIndices
page ListIndices
rq AWSResponse ListIndices
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListIndices
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListIndicesResponse (Maybe Text)
listIndicesResponse_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 ListIndices
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListIndicesResponse (Maybe [Text])
listIndicesResponse_indexNames
            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.$ ListIndices
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListIndices (Maybe Text)
listIndices_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListIndices
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListIndicesResponse (Maybe Text)
listIndicesResponse_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 ListIndices where
  type AWSResponse ListIndices = ListIndicesResponse
  request :: (Service -> Service) -> ListIndices -> Request ListIndices
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 ListIndices
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListIndices)))
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] -> Maybe Text -> Int -> ListIndicesResponse
ListIndicesResponse'
            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
"indexNames" 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 ListIndices where
  hashWithSalt :: Int -> ListIndices -> Int
hashWithSalt Int
_salt ListIndices' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListIndices' :: ListIndices -> Maybe Text
$sel:maxResults:ListIndices' :: ListIndices -> 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 ListIndices where
  rnf :: ListIndices -> ()
rnf ListIndices' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListIndices' :: ListIndices -> Maybe Text
$sel:maxResults:ListIndices' :: ListIndices -> 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 ListIndices where
  toHeaders :: ListIndices -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToQuery ListIndices where
  toQuery :: ListIndices -> QueryString
toQuery ListIndices' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListIndices' :: ListIndices -> Maybe Text
$sel:maxResults:ListIndices' :: ListIndices -> 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:/ 'newListIndicesResponse' smart constructor.
data ListIndicesResponse = ListIndicesResponse'
  { -- | The index names.
    ListIndicesResponse -> Maybe [Text]
indexNames :: Prelude.Maybe [Prelude.Text],
    -- | The token used to get the next set of results, or @null@ if there are no
    -- additional results.
    ListIndicesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListIndicesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListIndicesResponse -> ListIndicesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListIndicesResponse -> ListIndicesResponse -> Bool
$c/= :: ListIndicesResponse -> ListIndicesResponse -> Bool
== :: ListIndicesResponse -> ListIndicesResponse -> Bool
$c== :: ListIndicesResponse -> ListIndicesResponse -> Bool
Prelude.Eq, ReadPrec [ListIndicesResponse]
ReadPrec ListIndicesResponse
Int -> ReadS ListIndicesResponse
ReadS [ListIndicesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListIndicesResponse]
$creadListPrec :: ReadPrec [ListIndicesResponse]
readPrec :: ReadPrec ListIndicesResponse
$creadPrec :: ReadPrec ListIndicesResponse
readList :: ReadS [ListIndicesResponse]
$creadList :: ReadS [ListIndicesResponse]
readsPrec :: Int -> ReadS ListIndicesResponse
$creadsPrec :: Int -> ReadS ListIndicesResponse
Prelude.Read, Int -> ListIndicesResponse -> ShowS
[ListIndicesResponse] -> ShowS
ListIndicesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListIndicesResponse] -> ShowS
$cshowList :: [ListIndicesResponse] -> ShowS
show :: ListIndicesResponse -> String
$cshow :: ListIndicesResponse -> String
showsPrec :: Int -> ListIndicesResponse -> ShowS
$cshowsPrec :: Int -> ListIndicesResponse -> ShowS
Prelude.Show, forall x. Rep ListIndicesResponse x -> ListIndicesResponse
forall x. ListIndicesResponse -> Rep ListIndicesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListIndicesResponse x -> ListIndicesResponse
$cfrom :: forall x. ListIndicesResponse -> Rep ListIndicesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListIndicesResponse' 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:
--
-- 'indexNames', 'listIndicesResponse_indexNames' - The index names.
--
-- 'nextToken', 'listIndicesResponse_nextToken' - The token used to get the next set of results, or @null@ if there are no
-- additional results.
--
-- 'httpStatus', 'listIndicesResponse_httpStatus' - The response's http status code.
newListIndicesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListIndicesResponse
newListIndicesResponse :: Int -> ListIndicesResponse
newListIndicesResponse Int
pHttpStatus_ =
  ListIndicesResponse'
    { $sel:indexNames:ListIndicesResponse' :: Maybe [Text]
indexNames = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListIndicesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListIndicesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The index names.
listIndicesResponse_indexNames :: Lens.Lens' ListIndicesResponse (Prelude.Maybe [Prelude.Text])
listIndicesResponse_indexNames :: Lens' ListIndicesResponse (Maybe [Text])
listIndicesResponse_indexNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIndicesResponse' {Maybe [Text]
indexNames :: Maybe [Text]
$sel:indexNames:ListIndicesResponse' :: ListIndicesResponse -> Maybe [Text]
indexNames} -> Maybe [Text]
indexNames) (\s :: ListIndicesResponse
s@ListIndicesResponse' {} Maybe [Text]
a -> ListIndicesResponse
s {$sel:indexNames:ListIndicesResponse' :: Maybe [Text]
indexNames = Maybe [Text]
a} :: ListIndicesResponse) 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 token used to get the next set of results, or @null@ if there are no
-- additional results.
listIndicesResponse_nextToken :: Lens.Lens' ListIndicesResponse (Prelude.Maybe Prelude.Text)
listIndicesResponse_nextToken :: Lens' ListIndicesResponse (Maybe Text)
listIndicesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListIndicesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListIndicesResponse' :: ListIndicesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListIndicesResponse
s@ListIndicesResponse' {} Maybe Text
a -> ListIndicesResponse
s {$sel:nextToken:ListIndicesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListIndicesResponse)

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

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