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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.Route53RecoveryControlConfig.Types.RuleConfig

-- | A new gating rule for a control panel.
--
-- /See:/ 'newNewGatingRule' smart constructor.
data NewGatingRule = NewGatingRule'
  { -- | Routing controls that can only be set or unset if the specified
    -- RuleConfig evaluates to true for the specified GatingControls. For
    -- example, say you have three gating controls, one for each of three
    -- Amazon Web Services Regions. Now you specify ATLEAST 2 as your
    -- RuleConfig. With these settings, you can only change (set or unset) the
    -- routing controls that you have specified as TargetControls if that rule
    -- evaluates to true.
    --
    -- In other words, your ability to change the routing controls that you
    -- have specified as TargetControls is gated by the rule that you set for
    -- the routing controls in GatingControls.
    NewGatingRule -> [Text]
targetControls :: [Prelude.Text],
    -- | The Amazon Resource Name (ARN) of the control panel.
    NewGatingRule -> Text
controlPanelArn :: Prelude.Text,
    -- | The gating controls for the new gating rule. That is, routing controls
    -- that are evaluated by the rule configuration that you specify.
    NewGatingRule -> [Text]
gatingControls :: [Prelude.Text],
    -- | The criteria that you set for specific gating controls (routing
    -- controls) that designate how many control states must be ON to allow you
    -- to change (set or unset) the target control states.
    NewGatingRule -> RuleConfig
ruleConfig :: RuleConfig,
    -- | An evaluation period, in milliseconds (ms), during which any request
    -- against the target routing controls will fail. This helps prevent
    -- \"flapping\" of state. The wait period is 5000 ms by default, but you
    -- can choose a custom value.
    NewGatingRule -> Int
waitPeriodMs :: Prelude.Int,
    -- | The name for the new gating rule.
    NewGatingRule -> Text
name :: Prelude.Text
  }
  deriving (NewGatingRule -> NewGatingRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NewGatingRule -> NewGatingRule -> Bool
$c/= :: NewGatingRule -> NewGatingRule -> Bool
== :: NewGatingRule -> NewGatingRule -> Bool
$c== :: NewGatingRule -> NewGatingRule -> Bool
Prelude.Eq, ReadPrec [NewGatingRule]
ReadPrec NewGatingRule
Int -> ReadS NewGatingRule
ReadS [NewGatingRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NewGatingRule]
$creadListPrec :: ReadPrec [NewGatingRule]
readPrec :: ReadPrec NewGatingRule
$creadPrec :: ReadPrec NewGatingRule
readList :: ReadS [NewGatingRule]
$creadList :: ReadS [NewGatingRule]
readsPrec :: Int -> ReadS NewGatingRule
$creadsPrec :: Int -> ReadS NewGatingRule
Prelude.Read, Int -> NewGatingRule -> ShowS
[NewGatingRule] -> ShowS
NewGatingRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NewGatingRule] -> ShowS
$cshowList :: [NewGatingRule] -> ShowS
show :: NewGatingRule -> String
$cshow :: NewGatingRule -> String
showsPrec :: Int -> NewGatingRule -> ShowS
$cshowsPrec :: Int -> NewGatingRule -> ShowS
Prelude.Show, forall x. Rep NewGatingRule x -> NewGatingRule
forall x. NewGatingRule -> Rep NewGatingRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NewGatingRule x -> NewGatingRule
$cfrom :: forall x. NewGatingRule -> Rep NewGatingRule x
Prelude.Generic)

-- |
-- Create a value of 'NewGatingRule' 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:
--
-- 'targetControls', 'newGatingRule_targetControls' - Routing controls that can only be set or unset if the specified
-- RuleConfig evaluates to true for the specified GatingControls. For
-- example, say you have three gating controls, one for each of three
-- Amazon Web Services Regions. Now you specify ATLEAST 2 as your
-- RuleConfig. With these settings, you can only change (set or unset) the
-- routing controls that you have specified as TargetControls if that rule
-- evaluates to true.
--
-- In other words, your ability to change the routing controls that you
-- have specified as TargetControls is gated by the rule that you set for
-- the routing controls in GatingControls.
--
-- 'controlPanelArn', 'newGatingRule_controlPanelArn' - The Amazon Resource Name (ARN) of the control panel.
--
-- 'gatingControls', 'newGatingRule_gatingControls' - The gating controls for the new gating rule. That is, routing controls
-- that are evaluated by the rule configuration that you specify.
--
-- 'ruleConfig', 'newGatingRule_ruleConfig' - The criteria that you set for specific gating controls (routing
-- controls) that designate how many control states must be ON to allow you
-- to change (set or unset) the target control states.
--
-- 'waitPeriodMs', 'newGatingRule_waitPeriodMs' - An evaluation period, in milliseconds (ms), during which any request
-- against the target routing controls will fail. This helps prevent
-- \"flapping\" of state. The wait period is 5000 ms by default, but you
-- can choose a custom value.
--
-- 'name', 'newGatingRule_name' - The name for the new gating rule.
newNewGatingRule ::
  -- | 'controlPanelArn'
  Prelude.Text ->
  -- | 'ruleConfig'
  RuleConfig ->
  -- | 'waitPeriodMs'
  Prelude.Int ->
  -- | 'name'
  Prelude.Text ->
  NewGatingRule
