{-# 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.VoteOnProposal
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Casts a vote for a specified @ProposalId@ on behalf of a member. The
-- member to vote as, specified by @VoterMemberId@, must be in the same AWS
-- account as the principal that calls the action.
--
-- Applies only to Hyperledger Fabric.
module Amazonka.ManagedBlockChain.VoteOnProposal
  ( -- * Creating a Request
    VoteOnProposal (..),
    newVoteOnProposal,

    -- * Request Lenses
    voteOnProposal_networkId,
    voteOnProposal_proposalId,
    voteOnProposal_voterMemberId,
    voteOnProposal_vote,

    -- * Destructuring the Response
    VoteOnProposalResponse (..),
    newVoteOnProposalResponse,

    -- * Response Lenses
    voteOnProposalResponse_httpStatus,
  )
where

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

-- | /See:/ 'newVoteOnProposal' smart constructor.
data VoteOnProposal = VoteOnProposal'
  { -- | The unique identifier of the network.
    VoteOnProposal -> Text
networkId :: Prelude.Text,
    -- | The unique identifier of the proposal.
    VoteOnProposal -> Text
proposalId :: Prelude.Text,
    -- | The unique identifier of the member casting the vote.
    VoteOnProposal -> Text
voterMemberId :: Prelude.Text,
    -- | The value of the vote.
    VoteOnProposal -> VoteValue
vote :: VoteValue
  }
  deriving (VoteOnProposal -> VoteOnProposal -> Bool
(VoteOnProposal -> VoteOnProposal -> Bool)
-> (VoteOnProposal -> VoteOnProposal -> Bool) -> Eq VoteOnProposal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VoteOnProposal -> VoteOnProposal -> Bool
$c/= :: VoteOnProposal -> VoteOnProposal -> Bool
== :: VoteOnProposal -> VoteOnProposal -> Bool
$c== :: VoteOnProposal -> VoteOnProposal -> Bool
Prelude.Eq, ReadPrec [VoteOnProposal]
ReadPrec VoteOnProposal
Int -> ReadS VoteOnProposal
ReadS [VoteOnProposal]
(Int -> ReadS VoteOnProposal)
-> ReadS [VoteOnProposal]
-> ReadPrec VoteOnProposal
-> ReadPrec [VoteOnProposal]
-> Read VoteOnProposal
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VoteOnProposal]
$creadListPrec :: ReadPrec [VoteOnProposal]
readPrec :: ReadPrec VoteOnProposal
$creadPrec :: ReadPrec VoteOnProposal
readList :: ReadS [VoteOnProposal]
$creadList :: ReadS [VoteOnProposal]
readsPrec :: Int -> ReadS VoteOnProposal
$creadsPrec :: Int -> ReadS VoteOnProposal
Prelude.Read, Int -> VoteOnProposal -> ShowS
[VoteOnProposal] -> ShowS
VoteOnProposal -> String
(Int -> VoteOnProposal -> ShowS)
-> (VoteOnProposal -> String)
-> ([VoteOnProposal] -> ShowS)
-> Show VoteOnProposal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VoteOnProposal] -> ShowS
$cshowList :: [VoteOnProposal] -> ShowS
show :: VoteOnProposal -> String
$cshow :: VoteOnProposal -> String
showsPrec :: Int -> VoteOnProposal -> ShowS
$cshowsPrec :: Int -> VoteOnProposal -> ShowS
Prelude.Show, (forall x. VoteOnProposal -> Rep VoteOnProposal x)
-> (forall x. Rep VoteOnProposal x -> VoteOnProposal)
-> Generic VoteOnProposal
forall x. Rep VoteOnProposal x -> VoteOnProposal
forall x. VoteOnProposal -> Rep VoteOnProposal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VoteOnProposal x -> VoteOnProposal
$cfrom :: forall x. VoteOnProposal -> Rep VoteOnProposal x
Prelude.Generic)

-- |
-- Create a value of 'VoteOnProposal' 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:
--
-- 'networkId', 'voteOnProposal_networkId' - The unique identifier of the network.
--
-- 'proposalId', 'voteOnProposal_proposalId' - The unique identifier of the proposal.
--
-- 'voterMemberId', 'voteOnProposal_voterMemberId' - The unique identifier of the member casting the vote.
--
-- 'vote', 'voteOnProposal_vote' - The value of the vote.
newVoteOnProposal ::
  -- | 'networkId'
  Prelude.Text ->
  -- | 'proposalId'
  Prelude.Text ->
  -- | 'voterMemberId'
  Prelude.Text ->
  -- | 'vote'
  VoteValue ->
  VoteOnProposal
