{-# 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.Inspector2.ListMembers
-- 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 members associated with the Amazon Inspector delegated
-- administrator for your organization.
--
-- This operation returns paginated results.
module Amazonka.Inspector2.ListMembers
  ( -- * Creating a Request
    ListMembers (..),
    newListMembers,

    -- * Request Lenses
    listMembers_maxResults,
    listMembers_nextToken,
    listMembers_onlyAssociated,

    -- * Destructuring the Response
    ListMembersResponse (..),
    newListMembersResponse,

    -- * Response Lenses
    listMembersResponse_members,
    listMembersResponse_nextToken,
    listMembersResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListMembers' smart constructor.
data ListMembers = ListMembers'
  { -- | The maximum number of results to return in the response.
    ListMembers -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A token to use for paginating results that are returned in the response.
    -- Set the value of this parameter to null for the first request to a list
    -- action. For subsequent calls, use the @NextToken@ value returned from
    -- the previous request to continue listing results after the first page.
    ListMembers -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Specifies whether to list only currently associated members if @True@ or
    -- to list all members within the organization if @False@.
    ListMembers -> Maybe Bool
onlyAssociated :: Prelude.Maybe Prelude.Bool
  }
  deriving (ListMembers -> ListMembers -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListMembers -> ListMembers -> Bool
$c/= :: ListMembers -> ListMembers -> Bool
== :: ListMembers -> ListMembers -> Bool
$c== :: ListMembers -> ListMembers -> Bool
Prelude.Eq, ReadPrec [ListMembers]
ReadPrec ListMembers
Int -> ReadS ListMembers
ReadS [ListMembers]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListMembers]
$creadListPrec :: ReadPrec [ListMembers]
readPrec :: ReadPrec ListMembers
$creadPrec :: ReadPrec ListMembers
readList :: ReadS [ListMembers]
$creadList :: ReadS [ListMembers]
readsPrec :: Int -> ReadS ListMembers
$creadsPrec :: Int -> ReadS ListMembers
Prelude.Read, Int -> ListMembers -> ShowS
[ListMembers] -> ShowS
ListMembers -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListMembers] -> ShowS
$cshowList :: [ListMembers] -> ShowS
show :: ListMembers -> String
$cshow :: ListMembers -> String
showsPrec :: Int -> ListMembers -> ShowS
$cshowsPrec :: Int -> ListMembers -> ShowS
Prelude.Show, forall x. Rep ListMembers x -> ListMembers
forall x. ListMembers -> Rep ListMembers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListMembers x -> ListMembers
$cfrom :: forall x. ListMembers -> Rep ListMembers x
Prelude.Generic)

-- |
-- Create a value of 'ListMembers' 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', 'listMembers_maxResults' - The maximum number of results to return in the response.
--
-- 'nextToken', 'listMembers_nextToken' - A token to use for paginating results that are returned in the response.
-- Set the value of this parameter to null for the first request to a list
-- action. For subsequent calls, use the @NextToken@ value returned from
-- the previous request to continue listing results after the first page.
--
-- 'onlyAssociated', 'listMembers_onlyAssociated' - Specifies whether to list only currently associated members if @True@ or
-- to list all members within the organization if @False@.
newListMembers ::
  ListMembers
newListMembers :: ListMembers
newListMembers =
  ListMembers'
    { $sel:maxResults:ListMembers' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListMembers' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:onlyAssociated:ListMembers' :: Maybe Bool
onlyAssociated = forall a. Maybe a
Prelude.Nothing
    }

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

-- | A token to use for paginating results that are returned in the response.
-- Set the value of this parameter to null for the first request to a list
-- action. For subsequent calls, use the @NextToken@ value returned from
-- the previous request to continue listing results after the first page.
listMembers_nextToken :: Lens.Lens' ListMembers (Prelude.Maybe Prelude.Text)
listMembers_nextToken :: Lens' ListMembers (Maybe Text)
listMembers_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListMembers' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListMembers' :: ListMembers -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListMembers
s@ListMembers' {} Maybe Text
a -> ListMembers
s {$sel:nextToken:ListMembers' :: Maybe Text
nextToken = Maybe Text
a} :: ListMembers)

-- | Specifies whether to list only currently associated members if @True@ or
-- to list all members within the organization if @False@.
listMembers_onlyAssociated :: Lens.Lens' ListMembers (Prelude.Maybe Prelude.Bool)
listMembers_onlyAssociated :: Lens' ListMembers (Maybe Bool)
listMembers_onlyAssociated = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListMembers' {Maybe Bool
onlyAssociated :: Maybe Bool
$sel:onlyAssociated:ListMembers' :: ListMembers -> Maybe Bool
onlyAssociated} -> Maybe Bool
onlyAssociated) (\s :: ListMembers
s@ListMembers' {} Maybe Bool
a -> ListMembers
s {$sel:onlyAssociated:ListMembers' :: Maybe Bool
onlyAssociated = Maybe Bool
a} :: ListMembers)

instance Core.AWSPager ListMembers where
  page :: ListMembers -> AWSResponse ListMembers -> Maybe ListMembers
page ListMembers
rq AWSResponse ListMembers
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListMembers
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListMembersResponse (Maybe Text)
listMembersResponse_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 ListMembers
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListMembersResponse (Maybe [Member])
listMembersResponse_members
            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.$ ListMembers
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListMembers (Maybe Text)
listMembers_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListMembers
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListMembersResponse (Maybe Text)
listMembersResponse_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 ListMembers where
  type AWSResponse ListMembers = ListMembersResponse
  request :: (Service -> Service) -> ListMembers -> Request ListMembers
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 ListMembers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListMembers)))
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 [Member] -> Maybe Text -> Int -> ListMembersResponse
ListMembersResponse'
            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
