{-# 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.RolesAnywhere.ListSubjects
-- 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 subjects in the authenticated account and Amazon Web Services
-- Region.
--
-- __Required permissions:__ @rolesanywhere:ListSubjects@.
--
-- This operation returns paginated results.
module Amazonka.RolesAnywhere.ListSubjects
  ( -- * Creating a Request
    ListSubjects (..),
    newListSubjects,

    -- * Request Lenses
    listSubjects_nextToken,
    listSubjects_pageSize,

    -- * Destructuring the Response
    ListSubjectsResponse (..),
    newListSubjectsResponse,

    -- * Response Lenses
    listSubjectsResponse_nextToken,
    listSubjectsResponse_subjects,
    listSubjectsResponse_httpStatus,
  )
where

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
import Amazonka.RolesAnywhere.Types

-- | /See:/ 'newListSubjects' smart constructor.
data ListSubjects = ListSubjects'
  { -- | A token that indicates where the output should continue from, if a
    -- previous operation did not show all results. To get the next results,
    -- call the operation again with this value.
    ListSubjects -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The number of resources in the paginated list.
    ListSubjects -> Maybe Int
pageSize :: Prelude.Maybe Prelude.Int
  }
  deriving (ListSubjects -> ListSubjects -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListSubjects -> ListSubjects -> Bool
$c/= :: ListSubjects -> ListSubjects -> Bool
== :: ListSubjects -> ListSubjects -> Bool
$c== :: ListSubjects -> ListSubjects -> Bool
Prelude.Eq, ReadPrec [ListSubjects]
ReadPrec ListSubjects
Int -> ReadS ListSubjects
ReadS [ListSubjects]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListSubjects]
$creadListPrec :: ReadPrec [ListSubjects]
readPrec :: ReadPrec ListSubjects
$creadPrec :: ReadPrec ListSubjects
readList :: ReadS [ListSubjects]
$creadList :: ReadS [ListSubjects]
readsPrec :: Int -> ReadS ListSubjects
$creadsPrec :: Int -> ReadS ListSubjects
Prelude.Read, Int -> ListSubjects -> ShowS
[ListSubjects] -> ShowS
ListSubjects -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListSubjects] -> ShowS
$cshowList :: [ListSubjects] -> ShowS
show :: ListSubjects -> String
$cshow :: ListSubjects -> String
showsPrec :: Int -> ListSubjects -> ShowS
$cshowsPrec :: Int -> ListSubjects -> ShowS
Prelude.Show, forall x. Rep ListSubjects x -> ListSubjects
forall x. ListSubjects -> Rep ListSubjects x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListSubjects x -> ListSubjects
$cfrom :: forall x. ListSubjects -> Rep ListSubjects x
Prelude.Generic)

-- |
-- Create a value of 'ListSubjects' 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', 'listSubjects_nextToken' - A token that indicates where the output should continue from, if a
-- previous operation did not show all results. To get the next results,
-- call the operation again with this value.
--
-- 'pageSize', 'listSubjects_pageSize' - The number of resources in the paginated list.
newListSubjects ::
  ListSubjects
newListSubjects :: ListSubjects
newListSubjects =
  ListSubjects'
    { $sel:nextToken:ListSubjects' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:pageSize:ListSubjects' :: Maybe Int
pageSize = forall a. Maybe a
Prelude.Nothing
    }

-- | A token that indicates where the output should continue from, if a
-- previous operation did not show all results. To get the next results,
-- call the operation again with this value.
listSubjects_nextToken :: Lens.Lens' ListSubjects (Prelude.Maybe Prelude.Text)
listSubjects_nextToken :: Lens' ListSubjects (Maybe Text)
listSubjects_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListSubjects' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListSubjects' :: ListSubjects -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListSubjects
s@ListSubjects' {} Maybe Text
a -> ListSubjects
s {$sel:nextToken:ListSubjects' :: Maybe Text
nextToken = Maybe Text
a} :: ListSubjects)

-- | The number of resources in the paginated list.
listSubjects_pageSize :: Lens.Lens' ListSubjects (Prelude.Maybe Prelude.Int)
listSubjects_pageSize :: Lens' ListSubjects (Maybe Int)
listSubjects_pageSize = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListSubjects' {Maybe Int
pageSize :: Maybe Int
$sel:pageSize:ListSubjects' :: ListSubjects -> Maybe Int
pageSize} -> Maybe Int
pageSize) (\s :: ListSubjects
s@ListSubjects' {} Maybe Int
a -> ListSubjects
s {$sel:pageSize:ListSubjects' :: Maybe Int
pageSize = Maybe Int
a} :: ListSubjects)

instance Core.AWSPager ListSubjects where
  page :: ListSubjects -> AWSResponse ListSubjects -> Maybe ListSubjects
page ListSubjects
rq AWSResponse ListSubjects
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListSubjects
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListSubjectsResponse (Maybe Text)
listSubjectsResponse_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 ListSubjects
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListSubjectsResponse (Maybe [SubjectSummary])
listSubjectsResponse_subjects
            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.$ ListSubjects
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListSubjects (Maybe Text)
listSubjects_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListSubjects
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListSubjectsResponse (Maybe Text)
listSubjectsResponse_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 ListSubjects where
  type AWSResponse ListSubjects = ListSubjectsResponse
  request :: (Service -> Service) -> ListSubjects -> Request ListSubjects
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 ListSubjects
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListSubjects)))
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 [SubjectSummary] -> Int -> ListSubjectsResponse
ListSubjectsResponse'
            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.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"subjects" 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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListSubjects where
  hashWithSalt :: Int -> ListSubjects -> Int
