{-# 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.ApprovalThresholdPolicy
-- 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.ApprovalThresholdPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.ManagedBlockChain.Types.ThresholdComparator
import qualified Amazonka.Prelude as Prelude

-- | A policy type that defines the voting rules for the network. The rules
-- decide if a proposal is approved. Approval may be based on criteria such
-- as the percentage of @YES@ votes and the duration of the proposal. The
-- policy applies to all proposals and is specified when the network is
-- created.
--
-- Applies only to Hyperledger Fabric.
--
-- /See:/ 'newApprovalThresholdPolicy' smart constructor.
data ApprovalThresholdPolicy = ApprovalThresholdPolicy'
  { -- | The percentage of votes among all members that must be @YES@ for a
    -- proposal to be approved. For example, a @ThresholdPercentage@ value of
    -- @50@ indicates 50%. The @ThresholdComparator@ determines the precise
    -- comparison. If a @ThresholdPercentage@ value of @50@ is specified on a
    -- network with 10 members, along with a @ThresholdComparator@ value of
    -- @GREATER_THAN@, this indicates that 6 @YES@ votes are required for the
    -- proposal to be approved.
    ApprovalThresholdPolicy -> Maybe Natural
thresholdPercentage :: Prelude.Maybe Prelude.Natural,
    -- | Determines whether the vote percentage must be greater than the
    -- @ThresholdPercentage@ or must be greater than or equal to the
    -- @ThreholdPercentage@ to be approved.
    ApprovalThresholdPolicy -> Maybe ThresholdComparator
thresholdComparator :: Prelude.Maybe ThresholdComparator,
    -- | The duration from the time that a proposal is created until it expires.
    -- If members cast neither the required number of @YES@ votes to approve
    -- the proposal nor the number of @NO@ votes required to reject it before
    -- the duration expires, the proposal is @EXPIRED@ and @ProposalActions@
    -- are not carried out.
    ApprovalThresholdPolicy -> Maybe Natural
proposalDurationInHours :: Prelude.Maybe Prelude.Natural
  }
  deriving (ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool
(ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool)
-> (ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool)
-> Eq ApprovalThresholdPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool
$c/= :: ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool
== :: ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool
$c== :: ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool
Prelude.Eq, ReadPrec [ApprovalThresholdPolicy]
ReadPrec ApprovalThresholdPolicy
Int -> ReadS ApprovalThresholdPolicy
ReadS [ApprovalThresholdPolicy]
(Int -> ReadS ApprovalThresholdPolicy)
-> ReadS [ApprovalThresholdPolicy]
-> ReadPrec ApprovalThresholdPolicy
-> ReadPrec [ApprovalThresholdPolicy]
-> Read ApprovalThresholdPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ApprovalThresholdPolicy]
$creadListPrec :: ReadPrec [ApprovalThresholdPolicy]
readPrec :: ReadPrec ApprovalThresholdPolicy
$creadPrec :: ReadPrec ApprovalThresholdPolicy
readList :: ReadS [ApprovalThresholdPolicy]
$creadList :: ReadS [ApprovalThresholdPolicy]
readsPrec :: Int -> ReadS ApprovalThresholdPolicy
$creadsPrec :: Int -> ReadS ApprovalThresholdPolicy
Prelude.Read, Int -> ApprovalThresholdPolicy -> ShowS
[ApprovalThresholdPolicy] -> ShowS
ApprovalThresholdPolicy -> String
(Int -> ApprovalThresholdPolicy -> ShowS)
-> (ApprovalThresholdPolicy -> String)
-> ([ApprovalThresholdPolicy] -> ShowS)
-> Show ApprovalThresholdPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApprovalThresholdPolicy] -> ShowS
$cshowList :: [ApprovalThresholdPolicy] -> ShowS
show :: ApprovalThresholdPolicy -> String
$cshow :: ApprovalThresholdPolicy -> String
showsPrec :: Int -> ApprovalThresholdPolicy -> ShowS
$cshowsPrec :: Int -> ApprovalThresholdPolicy -> ShowS
Prelude.Show, (forall x.
 ApprovalThresholdPolicy -> Rep ApprovalThresholdPolicy x)
-> (forall x.
    Rep ApprovalThresholdPolicy x -> ApprovalThresholdPolicy)