"members" 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 ListMembers where
  hashWithSalt :: Int -> ListMembers -> Int
hashWithSalt Int
_salt ListMembers' {Maybe Bool
Maybe Natural
Maybe Text
onlyAssociated :: Maybe Bool
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:onlyAssociated:ListMembers' :: ListMembers -> Maybe Bool
$sel:nextToken:ListMembers' :: ListMembers -> Maybe Text
$sel:maxResults:ListMembers' :: ListMembers -> 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` Maybe Bool
onlyAssociated

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

instance Data.ToHeaders ListMembers where
  toHeaders :: ListMembers -> 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.ToJSON ListMembers where
  toJSON :: ListMembers -> Value
toJSON ListMembers' {Maybe Bool
Maybe Natural
Maybe Text
onlyAssociated :: Maybe Bool
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:onlyAssociated:ListMembers' :: ListMembers -> Maybe Bool
$sel:nextToken:ListMembers' :: ListMembers -> Maybe Text
$sel:maxResults:ListMembers' :: ListMembers -> 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,
            (Key
"onlyAssociated" 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 Bool
onlyAssociated
          ]
      )

instance Data.ToPath ListMembers where
  toPath :: ListMembers -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/members/list"

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

-- | /See:/ 'newListMembersResponse' smart constructor.
data ListMembersResponse = ListMembersResponse'
  { -- | An object that contains details for each member account.
    ListMembersResponse -> Maybe [Member]
members :: Prelude.Maybe [Member],
    -- | The pagination parameter to be used on the next list operation to
    -- retrieve more items.
    ListMembersResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListMembersResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListMembersResponse -> ListMembersResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListMembersResponse -> ListMembersResponse -> Bool
$c/= :: ListMembersResponse -> ListMembersResponse -> Bool
== :: ListMembersResponse -> ListMembersResponse -> Bool
$c== :: ListMembersResponse -> ListMembersResponse -> Bool
Prelude.Eq, ReadPrec [ListMembersResponse]
ReadPrec ListMembersResponse
Int -> ReadS ListMembersResponse
ReadS [ListMembersResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListMembersResponse]
$creadListPrec :: ReadPrec [ListMembersResponse]
readPrec :: ReadPrec ListMembersResponse
$creadPrec :: ReadPrec ListMembersResponse
readList :: ReadS [ListMembersResponse]
$creadList :: ReadS [ListMembersResponse]
readsPrec :: Int -> ReadS ListMembersResponse
$creadsPrec :: Int -> ReadS ListMembersResponse
Prelude.Read, Int -> ListMembersResponse -> ShowS
[ListMembersResponse] -> ShowS
ListMembersResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListMembersResponse] -> ShowS
$cshowList :: [ListMembersResponse] -> ShowS
show :: ListMembersResponse -> String
$cshow :: ListMembersResponse -> String
showsPrec :: Int -> ListMembersResponse -> ShowS
$cshowsPrec :: Int -> ListMembersResponse -> ShowS
Prelude.Show, forall x. Rep ListMembersResponse x -> ListMembersResponse
forall x. ListMembersResponse -> Rep ListMembersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListMembersResponse x -> ListMembersResponse
$cfrom :: forall x. ListMembersResponse -> Rep ListMembersResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListMembersResponse' 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:
--
-- 'members', 'listMembersResponse_members' - An object that contains details for each member account.
--
-- 'nextToken', 'listMembersResponse_nextToken' - The pagination parameter to be used on the next list operation to
-- retrieve more items.
--
-- 'httpStatus', 'listMembersResponse_httpStatus' - The response's http status code.
newListMembersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListMembersResponse
newListMembersResponse :: Int -> ListMembersResponse
newListMembersResponse Int
pHttpStatus_ =
  ListMembersResponse'
    { $sel:members:ListMembersResponse' :: Maybe [Member]
members = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListMembersResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListMembersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An object that contains details for each member account.
listMembersResponse_members :: Lens.Lens' ListMembersResponse (Prelude.Maybe [Member])
listMembersResponse_members :: Lens' ListMembersResponse (Maybe [Member])
listMembersResponse_members = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListMembersResponse' {Maybe [Member]
members :: Maybe [Member]
$sel:members:ListMembersResponse' :: ListMembersResponse -> Maybe [Member]
members} -> Maybe [Member]
members) (\s :: ListMembersResponse
s@ListMembersResponse' {} Maybe [Member]
a -> ListMembersResponse
s {$sel:members:ListMembersResponse' :: Maybe [Member]
members = Maybe [Member]
a} :: ListMembersResponse) 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 pagination parameter to be used on the next list operation to
-- retrieve more items.
listMembersResponse_nextToken :: Lens.Lens' ListMembersResponse (Prelude.Maybe Prelude.Text)
listMembersResponse_nextToken :: Lens' ListMembersResponse (Maybe Text)
listMembersResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListMembersResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListMembersResponse' :: ListMembersResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListMembersResponse
s@ListMembersResponse' {} Maybe Text
a -> ListMembersResponse
s {$sel:nextToken:ListMembersResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListMembersResponse)

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

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