newVoteOnProposal :: Text -> Text -> Text -> VoteValue -> VoteOnProposal
newVoteOnProposal
  Text
pNetworkId_
  Text
pProposalId_
  Text
pVoterMemberId_
  VoteValue
pVote_ =
    VoteOnProposal' :: Text -> Text -> Text -> VoteValue -> VoteOnProposal
VoteOnProposal'
      { $sel:networkId:VoteOnProposal' :: Text
networkId = Text
pNetworkId_,
        $sel:proposalId:VoteOnProposal' :: Text
proposalId = Text
pProposalId_,
        $sel:voterMemberId:VoteOnProposal' :: Text
voterMemberId = Text
pVoterMemberId_,
        $sel:vote:VoteOnProposal' :: VoteValue
vote = VoteValue
pVote_
      }

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

-- | The unique identifier of the proposal.
voteOnProposal_proposalId :: Lens.Lens' VoteOnProposal Prelude.Text
voteOnProposal_proposalId :: (Text -> f Text) -> VoteOnProposal -> f VoteOnProposal
voteOnProposal_proposalId = (VoteOnProposal -> Text)
-> (VoteOnProposal -> Text -> VoteOnProposal)
-> Lens VoteOnProposal VoteOnProposal Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VoteOnProposal' {Text
proposalId :: Text
$sel:proposalId:VoteOnProposal' :: VoteOnProposal -> Text
proposalId} -> Text
proposalId) (\s :: VoteOnProposal
s@VoteOnProposal' {} Text
a -> VoteOnProposal
s {$sel:proposalId:VoteOnProposal' :: Text
proposalId = Text
a} :: VoteOnProposal)

-- | The unique identifier of the member casting the vote.
voteOnProposal_voterMemberId :: Lens.Lens' VoteOnProposal Prelude.Text
voteOnProposal_voterMemberId :: (Text -> f Text) -> VoteOnProposal -> f VoteOnProposal
voteOnProposal_voterMemberId = (VoteOnProposal -> Text)
-> (VoteOnProposal -> Text -> VoteOnProposal)
-> Lens VoteOnProposal VoteOnProposal Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VoteOnProposal' {Text
voterMemberId :: Text
$sel:voterMemberId:VoteOnProposal' :: VoteOnProposal -> Text
voterMemberId} -> Text
voterMemberId) (\s :: VoteOnProposal
s@VoteOnProposal' {} Text
a -> VoteOnProposal
s {$sel:voterMemberId:VoteOnProposal' :: Text
voterMemberId = Text
a} :: VoteOnProposal)

-- | The value of the vote.
voteOnProposal_vote :: Lens.Lens' VoteOnProposal VoteValue
voteOnProposal_vote :: (VoteValue -> f VoteValue) -> VoteOnProposal -> f VoteOnProposal
voteOnProposal_vote = (VoteOnProposal -> VoteValue)
-> (VoteOnProposal -> VoteValue -> VoteOnProposal)
-> Lens VoteOnProposal VoteOnProposal VoteValue VoteValue
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VoteOnProposal' {VoteValue
vote :: VoteValue
$sel:vote:VoteOnProposal' :: VoteOnProposal -> VoteValue
vote} -> VoteValue
vote) (\s :: VoteOnProposal
s@VoteOnProposal' {} VoteValue
a -> VoteOnProposal
s {$sel:vote:VoteOnProposal' :: VoteValue
vote = VoteValue
a} :: VoteOnProposal)

instance Core.AWSRequest VoteOnProposal where
  type
    AWSResponse VoteOnProposal =
      VoteOnProposalResponse
  request :: VoteOnProposal -> Request VoteOnProposal
request = Service -> VoteOnProposal -> Request VoteOnProposal
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy VoteOnProposal
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse VoteOnProposal)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse VoteOnProposal))
-> Logger
-> Service
-> Proxy VoteOnProposal
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse VoteOnProposal)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> VoteOnProposalResponse
VoteOnProposalResponse'
            (Int -> VoteOnProposalResponse)
-> Either String Int -> Either String VoteOnProposalResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable VoteOnProposal

instance Prelude.NFData VoteOnProposal

instance Core.ToHeaders VoteOnProposal where
  toHeaders :: VoteOnProposal -> ResponseHeaders
toHeaders =
    ResponseHeaders -> VoteOnProposal -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON VoteOnProposal where
  toJSON :: VoteOnProposal -> Value
toJSON VoteOnProposal' {Text
VoteValue
vote :: VoteValue
voterMemberId :: Text
proposalId :: Text
networkId :: Text
$sel:vote:VoteOnProposal' :: VoteOnProposal -> VoteValue
$sel:voterMemberId:VoteOnProposal' :: VoteOnProposal -> Text
$sel:proposalId:VoteOnProposal' :: VoteOnProposal -> Text
$sel:networkId:VoteOnProposal' :: VoteOnProposal -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"VoterMemberId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
voterMemberId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Vote" Text -> VoteValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= VoteValue
vote)
          ]
      )

