{-# 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-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)
module Amazonka.ManagedBlockChain.Types.VotingPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(VotingPolicy -> VotingPolicy -> Bool)
-> (VotingPolicy -> VotingPolicy -> Bool) -> Eq VotingPolicy
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]
(Int -> ReadS VotingPolicy)
-> ReadS [VotingPolicy]
-> ReadPrec VotingPolicy
-> ReadPrec [VotingPolicy]
-> Read 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
(Int -> VotingPolicy -> ShowS)
-> (VotingPolicy -> String)
-> ([VotingPolicy] -> ShowS)
-> Show VotingPolicy
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. VotingPolicy -> Rep VotingPolicy x)
-> (forall x. Rep VotingPolicy x -> VotingPolicy)
-> Generic VotingPolicy
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' :: Maybe ApprovalThresholdPolicy -> VotingPolicy
VotingPolicy'
    { $sel:approvalThresholdPolicy:VotingPolicy' :: Maybe ApprovalThresholdPolicy
approvalThresholdPolicy =
        Maybe 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 :: (Maybe ApprovalThresholdPolicy
 -> f (Maybe ApprovalThresholdPolicy))
-> VotingPolicy -> f VotingPolicy
votingPolicy_approvalThresholdPolicy = (VotingPolicy -> Maybe ApprovalThresholdPolicy)
-> (VotingPolicy -> Maybe ApprovalThresholdPolicy -> VotingPolicy)
-> Lens
     VotingPolicy
     VotingPolicy
     (Maybe ApprovalThresholdPolicy)
     (Maybe 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 Core.FromJSON VotingPolicy where
  parseJSON :: Value -> Parser VotingPolicy
parseJSON =
    String
-> (Object -> Parser VotingPolicy) -> Value -> Parser VotingPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"VotingPolicy"
      ( \Object
x ->
          Maybe ApprovalThresholdPolicy -> VotingPolicy
VotingPolicy'
            (Maybe ApprovalThresholdPolicy -> VotingPolicy)
-> Parser (Maybe ApprovalThresholdPolicy) -> Parser VotingPolicy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ApprovalThresholdPolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ApprovalThresholdPolicy")
      )

instance Prelude.Hashable VotingPolicy

instance Prelude.NFData VotingPolicy

instance Core.ToJSON VotingPolicy where
  toJSON :: VotingPolicy -> Value
toJSON VotingPolicy' {Maybe ApprovalThresholdPolicy
approvalThresholdPolicy :: Maybe ApprovalThresholdPolicy
$sel:approvalThresholdPolicy:VotingPolicy' :: VotingPolicy -> Maybe ApprovalThresholdPolicy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ApprovalThresholdPolicy" Text -> ApprovalThresholdPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ApprovalThresholdPolicy -> Pair)
-> Maybe ApprovalThresholdPolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ApprovalThresholdPolicy
approvalThresholdPolicy
          ]
      )