{-# 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.Route53RecoveryControlConfig.Types.RuleConfig
-- 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.Route53RecoveryControlConfig.Types.RuleConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Route53RecoveryControlConfig.Types.RuleType

-- | The rule configuration for an assertion rule. That is, the criteria that
-- you set for specific assertion controls (routing controls) that specify
-- how many controls must be enabled after a transaction completes.
--
-- /See:/ 'newRuleConfig' smart constructor.
data RuleConfig = RuleConfig'
  { -- | A rule can be one of the following: ATLEAST, AND, or OR.
    RuleConfig -> RuleType
type' :: RuleType,
    -- | Logical negation of the rule. If the rule would usually evaluate true,
    -- it\'s evaluated as false, and vice versa.
    RuleConfig -> Bool
inverted :: Prelude.Bool,
    -- | The value of N, when you specify an ATLEAST rule type. That is,
    -- Threshold is the number of controls that must be set when you specify an
    -- ATLEAST type.
    RuleConfig -> Int
threshold :: Prelude.Int
  }
  deriving (RuleConfig -> RuleConfig -> Bool
(RuleConfig -> RuleConfig -> Bool)
-> (RuleConfig -> RuleConfig -> Bool) -> Eq RuleConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuleConfig -> RuleConfig -> Bool
$c/= :: RuleConfig -> RuleConfig -> Bool
== :: RuleConfig -> RuleConfig -> Bool
$c== :: RuleConfig -> RuleConfig -> Bool
Prelude.Eq, ReadPrec [RuleConfig]
ReadPrec RuleConfig
Int -> ReadS RuleConfig
ReadS [RuleConfig]
(Int -> ReadS RuleConfig)
-> ReadS [RuleConfig]
-> ReadPrec RuleConfig
-> ReadPrec [RuleConfig]
-> Read RuleConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuleConfig]
$creadListPrec :: ReadPrec [RuleConfig]
readPrec :: ReadPrec RuleConfig
$creadPrec :: ReadPrec RuleConfig
readList :: ReadS [RuleConfig]
$creadList :: ReadS [RuleConfig]
readsPrec :: Int -> ReadS RuleConfig
$creadsPrec :: Int -> ReadS RuleConfig
Prelude.Read, Int -> RuleConfig -> ShowS
[RuleConfig] -> ShowS
RuleConfig -> String
(Int -> RuleConfig -> ShowS)
-> (RuleConfig -> String)
-> ([RuleConfig] -> ShowS)
-> Show RuleConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuleConfig] -> ShowS
$cshowList :: [RuleConfig] -> ShowS
show :: RuleConfig -> String
$cshow :: RuleConfig -> String
showsPrec :: Int -> RuleConfig -> ShowS
$cshowsPrec :: Int -> RuleConfig -> ShowS
Prelude.Show, (forall x. RuleConfig -> Rep RuleConfig x)
-> (forall x. Rep RuleConfig x -> RuleConfig) -> Generic RuleConfig
forall x. Rep RuleConfig x -> RuleConfig
forall x. RuleConfig -> Rep RuleConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuleConfig x -> RuleConfig
$cfrom :: forall x. RuleConfig -> Rep RuleConfig x
Prelude.Generic)

-- |
-- Create a value of 'RuleConfig' 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:
--
-- 'type'', 'ruleConfig_type' - A rule can be one of the following: ATLEAST, AND, or OR.
--
-- 'inverted', 'ruleConfig_inverted' - Logical negation of the rule. If the rule would usually evaluate true,
-- it\'s evaluated as false, and vice versa.
--
-- 'threshold', 'ruleConfig_threshold' - The value of N, when you specify an ATLEAST rule type. That is,
-- Threshold is the number of controls that must be set when you specify an
-- ATLEAST type.
newRuleConfig ::
  -- | 'type''
  RuleType ->
  -- | 'inverted'
  Prelude.Bool ->
  -- | 'threshold'
  Prelude.Int ->
  RuleConfig
newRuleConfig :: RuleType -> Bool -> Int -> RuleConfig
newRuleConfig RuleType
pType_ Bool
pInverted_ Int
pThreshold_ =
  RuleConfig' :: RuleType -> Bool -> Int -> RuleConfig
