{-# 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.ManagedBlockChain.ListProposals
-- 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 proposals for the network.
--
-- Applies only to Hyperledger Fabric.
module Amazonka.ManagedBlockChain.ListProposals
  ( -- * Creating a Request
    ListProposals (..),
    newListProposals,

    -- * Request Lenses
    listProposals_maxResults,
    listProposals_nextToken,
    listProposals_networkId,

    -- * Destructuring the Response
    ListProposalsResponse (..),
    newListProposalsResponse,

    -- * Response Lenses
    listProposalsResponse_nextToken,
    listProposalsResponse_proposals,
    listProposalsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListProposals' smart constructor.
data ListProposals = ListProposals'
  { -- | The maximum number of proposals to return.
    ListProposals -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The pagination token that indicates the next set of results to retrieve.
    ListProposals -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier of the network.
    ListProposals -> Text
networkId :: Prelude.Text
  }
  deriving (ListProposals -> ListProposals -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListProposals -> ListProposals -> Bool
$c/= :: ListProposals -> ListProposals -> Bool
== :: ListProposals -> ListProposals -> Bool
$c== :: ListProposals -> ListProposals -> Bool
Prelude.Eq, ReadPrec [ListProposals]
ReadPrec ListProposals
Int -> ReadS ListProposals
ReadS [ListProposals]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListProposals]
$creadListPrec :: ReadPrec [ListProposals]
readPrec :: ReadPrec ListProposals
$creadPrec :: ReadPrec ListProposals
readList :: ReadS [ListProposals]
$creadList :: ReadS [ListProposals]
readsPrec :: Int -> ReadS ListProposals
$creadsPrec :: Int -> ReadS ListProposals
Prelude.Read, Int -> ListProposals -> ShowS
[ListProposals] -> ShowS
ListProposals -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListProposals] -> ShowS
$cshowList :: [ListProposals] -> ShowS
show :: ListProposals -> String
$cshow :: ListProposals -> String
showsPrec :: Int -> ListProposals -> ShowS
$cshowsPrec :: Int -> ListProposals -> ShowS
Prelude.Show, forall x. Rep ListProposals x -> ListProposals
forall x. ListProposals -> Rep ListProposals x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListProposals x -> ListProposals
$cfrom :: forall x. ListProposals -> Rep ListProposals x
Prelude.Generic)

-- |
-- Create a value of 'ListProposals' 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', 'listProposals_maxResults' - The maximum number of proposals to return.
--
-- 'nextToken', 'listProposals_nextToken' - The pagination token that indicates the next set of results to retrieve.
--
-- 'networkId', 'listProposals_networkId' - The unique identifier of the network.
newListProposals ::
  -- | 'networkId'
  Prelude.Text ->
  ListProposals
newListProposals :: Text -> ListProposals
newListProposals Text
pNetworkId_ =
  ListProposals'
    { $sel:maxResults:ListProposals' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListProposals' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:networkId:ListProposals' :: Text
networkId = Text
pNetworkId_
    }

-- | The maximum number of proposals to return.
listProposals_maxResults :: Lens.Lens' ListProposals (Prelude.Maybe Prelude.Natural)
listProposals_maxResults :: Lens' ListProposals (Maybe Natural)
listProposals_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProposals' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListProposals' :: ListProposals -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListProposals
s@ListProposals' {} Maybe Natural
a -> ListProposals
s {$sel:maxResults:ListProposals' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListProposals)

-- | The pagination token that indicates the next set of results to retrieve.
listProposals_nextToken :: Lens.Lens' ListProposals (Prelude.Maybe Prelude.Text)
listProposals_nextToken :: Lens' ListProposals (Maybe Text)
listProposals_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProposals' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListProposals' :: ListProposals -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListProposals
s@ListProposals' {} Maybe Text
a -> ListProposals
s {$sel:nextToken:ListProposals' :: Maybe Text
nextToken = Maybe Text
a} :: ListProposals)

-- | The unique identifier of the network.
listProposals_networkId :: Lens.Lens' ListProposals Prelude.Text
listProposals_networkId :: Lens' ListProposals Text
listProposals_networkId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProposals' {Text
networkId :: Text
$sel:networkId:ListProposals' :: ListProposals -> Text
networkId} -> Text
networkId) (\s :: ListProposals
s@ListProposals' {} Text
a -> ListProposals
s {$sel:networkId:ListProposals' :: Text
networkId = Text
a} :: ListProposals)

instance Core.AWSRequest ListProposals where
  type
    AWSResponse ListProposals =
      ListProposalsResponse
  request :: (Service -> Service) -> ListProposals -> Request ListProposals
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 ListProposals
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListProposals)))
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 [ProposalSummary] -> Int -> ListProposalsResponse
ListProposalsResponse'
            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
"Proposals" 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 ListProposals where
  hashWithSalt :: Int -> ListProposals -> Int
hashWithSalt Int
_salt ListProposals' {Maybe Natural
Maybe Text
Text
networkId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:networkId:ListProposals' :: ListProposals -> Text
$sel:nextToken:ListProposals' :: ListProposals -> Maybe Text
$sel:maxResults:ListProposals' :: ListProposals -> 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` Text
networkId

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

instance Data.ToHeaders ListProposals where
  toHeaders :: ListProposals -> 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 ListProposals where
  toPath :: ListProposals -> ByteString
