{-# 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.CloudHSM.ListHapgs
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- This is documentation for __AWS CloudHSM Classic__. For more
-- information, see
-- <http://aws.amazon.com/cloudhsm/faqs-classic/ AWS CloudHSM Classic FAQs>,
-- the
-- <https://docs.aws.amazon.com/cloudhsm/classic/userguide/ AWS CloudHSM Classic User Guide>,
-- and the
-- <https://docs.aws.amazon.com/cloudhsm/classic/APIReference/ AWS CloudHSM Classic API Reference>.
--
-- __For information about the current version of AWS CloudHSM__, see
-- <http://aws.amazon.com/cloudhsm/ AWS CloudHSM>, the
-- <https://docs.aws.amazon.com/cloudhsm/latest/userguide/ AWS CloudHSM User Guide>,
-- and the
-- <https://docs.aws.amazon.com/cloudhsm/latest/APIReference/ AWS CloudHSM API Reference>.
--
-- Lists the high-availability partition groups for the account.
--
-- This operation supports pagination with the use of the @NextToken@
-- member. If more results are available, the @NextToken@ member of the
-- response contains a token that you pass in the next call to @ListHapgs@
-- to retrieve the next set of items.
--
-- This operation returns paginated results.
module Amazonka.CloudHSM.ListHapgs
  ( -- * Creating a Request
    ListHapgs (..),
    newListHapgs,

    -- * Request Lenses
    listHapgs_nextToken,

    -- * Destructuring the Response
    ListHapgsResponse (..),
    newListHapgsResponse,

    -- * Response Lenses
    listHapgsResponse_nextToken,
    listHapgsResponse_httpStatus,
    listHapgsResponse_hapgList,
  )
where

import Amazonka.CloudHSM.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:/ 'newListHapgs' smart constructor.
data ListHapgs = ListHapgs'
  { -- | The @NextToken@ value from a previous call to @ListHapgs@. Pass null if
    -- this is the first call.
    ListHapgs -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListHapgs -> ListHapgs -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListHapgs -> ListHapgs -> Bool
$c/= :: ListHapgs -> ListHapgs -> Bool
== :: ListHapgs -> ListHapgs -> Bool
$c== :: ListHapgs -> ListHapgs -> Bool
Prelude.Eq, ReadPrec [ListHapgs]
ReadPrec ListHapgs
Int -> ReadS ListHapgs
ReadS [ListHapgs]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListHapgs]
$creadListPrec :: ReadPrec [ListHapgs]
readPrec :: ReadPrec ListHapgs
$creadPrec :: ReadPrec ListHapgs
readList :: ReadS [ListHapgs]
$creadList :: ReadS [ListHapgs]
readsPrec :: Int -> ReadS ListHapgs
$creadsPrec :: Int -> ReadS ListHapgs
Prelude.Read, Int -> ListHapgs -> ShowS
[ListHapgs] -> ShowS
ListHapgs -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListHapgs] -> ShowS
$cshowList :: [ListHapgs] -> ShowS
show :: ListHapgs -> String
$cshow :: ListHapgs -> String
showsPrec :: Int -> ListHapgs -> ShowS
$cshowsPrec :: Int -> ListHapgs -> ShowS
Prelude.Show, forall x. Rep ListHapgs x -> ListHapgs
forall x. ListHapgs -> Rep ListHapgs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListHapgs x -> ListHapgs
$cfrom :: forall x. ListHapgs -> Rep ListHapgs x
Prelude.Generic)

-- |
-- Create a value of 'ListHapgs' 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', 'listHapgs_nextToken' - The @NextToken@ value from a previous call to @ListHapgs@. Pass null if
-- this is the first call.
newListHapgs ::
  ListHapgs
newListHapgs :: ListHapgs
newListHapgs =
  ListHapgs' {$sel:nextToken:ListHapgs' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing}

-- | The @NextToken@ value from a previous call to @ListHapgs@. Pass null if
-- this is the first call.
listHapgs_nextToken :: Lens.Lens' ListHapgs (Prelude.Maybe Prelude.Text)
listHapgs_nextToken :: Lens' ListHapgs (Maybe Text)
listHapgs_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHapgs' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHapgs' :: ListHapgs -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListHapgs
s@ListHapgs' {} Maybe Text
a -> ListHapgs
s {$sel:nextToken:ListHapgs' :: Maybe Text
nextToken = Maybe Text
a} :: ListHapgs)

instance Core.AWSPager ListHapgs where
  page :: ListHapgs -> AWSResponse ListHapgs -> Maybe ListHapgs
page ListHapgs
rq AWSResponse ListHapgs
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListHapgs
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListHapgsResponse (Maybe Text)
listHapgsResponse_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 ListHapgs
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' ListHapgsResponse [Text]
listHapgsResponse_hapgList) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListHapgs
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListHapgs (Maybe Text)
listHapgs_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListHapgs
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListHapgsResponse (Maybe Text)
listHapgsResponse_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 ListHapgs where
  type AWSResponse ListHapgs = ListHapgsResponse
  request :: (Service -> Service) -> ListHapgs -> Request ListHapgs
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 ListHapgs
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListHapgs)))
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 -> Int -> [Text] -> ListHapgsResponse
ListHapgsResponse'
            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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            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
