{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.VotingPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ManagedBlockChain.Types.VotingPolicy 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.ApprovalThresholdPolicy
import qualified Amazonka.Prelude as Prelude

-- | The voting rules for the network to decide if a proposal is accepted
--
-- Applies only to Hyperledger Fabric.
--
-- /See:/ 'newVotingPolicy' smart constructor.
data VotingPolicy = VotingPolicy'
  { -- | Defines the rules for the network for voting on proposals, such as the
    -- percentage of @YES@ votes required for the proposal to be approved and
    -- the duration of the proposal. The policy applies to all proposals and is
    -- specified when the network is created.
    VotingPolicy -> Maybe ApprovalThresholdPolicy
approvalThresholdPolicy :: Prelude.Maybe ApprovalThresholdPolicy
  }
  deriving (VotingPolicy -> VotingPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VotingPolicy -> VotingPolicy -> Bool
$c/= :: VotingPolicy -> VotingPolicy -> Bool
== :: VotingPolicy -> VotingPolicy -> Bool
$c== :: VotingPolicy -> VotingPolicy -> Bool
Prelude.Eq, ReadPrec [VotingPolicy]
ReadPrec VotingPolicy
Int -> ReadS VotingPolicy
ReadS [VotingPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VotingPolicy]
$creadListPrec :: ReadPrec [VotingPolicy]
readPrec :: ReadPrec VotingPolicy
$creadPrec :: ReadPrec VotingPolicy
readList :: ReadS [VotingPolicy]
$creadList :: ReadS [VotingPolicy]
readsPrec :: Int -> ReadS VotingPolicy
$creadsPrec :: Int -> ReadS VotingPolicy
Prelude.Read, Int -> VotingPolicy -> ShowS
[VotingPolicy] -> ShowS
VotingPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VotingPolicy] -> ShowS
$cshowList :: [VotingPolicy] -> ShowS
show :: VotingPolicy -> String
$cshow :: VotingPolicy -> String
showsPrec :: Int -> VotingPolicy -> ShowS
$cshowsPrec :: Int -> VotingPolicy -> ShowS
Prelude.Show, forall x. Rep VotingPolicy x -> VotingPolicy
forall x. VotingPolicy -> Rep VotingPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VotingPolicy x -> VotingPolicy
$cfrom :: forall x. VotingPolicy -> Rep VotingPolicy x
Prelude.Generic)

-- |
-- Create a value of 'VotingPolicy' 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:
--
-- 'approvalThresholdPolicy', 'votingPolicy_approvalThresholdPolicy' - Defines the rules for the network for voting on proposals, such as the
-- percentage of @YES@ votes required for the proposal to be approved and
-- the duration of the proposal. The policy applies to all proposals and is
-- specified when the network is created.
newVotingPolicy ::
  VotingPolicy
newVotingPolicy :: VotingPolicy
newVotingPolicy =
  VotingPolicy'
    { $sel:approvalThresholdPolicy:VotingPolicy' :: Maybe ApprovalThresholdPolicy
approvalThresholdPolicy =
        forall a. Maybe a
Prelude.Nothing
    }

-- | Defines the rules for the network for voting on proposals, such as the
-- percentage of @YES@ votes required for the proposal to be approved and
-- the duration of the proposal. The policy applies to all proposals and is
-- specified when the network is created.
votingPolicy_approvalThresholdPolicy :: Lens.Lens' VotingPolicy (Prelude.Maybe ApprovalThresholdPolicy)
votingPolicy_approvalThresholdPolicy :: Lens' VotingPolicy (Maybe ApprovalThresholdPolicy)
votingPolicy_approvalThresholdPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VotingPolicy' {Maybe ApprovalThresholdPolicy
approvalThresholdPolicy :: Maybe ApprovalThresholdPolicy
$sel:approvalThresholdPolicy:VotingPolicy' :: VotingPolicy -> Maybe ApprovalThresholdPolicy
approvalThresholdPolicy} -> Maybe ApprovalThresholdPolicy
approvalThresholdPolicy) (\s :: VotingPolicy
s@VotingPolicy' {} Maybe ApprovalThresholdPolicy
a -> VotingPolicy
s {$sel:approvalThresholdPolicy:VotingPolicy' :: Maybe ApprovalThresholdPolicy
approvalThresholdPolicy = Maybe ApprovalThresholdPolicy
a} :: VotingPolicy)

instance Data.FromJSON VotingPolicy where
  parseJSON :: Value -> Parser VotingPolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"VotingPolicy"
      ( \Object
x ->
          Maybe ApprovalThresholdPolicy -> VotingPolicy
VotingPolicy'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ApprovalThresholdPolicy")
      )

instance Prelude.Hashable VotingPolicy where
  hashWithSalt :: Int -> VotingPolicy -> Int
hashWithSalt Int
_salt VotingPolicy' {Maybe ApprovalThresholdPolicy
approvalThresholdPolicy :: Maybe ApprovalThresholdPolicy
$sel:approvalThresholdPolicy:VotingPolicy' :: VotingPolicy -> Maybe ApprovalThresholdPolicy
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ApprovalThresholdPolicy
approvalThresholdPolicy

instance Prelude.NFData VotingPolicy where
  rnf :: VotingPolicy -> ()
rnf VotingPolicy' {Maybe ApprovalThresholdPolicy
approvalThresholdPolicy :: Maybe ApprovalThresholdPolicy
$sel:approvalThresholdPolicy:VotingPolicy' :: VotingPolicy -> Maybe ApprovalThresholdPolicy
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ApprovalThresholdPolicy
approvalThresholdPolicy

instance Data.ToJSON VotingPolicy where
  toJSON :: VotingPolicy -> Value
toJSON VotingPolicy' {Maybe ApprovalThresholdPolicy
approvalThresholdPolicy :: Maybe ApprovalThresholdPolicy
$sel:approvalThresholdPolicy:VotingPolicy' :: VotingPolicy -> Maybe ApprovalThresholdPolicy
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ApprovalThresholdPolicy" 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 ApprovalThresholdPolicy
approvalThresholdPolicy
          ]
      )