toPath ListProposals' {Maybe Natural
Maybe Text
Text
networkId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:networkId:ListProposals' :: ListProposals -> Text
$sel:nextToken:ListProposals' :: ListProposals -> Maybe Text
$sel:maxResults:ListProposals' :: ListProposals -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/networks/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
networkId, ByteString
"/proposals"]

instance Data.ToQuery ListProposals where
  toQuery :: ListProposals -> QueryString
toQuery ListProposals' {Maybe Natural
Maybe Text
Text
networkId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:networkId:ListProposals' :: ListProposals -> Text
$sel:nextToken:ListProposals' :: ListProposals -> Maybe Text
$sel:maxResults:ListProposals' :: ListProposals -> 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:/ 'newListProposalsResponse' smart constructor.
data ListProposalsResponse = ListProposalsResponse'
  { -- | The pagination token that indicates the next set of results to retrieve.
    ListProposalsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The summary of each proposal made on the network.
    ListProposalsResponse -> Maybe [ProposalSummary]
proposals :: Prelude.Maybe [ProposalSummary],
    -- | The response's http status code.
    ListProposalsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListProposalsResponse -> ListProposalsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListProposalsResponse -> ListProposalsResponse -> Bool
$c/= :: ListProposalsResponse -> ListProposalsResponse -> Bool
== :: ListProposalsResponse -> ListProposalsResponse -> Bool
$c== :: ListProposalsResponse -> ListProposalsResponse -> Bool
Prelude.Eq, ReadPrec [ListProposalsResponse]
ReadPrec ListProposalsResponse
Int -> ReadS ListProposalsResponse
ReadS [ListProposalsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListProposalsResponse]
$creadListPrec :: ReadPrec [ListProposalsResponse]
readPrec :: ReadPrec ListProposalsResponse
$creadPrec :: ReadPrec ListProposalsResponse
readList :: ReadS [ListProposalsResponse]
$creadList :: ReadS [ListProposalsResponse]
readsPrec :: Int -> ReadS ListProposalsResponse
$creadsPrec :: Int -> ReadS ListProposalsResponse
Prelude.Read, Int -> ListProposalsResponse -> ShowS
[ListProposalsResponse] -> ShowS
ListProposalsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListProposalsResponse] -> ShowS
$cshowList :: [ListProposalsResponse] -> ShowS
show :: ListProposalsResponse -> String
$cshow :: ListProposalsResponse -> String
showsPrec :: Int -> ListProposalsResponse -> ShowS
$cshowsPrec :: Int -> ListProposalsResponse -> ShowS
Prelude.Show, forall x. Rep ListProposalsResponse x -> ListProposalsResponse
forall x. ListProposalsResponse -> Rep ListProposalsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListProposalsResponse x -> ListProposalsResponse
$cfrom :: forall x. ListProposalsResponse -> Rep ListProposalsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListProposalsResponse' 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', 'listProposalsResponse_nextToken' - The pagination token that indicates the next set of results to retrieve.
--
-- 'proposals', 'listProposalsResponse_proposals' - The summary of each proposal made on the network.
--
-- 'httpStatus', 'listProposalsResponse_httpStatus' - The response's http status code.
newListProposalsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListProposalsResponse
newListProposalsResponse :: Int -> ListProposalsResponse
newListProposalsResponse Int
pHttpStatus_ =
  ListProposalsResponse'
    { $sel:nextToken:ListProposalsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:proposals:ListProposalsResponse' :: Maybe [ProposalSummary]
proposals = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListProposalsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The pagination token that indicates the next set of results to retrieve.
listProposalsResponse_nextToken :: Lens.Lens' ListProposalsResponse (Prelude.Maybe Prelude.Text)
listProposalsResponse_nextToken :: Lens' ListProposalsResponse (Maybe Text)
listProposalsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProposalsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListProposalsResponse' :: ListProposalsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListProposalsResponse
s@ListProposalsResponse' {} Maybe Text
a -> ListProposalsResponse
s {$sel:nextToken:ListProposalsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListProposalsResponse)

-- | The summary of each proposal made on the network.
listProposalsResponse_proposals :: Lens.Lens' ListProposalsResponse (Prelude.Maybe [ProposalSummary])
listProposalsResponse_proposals :: Lens' ListProposalsResponse (Maybe [ProposalSummary])
listProposalsResponse_proposals = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProposalsResponse' {Maybe [ProposalSummary]
proposals :: Maybe [ProposalSummary]
$sel:proposals:ListProposalsResponse' :: ListProposalsResponse -> Maybe [ProposalSummary]
proposals} -> Maybe [ProposalSummary]
proposals) (\s :: ListProposalsResponse
s@ListProposalsResponse' {} Maybe [ProposalSummary]
a -> ListProposalsResponse
s {$sel:proposals:ListProposalsResponse' :: Maybe [ProposalSummary]
proposals = Maybe [ProposalSummary]
a} :: ListProposalsResponse) 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.
listProposalsResponse_httpStatus :: Lens.Lens' ListProposalsResponse Prelude.Int
listProposalsResponse_httpStatus :: Lens' ListProposalsResponse Int
listProposalsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProposalsResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListProposalsResponse' :: ListProposalsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListProposalsResponse
s@ListProposalsResponse' {} Int
a -> ListProposalsResponse
s {$sel:httpStatus:ListProposalsResponse' :: Int
httpStatus = Int
a} :: ListProposalsResponse)

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