"HapgList" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

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

instance Prelude.NFData ListHapgs where
  rnf :: ListHapgs -> ()
rnf ListHapgs' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHapgs' :: ListHapgs -> Maybe Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

instance Data.ToHeaders ListHapgs where
  toHeaders :: ListHapgs -> 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
"CloudHsmFrontendService.ListHapgs" ::
                          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 ListHapgs where
  toJSON :: ListHapgs -> Value
toJSON ListHapgs' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHapgs' :: ListHapgs -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(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 ListHapgs where
  toPath :: ListHapgs -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListHapgsResponse' smart constructor.
data ListHapgsResponse = ListHapgsResponse'
  { -- | If not null, more results are available. Pass this value to @ListHapgs@
    -- to retrieve the next set of items.
    ListHapgsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListHapgsResponse -> Int
httpStatus :: Prelude.Int,
    -- | The list of high-availability partition groups.
    ListHapgsResponse -> [Text]
hapgList :: [Prelude.Text]
  }
  deriving (ListHapgsResponse -> ListHapgsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListHapgsResponse -> ListHapgsResponse -> Bool
$c/= :: ListHapgsResponse -> ListHapgsResponse -> Bool
== :: ListHapgsResponse -> ListHapgsResponse -> Bool
$c== :: ListHapgsResponse -> ListHapgsResponse -> Bool
Prelude.Eq, ReadPrec [ListHapgsResponse]
ReadPrec ListHapgsResponse
Int -> ReadS ListHapgsResponse
ReadS [ListHapgsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListHapgsResponse]
$creadListPrec :: ReadPrec [ListHapgsResponse]
readPrec :: ReadPrec ListHapgsResponse
$creadPrec :: ReadPrec ListHapgsResponse
readList :: ReadS [ListHapgsResponse]
$creadList :: ReadS [ListHapgsResponse]
readsPrec :: Int -> ReadS ListHapgsResponse
$creadsPrec :: Int -> ReadS ListHapgsResponse
Prelude.Read, Int -> ListHapgsResponse -> ShowS
[ListHapgsResponse] -> ShowS
ListHapgsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListHapgsResponse] -> ShowS
$cshowList :: [ListHapgsResponse] -> ShowS
show :: ListHapgsResponse -> String
$cshow :: ListHapgsResponse -> String
showsPrec :: Int -> ListHapgsResponse -> ShowS
$cshowsPrec :: Int -> ListHapgsResponse -> ShowS
Prelude.Show, forall x. Rep ListHapgsResponse x -> ListHapgsResponse
forall x. ListHapgsResponse -> Rep ListHapgsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListHapgsResponse x -> ListHapgsResponse
$cfrom :: forall x. ListHapgsResponse -> Rep ListHapgsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListHapgsResponse' 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', 'listHapgsResponse_nextToken' - If not null, more results are available. Pass this value to @ListHapgs@
-- to retrieve the next set of items.
--
-- 'httpStatus', 'listHapgsResponse_httpStatus' - The response's http status code.
--
-- 'hapgList', 'listHapgsResponse_hapgList' - The list of high-availability partition groups.
newListHapgsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListHapgsResponse
newListHapgsResponse :: Int -> ListHapgsResponse
newListHapgsResponse Int
pHttpStatus_ =
  ListHapgsResponse'
    { $sel:nextToken:ListHapgsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListHapgsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:hapgList:ListHapgsResponse' :: [Text]
hapgList = forall a. Monoid a => a
Prelude.mempty
    }

-- | If not null, more results are available. Pass this value to @ListHapgs@
-- to retrieve the next set of items.
listHapgsResponse_nextToken :: Lens.Lens' ListHapgsResponse (Prelude.Maybe Prelude.Text)
listHapgsResponse_nextToken :: Lens' ListHapgsResponse (Maybe Text)
listHapgsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHapgsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHapgsResponse' :: ListHapgsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListHapgsResponse
s@ListHapgsResponse' {} Maybe Text
a -> ListHapgsResponse
s {$sel:nextToken:ListHapgsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListHapgsResponse)

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

-- | The list of high-availability partition groups.
listHapgsResponse_hapgList :: Lens.Lens' ListHapgsResponse [Prelude.Text]
listHapgsResponse_hapgList :: Lens' ListHapgsResponse [Text]
listHapgsResponse_hapgList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHapgsResponse' {[Text]
hapgList :: [Text]
$sel:hapgList:ListHapgsResponse' :: ListHapgsResponse -> [Text]
hapgList} -> [Text]
hapgList) (\s :: ListHapgsResponse
s@ListHapgsResponse' {} [Text]
a -> ListHapgsResponse
s {$sel:hapgList:ListHapgsResponse' :: [Text]
hapgList = [Text]
a} :: ListHapgsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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