instance Core.ToPath VoteOnProposal where
  toPath :: VoteOnProposal -> ByteString
toPath VoteOnProposal' {Text
VoteValue
vote :: VoteValue
voterMemberId :: Text
proposalId :: Text
networkId :: Text
$sel:vote:VoteOnProposal' :: VoteOnProposal -> VoteValue
$sel:voterMemberId:VoteOnProposal' :: VoteOnProposal -> Text
$sel:proposalId:VoteOnProposal' :: VoteOnProposal -> Text
$sel:networkId:VoteOnProposal' :: VoteOnProposal -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/networks/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
networkId,
        ByteString
"/proposals/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
proposalId,
        ByteString
"/votes"
      ]

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

-- | /See:/ 'newVoteOnProposalResponse' smart constructor.
data VoteOnProposalResponse = VoteOnProposalResponse'
  { -- | The response's http status code.
    VoteOnProposalResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (VoteOnProposalResponse -> VoteOnProposalResponse -> Bool
(VoteOnProposalResponse -> VoteOnProposalResponse -> Bool)
-> (VoteOnProposalResponse -> VoteOnProposalResponse -> Bool)
-> Eq VoteOnProposalResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VoteOnProposalResponse -> VoteOnProposalResponse -> Bool
$c/= :: VoteOnProposalResponse -> VoteOnProposalResponse -> Bool
== :: VoteOnProposalResponse -> VoteOnProposalResponse -> Bool
$c== :: VoteOnProposalResponse -> VoteOnProposalResponse -> Bool
Prelude.Eq, ReadPrec [VoteOnProposalResponse]
ReadPrec VoteOnProposalResponse
Int -> ReadS VoteOnProposalResponse
ReadS [VoteOnProposalResponse]
(Int -> ReadS VoteOnProposalResponse)
-> ReadS [VoteOnProposalResponse]
-> ReadPrec VoteOnProposalResponse
-> ReadPrec [VoteOnProposalResponse]
-> Read VoteOnProposalResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VoteOnProposalResponse]
$creadListPrec :: ReadPrec [VoteOnProposalResponse]
readPrec :: ReadPrec VoteOnProposalResponse
$creadPrec :: ReadPrec VoteOnProposalResponse
readList :: ReadS [VoteOnProposalResponse]
$creadList :: ReadS [VoteOnProposalResponse]
readsPrec :: Int -> ReadS VoteOnProposalResponse
$creadsPrec :: Int -> ReadS VoteOnProposalResponse
Prelude.Read, Int -> VoteOnProposalResponse -> ShowS
[VoteOnProposalResponse] -> ShowS
VoteOnProposalResponse -> String
(Int -> VoteOnProposalResponse -> ShowS)
-> (VoteOnProposalResponse -> String)
-> ([VoteOnProposalResponse] -> ShowS)
-> Show VoteOnProposalResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VoteOnProposalResponse] -> ShowS
$cshowList :: [VoteOnProposalResponse] -> ShowS
show :: VoteOnProposalResponse -> String
$cshow :: VoteOnProposalResponse -> String
showsPrec :: Int -> VoteOnProposalResponse -> ShowS
$cshowsPrec :: Int -> VoteOnProposalResponse -> ShowS
Prelude.Show, (forall x. VoteOnProposalResponse -> Rep VoteOnProposalResponse x)
-> (forall x.
    Rep VoteOnProposalResponse x -> VoteOnProposalResponse)
-> Generic VoteOnProposalResponse
forall x. Rep VoteOnProposalResponse x -> VoteOnProposalResponse
forall x. VoteOnProposalResponse -> Rep VoteOnProposalResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VoteOnProposalResponse x -> VoteOnProposalResponse
$cfrom :: forall x. VoteOnProposalResponse -> Rep VoteOnProposalResponse x
Prelude.Generic)

-- |
-- Create a value of 'VoteOnProposalResponse' 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:
--
-- 'httpStatus', 'voteOnProposalResponse_httpStatus' - The response's http status code.
newVoteOnProposalResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  VoteOnProposalResponse
newVoteOnProposalResponse :: Int -> VoteOnProposalResponse
newVoteOnProposalResponse Int
pHttpStatus_ =
  VoteOnProposalResponse' :: Int -> VoteOnProposalResponse
VoteOnProposalResponse' {$sel:httpStatus:VoteOnProposalResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData VoteOnProposalResponse