-> Generic ApprovalThresholdPolicy
forall x. Rep ApprovalThresholdPolicy x -> ApprovalThresholdPolicy
forall x. ApprovalThresholdPolicy -> Rep ApprovalThresholdPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApprovalThresholdPolicy x -> ApprovalThresholdPolicy
$cfrom :: forall x. ApprovalThresholdPolicy -> Rep ApprovalThresholdPolicy x
Prelude.Generic)

-- |
-- Create a value of 'ApprovalThresholdPolicy' 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:
--
-- 'thresholdPercentage', 'approvalThresholdPolicy_thresholdPercentage' - The percentage of votes among all members that must be @YES@ for a
-- proposal to be approved. For example, a @ThresholdPercentage@ value of
-- @50@ indicates 50%. The @ThresholdComparator@ determines the precise
-- comparison. If a @ThresholdPercentage@ value of @50@ is specified on a
-- network with 10 members, along with a @ThresholdComparator@ value of
-- @GREATER_THAN@, this indicates that 6 @YES@ votes are required for the
-- proposal to be approved.
--
-- 'thresholdComparator', 'approvalThresholdPolicy_thresholdComparator' - Determines whether the vote percentage must be greater than the
-- @ThresholdPercentage@ or must be greater than or equal to the
-- @ThreholdPercentage@ to be approved.
--
-- 'proposalDurationInHours', 'approvalThresholdPolicy_proposalDurationInHours' - The duration from the time that a proposal is created until it expires.
-- If members cast neither the required number of @YES@ votes to approve
-- the proposal nor the number of @NO@ votes required to reject it before
-- the duration expires, the proposal is @EXPIRED@ and @ProposalActions@
-- are not carried out.
newApprovalThresholdPolicy ::
  ApprovalThresholdPolicy
newApprovalThresholdPolicy :: ApprovalThresholdPolicy
newApprovalThresholdPolicy =
  ApprovalThresholdPolicy' :: Maybe Natural
-> Maybe ThresholdComparator
-> Maybe Natural
-> ApprovalThresholdPolicy
ApprovalThresholdPolicy'
    { $sel:thresholdPercentage:ApprovalThresholdPolicy' :: Maybe Natural
thresholdPercentage =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:thresholdComparator:ApprovalThresholdPolicy' :: Maybe ThresholdComparator
thresholdComparator = Maybe ThresholdComparator
forall a. Maybe a
Prelude.Nothing,
      $sel:proposalDurationInHours:ApprovalThresholdPolicy' :: Maybe Natural
proposalDurationInHours = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The percentage of votes among all members that must be @YES@ for a
-- proposal to be approved. For example, a @ThresholdPercentage@ value of
-- @50@ indicates 50%. The @ThresholdComparator@ determines the precise
-- comparison. If a @ThresholdPercentage@ value of @50@ is specified on a
-- network with 10 members, along with a @ThresholdComparator@ value of
-- @GREATER_THAN@, this indicates that 6 @YES@ votes are required for the
-- proposal to be approved.
approvalThresholdPolicy_thresholdPercentage :: Lens.Lens' ApprovalThresholdPolicy (Prelude.Maybe Prelude.Natural)
approvalThresholdPolicy_thresholdPercentage :: (Maybe Natural -> f (Maybe Natural))
-> ApprovalThresholdPolicy -> f ApprovalThresholdPolicy
approvalThresholdPolicy_thresholdPercentage = (ApprovalThresholdPolicy -> Maybe Natural)
-> (ApprovalThresholdPolicy
    -> Maybe Natural -> ApprovalThresholdPolicy)
-> Lens
     ApprovalThresholdPolicy
     ApprovalThresholdPolicy
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApprovalThresholdPolicy' {Maybe Natural
thresholdPercentage :: Maybe Natural
$sel:thresholdPercentage:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
thresholdPercentage} -> Maybe Natural
thresholdPercentage) (\s :: ApprovalThresholdPolicy
s@ApprovalThresholdPolicy' {} Maybe Natural
a -> ApprovalThresholdPolicy
s {$sel:thresholdPercentage:ApprovalThresholdPolicy' :: Maybe Natural
thresholdPercentage = Maybe Natural
a} :: ApprovalThresholdPolicy)

-- | Determines whether the vote percentage must be greater than the
-- @ThresholdPercentage@ or must be greater than or equal to the
-- @ThreholdPercentage@ to be approved.
approvalThresholdPolicy_thresholdComparator :: Lens.Lens' ApprovalThresholdPolicy (Prelude.Maybe ThresholdComparator)
approvalThresholdPolicy_thresholdComparator :: (Maybe ThresholdComparator -> f (Maybe ThresholdComparator))
-> ApprovalThresholdPolicy -> f ApprovalThresholdPolicy
approvalThresholdPolicy_thresholdComparator = (ApprovalThresholdPolicy -> Maybe ThresholdComparator)
-> (ApprovalThresholdPolicy
    -> Maybe ThresholdComparator -> ApprovalThresholdPolicy)
-> Lens
     ApprovalThresholdPolicy
     ApprovalThresholdPolicy
     (Maybe ThresholdComparator)
     (Maybe ThresholdComparator)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApprovalThresholdPolicy' {Maybe ThresholdComparator
thresholdComparator :: Maybe ThresholdComparator
$sel:thresholdComparator:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe ThresholdComparator
thresholdComparator} -> Maybe ThresholdComparator
thresholdComparator) (\s :: ApprovalThresholdPolicy
s@ApprovalThresholdPolicy' {} Maybe ThresholdComparator
a -> ApprovalThresholdPolicy
s {$sel:thresholdComparator:ApprovalThresholdPolicy' :: Maybe ThresholdComparator
thresholdComparator = Maybe ThresholdComparator
a} :: ApprovalThresholdPolicy)

-- | The duration from the time that a proposal is created until it expires.
-- If members cast neither the required number of @YES@ votes to approve
-- the proposal nor the number of @NO@ votes required to reject it before
-- the duration expires, the proposal is @EXPIRED@ and @ProposalActions@
-- are not carried out.
approvalThresholdPolicy_proposalDurationInHours :: Lens.Lens' ApprovalThresholdPolicy (Prelude.Maybe Prelude.Natural)
approvalThresholdPolicy_proposalDurationInHours :: (Maybe Natural -> f (Maybe Natural))
-> ApprovalThresholdPolicy -> f ApprovalThresholdPolicy
approvalThresholdPolicy_proposalDurationInHours = (ApprovalThresholdPolicy -> Maybe Natural)
-> (ApprovalThresholdPolicy
    -> Maybe Natural -> ApprovalThresholdPolicy)
-> Lens
     ApprovalThresholdPolicy
     ApprovalThresholdPolicy
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApprovalThresholdPolicy' {Maybe Natural
proposalDurationInHours :: Maybe Natural
$sel:proposalDurationInHours:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
proposalDurationInHours} -> Maybe Natural
proposalDurationInHours) (\s :: ApprovalThresholdPolicy
s@ApprovalThresholdPolicy' {} Maybe Natural
a -> ApprovalThresholdPolicy
s {$sel:proposalDurationInHours:ApprovalThresholdPolicy' :: Maybe Natural
proposalDurationInHours = Maybe Natural
a} :: ApprovalThresholdPolicy)

instance Core.FromJSON ApprovalThresholdPolicy where
  parseJSON :: Value -> Parser ApprovalThresholdPolicy
parseJSON =
    String
-> (Object -> Parser ApprovalThresholdPolicy)
-> Value
-> Parser ApprovalThresholdPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ApprovalThresholdPolicy"
      ( \Object
x ->
          Maybe Natural
-> Maybe ThresholdComparator
-> Maybe Natural
-> ApprovalThresholdPolicy
ApprovalThresholdPolicy'
            (Maybe Natural
 -> Maybe ThresholdComparator
 -> Maybe Natural
 -> ApprovalThresholdPolicy)
-> Parser (Maybe Natural)
-> Parser
     (Maybe ThresholdComparator
      -> Maybe Natural -> ApprovalThresholdPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ThresholdPercentage")
            Parser
  (Maybe ThresholdComparator
   -> Maybe Natural -> ApprovalThresholdPolicy)
-> Parser (Maybe ThresholdComparator)
-> Parser (Maybe Natural -> ApprovalThresholdPolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ThresholdComparator)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ThresholdComparator")
            Parser (Maybe Natural -> ApprovalThresholdPolicy)
-> Parser (Maybe Natural) -> Parser ApprovalThresholdPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ProposalDurationInHours")
      )

instance Prelude.Hashable ApprovalThresholdPolicy

instance Prelude.NFData ApprovalThresholdPolicy

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