RuleConfig'
    { $sel:type':RuleConfig' :: RuleType
type' = RuleType
pType_,
      $sel:inverted:RuleConfig' :: Bool
inverted = Bool
pInverted_,
      $sel:threshold:RuleConfig' :: Int
threshold = Int
pThreshold_
    }

-- | A rule can be one of the following: ATLEAST, AND, or OR.
ruleConfig_type :: Lens.Lens' RuleConfig RuleType
ruleConfig_type :: (RuleType -> f RuleType) -> RuleConfig -> f RuleConfig
ruleConfig_type = (RuleConfig -> RuleType)
-> (RuleConfig -> RuleType -> RuleConfig)
-> Lens RuleConfig RuleConfig RuleType RuleType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleConfig' {RuleType
type' :: RuleType
$sel:type':RuleConfig' :: RuleConfig -> RuleType
type'} -> RuleType
type') (\s :: RuleConfig
s@RuleConfig' {} RuleType
a -> RuleConfig
s {$sel:type':RuleConfig' :: RuleType
type' = RuleType
a} :: RuleConfig)

-- | Logical negation of the rule. If the rule would usually evaluate true,
-- it\'s evaluated as false, and vice versa.
ruleConfig_inverted :: Lens.Lens' RuleConfig Prelude.Bool
ruleConfig_inverted :: (Bool -> f Bool) -> RuleConfig -> f RuleConfig
ruleConfig_inverted = (RuleConfig -> Bool)
-> (RuleConfig -> Bool -> RuleConfig)
-> Lens RuleConfig RuleConfig Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleConfig' {Bool
inverted :: Bool
$sel:inverted:RuleConfig' :: RuleConfig -> Bool
inverted} -> Bool
inverted) (\s :: RuleConfig
s@RuleConfig' {} Bool
a -> RuleConfig
s {$sel:inverted:RuleConfig' :: Bool
inverted = Bool
a} :: RuleConfig)

-- | The value of N, when you specify an ATLEAST rule type. That is,
-- Threshold is the number of controls that must be set when you specify an
-- ATLEAST type.
ruleConfig_threshold :: Lens.Lens' RuleConfig Prelude.Int
ruleConfig_threshold :: (Int -> f Int) -> RuleConfig -> f RuleConfig
ruleConfig_threshold = (RuleConfig -> Int)
-> (RuleConfig -> Int -> RuleConfig)
-> Lens RuleConfig RuleConfig Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleConfig' {Int
threshold :: Int
$sel:threshold:RuleConfig' :: RuleConfig -> Int
threshold} -> Int
threshold) (\s :: RuleConfig
s@RuleConfig' {} Int
a -> RuleConfig
s {$sel:threshold:RuleConfig' :: Int
threshold = Int
a} :: RuleConfig)

instance Core.FromJSON RuleConfig where
  parseJSON :: Value -> Parser RuleConfig
parseJSON =
    String
-> (Object -> Parser RuleConfig) -> Value -> Parser RuleConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RuleConfig"
      ( \Object
x ->
          RuleType -> Bool -> Int -> RuleConfig
RuleConfig'
            (RuleType -> Bool -> Int -> RuleConfig)
-> Parser RuleType -> Parser (Bool -> Int -> RuleConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser RuleType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
            Parser (Bool -> Int -> RuleConfig)
-> Parser Bool -> Parser (Int -> RuleConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Inverted")
            Parser (Int -> RuleConfig) -> Parser Int -> Parser RuleConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Threshold")
      )

instance Prelude.Hashable RuleConfig

instance Prelude.NFData RuleConfig

instance Core.ToJSON RuleConfig where
  toJSON :: RuleConfig -> Value
toJSON RuleConfig' {Bool
Int
RuleType
threshold :: Int
inverted :: Bool
type' :: RuleType
$sel:threshold:RuleConfig' :: RuleConfig -> Int
$sel:inverted:RuleConfig' :: RuleConfig -> Bool
$sel:type':RuleConfig' :: RuleConfig -> RuleType
..} =
    [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
"Type" Text -> RuleType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RuleType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Inverted" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
inverted),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Threshold" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
threshold)
          ]
      )