newNewGatingRule :: Text -> RuleConfig -> Int -> Text -> NewGatingRule
newNewGatingRule
  Text
pControlPanelArn_
  RuleConfig
pRuleConfig_
  Int
pWaitPeriodMs_
  Text
pName_ =
    NewGatingRule'
      { $sel:targetControls:NewGatingRule' :: [Text]
targetControls = forall a. Monoid a => a
Prelude.mempty,
        $sel:controlPanelArn:NewGatingRule' :: Text
controlPanelArn = Text
pControlPanelArn_,
        $sel:gatingControls:NewGatingRule' :: [Text]
gatingControls = forall a. Monoid a => a
Prelude.mempty,
        $sel:ruleConfig:NewGatingRule' :: RuleConfig
ruleConfig = RuleConfig
pRuleConfig_,
        $sel:waitPeriodMs:NewGatingRule' :: Int
waitPeriodMs = Int
pWaitPeriodMs_,
        $sel:name:NewGatingRule' :: Text
name = Text
pName_
      }

-- | Routing controls that can only be set or unset if the specified
-- RuleConfig evaluates to true for the specified GatingControls. For
-- example, say you have three gating controls, one for each of three
-- Amazon Web Services Regions. Now you specify ATLEAST 2 as your
-- RuleConfig. With these settings, you can only change (set or unset) the
-- routing controls that you have specified as TargetControls if that rule
-- evaluates to true.
--
-- In other words, your ability to change the routing controls that you
-- have specified as TargetControls is gated by the rule that you set for
-- the routing controls in GatingControls.
newGatingRule_targetControls :: Lens.Lens' NewGatingRule [Prelude.Text]
newGatingRule_targetControls :: Lens' NewGatingRule [Text]
newGatingRule_targetControls = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NewGatingRule' {[Text]
targetControls :: [Text]
$sel:targetControls:NewGatingRule' :: NewGatingRule -> [Text]
targetControls} -> [Text]
targetControls) (\s :: NewGatingRule
s@NewGatingRule' {} [Text]
a -> NewGatingRule
s {$sel:targetControls:NewGatingRule' :: [Text]
targetControls = [Text]
a} :: NewGatingRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the control panel.
newGatingRule_controlPanelArn :: Lens.Lens' NewGatingRule Prelude.Text
newGatingRule_controlPanelArn :: Lens' NewGatingRule Text
newGatingRule_controlPanelArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NewGatingRule' {Text
controlPanelArn :: Text
$sel:controlPanelArn:NewGatingRule' :: NewGatingRule -> Text
controlPanelArn} -> Text
controlPanelArn) (\s :: NewGatingRule
s@NewGatingRule' {} Text
a -> NewGatingRule
s {$sel:controlPanelArn:NewGatingRule' :: Text
controlPanelArn = Text
a} :: NewGatingRule)

-- | The gating controls for the new gating rule. That is, routing controls
-- that are evaluated by the rule configuration that you specify.
newGatingRule_gatingControls :: Lens.Lens' NewGatingRule [Prelude.Text]
newGatingRule_gatingControls :: Lens' NewGatingRule [Text]
newGatingRule_gatingControls = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NewGatingRule' {[Text]
gatingControls :: [Text]
$sel:gatingControls:NewGatingRule' :: NewGatingRule -> [Text]
gatingControls} -> [Text]
gatingControls) (\s :: NewGatingRule
s@NewGatingRule' {} [Text]
a -> NewGatingRule
s {$sel:gatingControls:NewGatingRule' :: [Text]
gatingControls = [Text]
a} :: NewGatingRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The criteria that you set for specific gating controls (routing
-- controls) that designate how many control states must be ON to allow you
-- to change (set or unset) the target control states.
newGatingRule_ruleConfig :: Lens.Lens' NewGatingRule RuleConfig
newGatingRule_ruleConfig :: Lens' NewGatingRule RuleConfig
newGatingRule_ruleConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NewGatingRule' {RuleConfig
ruleConfig :: RuleConfig
$sel:ruleConfig:NewGatingRule' :: NewGatingRule -> RuleConfig
ruleConfig} -> RuleConfig
ruleConfig) (\s :: NewGatingRule
s@NewGatingRule' {} RuleConfig
a -> NewGatingRule
s {$sel:ruleConfig:NewGatingRule' :: RuleConfig
ruleConfig = RuleConfig
a} :: NewGatingRule)