hashWithSalt Int
_salt ListSubjects' {Maybe Int
Maybe Text
pageSize :: Maybe Int
nextToken :: Maybe Text
$sel:pageSize:ListSubjects' :: ListSubjects -> Maybe Int
$sel:nextToken:ListSubjects' :: ListSubjects -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
pageSize

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

instance Data.ToHeaders ListSubjects where
  toHeaders :: ListSubjects -> 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 ListSubjects where
  toPath :: ListSubjects -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/subjects"

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

-- | /See:/ 'newListSubjectsResponse' smart constructor.
data ListSubjectsResponse = ListSubjectsResponse'
  { -- | A token that indicates where the output should continue from, if a
    -- previous operation did not show all results. To get the next results,
    -- call the operation again with this value.
    ListSubjectsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of subjects.
    ListSubjectsResponse -> Maybe [SubjectSummary]
subjects :: Prelude.Maybe [SubjectSummary],
    -- | The response's http status code.
    ListSubjectsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListSubjectsResponse -> ListSubjectsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListSubjectsResponse -> ListSubjectsResponse -> Bool
$c/= :: ListSubjectsResponse -> ListSubjectsResponse -> Bool
== :: ListSubjectsResponse -> ListSubjectsResponse -> Bool
$c== :: ListSubjectsResponse -> ListSubjectsResponse -> Bool
Prelude.Eq, ReadPrec [ListSubjectsResponse]
ReadPrec ListSubjectsResponse
Int -> ReadS ListSubjectsResponse
ReadS [ListSubjectsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListSubjectsResponse]
$creadListPrec :: ReadPrec [ListSubjectsResponse]
readPrec :: ReadPrec ListSubjectsResponse
$creadPrec :: ReadPrec ListSubjectsResponse
readList :: ReadS [ListSubjectsResponse]
$creadList :: ReadS [ListSubjectsResponse]
readsPrec :: Int -> ReadS ListSubjectsResponse
$creadsPrec :: Int -> ReadS ListSubjectsResponse
Prelude.Read, Int -> ListSubjectsResponse -> ShowS
[ListSubjectsResponse] -> ShowS
ListSubjectsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListSubjectsResponse] -> ShowS
$cshowList :: [ListSubjectsResponse] -> ShowS
show :: ListSubjectsResponse -> String
$cshow :: ListSubjectsResponse -> String
showsPrec :: Int -> ListSubjectsResponse -> ShowS
$cshowsPrec :: Int -> ListSubjectsResponse -> ShowS
Prelude.Show, forall x. Rep ListSubjectsResponse x -> ListSubjectsResponse
forall x. ListSubjectsResponse -> Rep ListSubjectsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListSubjectsResponse x -> ListSubjectsResponse
$cfrom :: forall x. ListSubjectsResponse -> Rep ListSubjectsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListSubjectsResponse' 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', 'listSubjectsResponse_nextToken' - A token that indicates where the output should continue from, if a
-- previous operation did not show all results. To get the next results,
-- call the operation again with this value.
--
-- 'subjects', 'listSubjectsResponse_subjects' - A list of subjects.
--
-- 'httpStatus', 'listSubjectsResponse_httpStatus' - The response's http status code.
newListSubjectsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListSubjectsResponse
newListSubjectsResponse :: Int -> ListSubjectsResponse
newListSubjectsResponse Int
pHttpStatus_ =
  ListSubjectsResponse'
    { $sel:nextToken:ListSubjectsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:subjects:ListSubjectsResponse' :: Maybe [SubjectSummary]
subjects = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListSubjectsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A token that indicates where the output should continue from, if a
-- previous operation did not show all results. To get the next results,
-- call the operation again with this value.
listSubjectsResponse_nextToken :: Lens.Lens' ListSubjectsResponse (Prelude.Maybe Prelude.Text)
listSubjectsResponse_nextToken :: Lens' ListSubjectsResponse (Maybe Text)
listSubjectsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListSubjectsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListSubjectsResponse' :: ListSubjectsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListSubjectsResponse
s@ListSubjectsResponse' {} Maybe Text
a -> ListSubjectsResponse
s {$sel:nextToken:ListSubjectsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListSubjectsResponse)

-- | A list of subjects.
listSubjectsResponse_subjects :: Lens.Lens' ListSubjectsResponse (Prelude.Maybe [SubjectSummary])
listSubjectsResponse_subjects :: Lens' ListSubjectsResponse (Maybe [SubjectSummary])
listSubjectsResponse_subjects = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListSubjectsResponse' {Maybe [SubjectSummary]
subjects :: Maybe [SubjectSummary]
$sel:subjects:ListSubjectsResponse' :: ListSubjectsResponse -> Maybe [SubjectSummary]
subjects} -> Maybe [SubjectSummary]
subjects) (\s :: ListSubjectsResponse
s@ListSubjectsResponse' {} Maybe [SubjectSummary]
a -> ListSubjectsResponse
s {$sel:subjects:ListSubjectsResponse' :: Maybe [SubjectSummary]
subjects = Maybe [SubjectSummary]
a} :: ListSubjectsResponse) 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 response's http status code.
listSubjectsResponse_httpStatus :: Lens.Lens' ListSubjectsResponse Prelude.Int
listSubjectsResponse_httpStatus :: Lens' ListSubjectsResponse Int
listSubjectsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListSubjectsResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListSubjectsResponse' :: ListSubjectsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListSubjectsResponse
s@ListSubjectsResponse' {} Int
a -> ListSubjectsResponse
s {$sel:httpStatus:ListSubjectsResponse' :: Int
httpStatus = Int
a} :: ListSubjectsResponse)

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