{-# 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-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.ApprovalThresholdPolicy 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.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 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@
    -- aren\'t carried out.
    ApprovalThresholdPolicy -> Maybe Natural
proposalDurationInHours :: 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 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
  }
  deriving (ApprovalThresholdPolicy -> ApprovalThresholdPolicy -> Bool
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]
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
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. 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:
--
-- '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@
-- aren\'t carried out.
--
-- '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.
--
-- '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.
newApprovalThresholdPolicy ::
  ApprovalThresholdPolicy
newApprovalThresholdPolicy :: ApprovalThresholdPolicy
newApprovalThresholdPolicy =
  ApprovalThresholdPolicy'
    { $sel:proposalDurationInHours:ApprovalThresholdPolicy' :: Maybe Natural
proposalDurationInHours =
        forall a. Maybe a
Prelude.Nothing,
      $sel:thresholdComparator:ApprovalThresholdPolicy' :: Maybe ThresholdComparator
thresholdComparator = forall a. Maybe a
Prelude.Nothing,
      $sel:thresholdPercentage:ApprovalThresholdPolicy' :: Maybe Natural
thresholdPercentage = forall a. Maybe a
Prelude.Nothing
    }

-- | 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@
-- aren\'t carried out.
approvalThresholdPolicy_proposalDurationInHours :: Lens.Lens' ApprovalThresholdPolicy (Prelude.Maybe Prelude.Natural)
approvalThresholdPolicy_proposalDurationInHours :: Lens' ApprovalThresholdPolicy (Maybe Natural)
approvalThresholdPolicy_proposalDurationInHours = 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)

-- | 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 :: Lens' ApprovalThresholdPolicy (Maybe ThresholdComparator)
approvalThresholdPolicy_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 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 :: Lens' ApprovalThresholdPolicy (Maybe Natural)
approvalThresholdPolicy_thresholdPercentage = 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)

instance Data.FromJSON ApprovalThresholdPolicy where
  parseJSON :: Value -> Parser ApprovalThresholdPolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ApprovalThresholdPolicy"
      ( \Object
x ->
          Maybe Natural
-> Maybe ThresholdComparator
-> Maybe Natural
-> ApprovalThresholdPolicy
ApprovalThresholdPolicy'
            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
"ProposalDurationInHours")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ThresholdComparator")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ThresholdPercentage")
      )

instance Prelude.Hashable ApprovalThresholdPolicy where
  hashWithSalt :: Int -> ApprovalThresholdPolicy -> Int
hashWithSalt Int
_salt ApprovalThresholdPolicy' {Maybe Natural
Maybe ThresholdComparator
thresholdPercentage :: Maybe Natural
thresholdComparator :: Maybe ThresholdComparator
proposalDurationInHours :: Maybe Natural
$sel:thresholdPercentage:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
$sel:thresholdComparator:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe ThresholdComparator
$sel:proposalDurationInHours:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
proposalDurationInHours
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ThresholdComparator
thresholdComparator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
thresholdPercentage

instance Prelude.NFData ApprovalThresholdPolicy where
  rnf :: ApprovalThresholdPolicy -> ()
rnf ApprovalThresholdPolicy' {Maybe Natural
Maybe ThresholdComparator
thresholdPercentage :: Maybe Natural
thresholdComparator :: Maybe ThresholdComparator
proposalDurationInHours :: Maybe Natural
$sel:thresholdPercentage:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
$sel:thresholdComparator:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe ThresholdComparator
$sel:proposalDurationInHours:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
proposalDurationInHours
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ThresholdComparator
thresholdComparator
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
thresholdPercentage

instance Data.ToJSON ApprovalThresholdPolicy where
  toJSON :: ApprovalThresholdPolicy -> Value
toJSON ApprovalThresholdPolicy' {Maybe Natural
Maybe ThresholdComparator
thresholdPercentage :: Maybe Natural
thresholdComparator :: Maybe ThresholdComparator
proposalDurationInHours :: Maybe Natural
$sel:thresholdPercentage:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
$sel:thresholdComparator:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe ThresholdComparator
$sel:proposalDurationInHours:ApprovalThresholdPolicy' :: ApprovalThresholdPolicy -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ProposalDurationInHours" 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 Natural
proposalDurationInHours,
            (Key
"ThresholdComparator" 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 ThresholdComparator
thresholdComparator,
            (Key
"ThresholdPercentage" 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 Natural
thresholdPercentage
          ]
      )