-- | An evaluation period, in milliseconds (ms), during which any request
-- against the target routing controls will fail. This helps prevent
-- \"flapping\" of state. The wait period is 5000 ms by default, but you
-- can choose a custom value.
newGatingRule_waitPeriodMs :: Lens.Lens' NewGatingRule Prelude.Int
newGatingRule_waitPeriodMs :: Lens' NewGatingRule Int
newGatingRule_waitPeriodMs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NewGatingRule' {Int
waitPeriodMs :: Int
$sel:waitPeriodMs:NewGatingRule' :: NewGatingRule -> Int
waitPeriodMs} -> Int
waitPeriodMs) (\s :: NewGatingRule
s@NewGatingRule' {} Int
a -> NewGatingRule
s {$sel:waitPeriodMs:NewGatingRule' :: Int
waitPeriodMs = Int
a} :: NewGatingRule)

-- | The name for the new gating rule.
newGatingRule_name :: Lens.Lens' NewGatingRule Prelude.Text
newGatingRule_name :: Lens' NewGatingRule Text
newGatingRule_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NewGatingRule' {Text
name :: Text
$sel:name:NewGatingRule' :: NewGatingRule -> Text
name} -> Text
name) (\s :: NewGatingRule
s@NewGatingRule' {} Text
a -> NewGatingRule
s {$sel:name:NewGatingRule' :: Text
name = Text
a} :: NewGatingRule)

instance Prelude.Hashable NewGatingRule where
  hashWithSalt :: Int -> NewGatingRule -> Int
hashWithSalt Int
_salt NewGatingRule' {Int
[Text]
Text
RuleConfig
name :: Text
waitPeriodMs :: Int
ruleConfig :: RuleConfig
gatingControls :: [Text]
controlPanelArn :: Text
targetControls :: [Text]
$sel:name:NewGatingRule' :: NewGatingRule -> Text
$sel:waitPeriodMs:NewGatingRule' :: NewGatingRule -> Int
$sel:ruleConfig:NewGatingRule' :: NewGatingRule -> RuleConfig
$sel:gatingControls:NewGatingRule' :: NewGatingRule -> [Text]
$sel:controlPanelArn:NewGatingRule' :: NewGatingRule -> Text
$sel:targetControls:NewGatingRule' :: NewGatingRule -> [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
targetControls
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
controlPanelArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
gatingControls
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RuleConfig
ruleConfig
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
waitPeriodMs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData NewGatingRule where
  rnf :: NewGatingRule -> ()
rnf NewGatingRule' {Int
[Text]
Text
RuleConfig
name :: Text
waitPeriodMs :: Int
ruleConfig :: RuleConfig
gatingControls :: [Text]
controlPanelArn :: Text
targetControls :: [Text]
$sel:name:NewGatingRule' :: NewGatingRule -> Text
$sel:waitPeriodMs:NewGatingRule' :: NewGatingRule -> Int
$sel:ruleConfig:NewGatingRule' :: NewGatingRule -> RuleConfig
$sel:gatingControls:NewGatingRule' :: NewGatingRule -> [Text]
$sel:controlPanelArn:NewGatingRule' :: NewGatingRule -> Text
$sel:targetControls:NewGatingRule' :: NewGatingRule -> [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [Text]
targetControls
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
controlPanelArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
gatingControls
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf RuleConfig
ruleConfig
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
waitPeriodMs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToJSON NewGatingRule where
  toJSON :: NewGatingRule -> Value
toJSON NewGatingRule' {Int
[Text]
Text
RuleConfig
name :: Text
waitPeriodMs :: Int
ruleConfig :: RuleConfig
gatingControls :: [Text]
controlPanelArn :: Text
targetControls :: [Text]
$sel:name:NewGatingRule' :: NewGatingRule -> Text
$sel:waitPeriodMs:NewGatingRule' :: NewGatingRule -> Int
$sel:ruleConfig:NewGatingRule' :: NewGatingRule -> RuleConfig
$sel:gatingControls:NewGatingRule' :: NewGatingRule -> [Text]
$sel:controlPanelArn:NewGatingRule' :: NewGatingRule -> Text
$sel:targetControls:NewGatingRule' :: NewGatingRule -> [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"TargetControls" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
targetControls),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ControlPanelArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
controlPanelArn),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"GatingControls" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
gatingControls),
            forall a. a -> Maybe a
Prelude.Just (Key
"RuleConfig" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= RuleConfig
ruleConfig),
            forall a. a -> Maybe a
Prelude.Just (Key
"WaitPeriodMs" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
waitPeriodMs),
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )