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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Route53RecoveryControlConfig.Types.RuleConfig
import Amazonka.Route53RecoveryControlConfig.Types.Status

-- | A gating rule verifies that a set of gating controls evaluates as true,
-- based on a rule configuration that you specify. If the gating rule
-- evaluates to true, Amazon Route 53 Application Recovery Controller
-- allows a set of routing control state changes to run and complete
-- against the set of target controls.
--
-- /See:/ 'newGatingRule' smart constructor.
data GatingRule = GatingRule'
  { -- | The deployment status of a gating rule. Status can be one of the
    -- following: PENDING, DEPLOYED, PENDING_DELETION.
    GatingRule -> Status
status :: Status,
    -- | 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.
    GatingRule -> [Text]
targetControls :: [Prelude.Text],
    -- | The Amazon Resource Name (ARN) of the control panel.
    GatingRule -> Text
controlPanelArn :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the gating rule.
    GatingRule -> Text
safetyRuleArn :: Prelude.Text,
    -- | The gating controls for the gating rule. That is, routing controls that
    -- are evaluated by the rule configuration that you specify.
    GatingRule -> [Text]
gatingControls :: [Prelude.Text],
    -- | The criteria that you set for specific gating controls (routing
    -- controls) that designates how many controls must be enabled to allow you
    -- to change (set or unset) the target controls.
    GatingRule -> 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.
    GatingRule -> Int
waitPeriodMs :: Prelude.Int,
    -- | The name for the gating rule.
    GatingRule -> Text
name :: Prelude.Text
  }
  deriving (GatingRule -> GatingRule -> Bool
(GatingRule -> GatingRule -> Bool)
-> (GatingRule -> GatingRule -> Bool) -> Eq GatingRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GatingRule -> GatingRule -> Bool
$c/= :: GatingRule -> GatingRule -> Bool
== :: GatingRule -> GatingRule -> Bool
$c== :: GatingRule -> GatingRule -> Bool
Prelude.Eq, ReadPrec [GatingRule]
ReadPrec GatingRule
Int -> ReadS GatingRule
ReadS [GatingRule]
(Int -> ReadS GatingRule)
-> ReadS [GatingRule]
-> ReadPrec GatingRule
-> ReadPrec [GatingRule]
-> Read GatingRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GatingRule]
$creadListPrec :: ReadPrec [GatingRule]
readPrec :: ReadPrec GatingRule
$creadPrec :: ReadPrec GatingRule
readList :: ReadS [GatingRule]
$creadList :: ReadS [GatingRule]
readsPrec :: Int -> ReadS GatingRule
$creadsPrec :: Int -> ReadS GatingRule
Prelude.Read, Int -> GatingRule -> ShowS
[GatingRule] -> ShowS
GatingRule -> String
(Int -> GatingRule -> ShowS)
-> (GatingRule -> String)
-> ([GatingRule] -> ShowS)
-> Show GatingRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GatingRule] -> ShowS
$cshowList :: [GatingRule] -> ShowS
show :: GatingRule -> String
$cshow :: GatingRule -> String
showsPrec :: Int -> GatingRule -> ShowS
$cshowsPrec :: Int -> GatingRule -> ShowS
Prelude.Show, (forall x. GatingRule -> Rep GatingRule x)
-> (forall x. Rep GatingRule x -> GatingRule) -> Generic GatingRule
forall x. Rep GatingRule x -> GatingRule
forall x. GatingRule -> Rep GatingRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GatingRule x -> GatingRule
$cfrom :: forall x. GatingRule -> Rep GatingRule x
Prelude.Generic)

-- |
-- Create a value of 'GatingRule' 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:
--
-- 'status', 'gatingRule_status' - The deployment status of a gating rule. Status can be one of the
-- following: PENDING, DEPLOYED, PENDING_DELETION.
--
-- 'targetControls', 'gatingRule_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', 'gatingRule_controlPanelArn' - The Amazon Resource Name (ARN) of the control panel.
--
-- 'safetyRuleArn', 'gatingRule_safetyRuleArn' - The Amazon Resource Name (ARN) of the gating rule.
--
-- 'gatingControls', 'gatingRule_gatingControls' - The gating controls for the gating rule. That is, routing controls that
-- are evaluated by the rule configuration that you specify.
--
-- 'ruleConfig', 'gatingRule_ruleConfig' - The criteria that you set for specific gating controls (routing
-- controls) that designates how many controls must be enabled to allow you
-- to change (set or unset) the target controls.
--
-- 'waitPeriodMs', 'gatingRule_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', 'gatingRule_name' - The name for the gating rule.
newGatingRule ::
  -- | 'status'
  Status ->
  -- | 'controlPanelArn'
  Prelude.Text ->
  -- | 'safetyRuleArn'
  Prelude.Text ->
  -- | 'ruleConfig'
  RuleConfig ->
  -- | 'waitPeriodMs'
  Prelude.Int ->
  -- | 'name'
  Prelude.Text ->
  GatingRule
newGatingRule :: Status -> Text -> Text -> RuleConfig -> Int -> Text -> GatingRule
newGatingRule
  Status
pStatus_
  Text
pControlPanelArn_
  Text
pSafetyRuleArn_
  RuleConfig
pRuleConfig_
  Int
pWaitPeriodMs_
  Text
pName_ =
    GatingRule' :: Status
-> [Text]
-> Text
-> Text
-> [Text]
-> RuleConfig
-> Int
-> Text
-> GatingRule
GatingRule'
      { $sel:status:GatingRule' :: Status
status = Status
pStatus_,
        $sel:targetControls:GatingRule' :: [Text]
targetControls = [Text]
forall a. Monoid a => a
Prelude.mempty,
        $sel:controlPanelArn:GatingRule' :: Text
controlPanelArn = Text
pControlPanelArn_,
        $sel:safetyRuleArn:GatingRule' :: Text
safetyRuleArn = Text
pSafetyRuleArn_,
        $sel:gatingControls:GatingRule' :: [Text]
gatingControls = [Text]
forall a. Monoid a => a
Prelude.mempty,
        $sel:ruleConfig:GatingRule' :: RuleConfig
ruleConfig = RuleConfig
pRuleConfig_,
        $sel:waitPeriodMs:GatingRule' :: Int
waitPeriodMs = Int
pWaitPeriodMs_,
        $sel:name:GatingRule' :: Text
name = Text
pName_
      }

-- | The deployment status of a gating rule. Status can be one of the
-- following: PENDING, DEPLOYED, PENDING_DELETION.
gatingRule_status :: Lens.Lens' GatingRule Status
gatingRule_status :: (Status -> f Status) -> GatingRule -> f GatingRule
gatingRule_status = (GatingRule -> Status)
-> (GatingRule -> Status -> GatingRule)
-> Lens GatingRule GatingRule Status Status
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatingRule' {Status
status :: Status
$sel:status:GatingRule' :: GatingRule -> Status
status} -> Status
status) (\s :: GatingRule
s@GatingRule' {} Status
a -> GatingRule
s {$sel:status:GatingRule' :: Status
status = Status
a} :: GatingRule)

-- | 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.
gatingRule_targetControls :: Lens.Lens' GatingRule [Prelude.Text]
gatingRule_targetControls :: ([Text] -> f [Text]) -> GatingRule -> f GatingRule
gatingRule_targetControls = (GatingRule -> [Text])
-> (GatingRule -> [Text] -> GatingRule)
-> Lens GatingRule GatingRule [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatingRule' {[Text]
targetControls :: [Text]
$sel:targetControls:GatingRule' :: GatingRule -> [Text]
targetControls} -> [Text]
targetControls) (\s :: GatingRule
s@GatingRule' {} [Text]
a -> GatingRule
s {$sel:targetControls:GatingRule' :: [Text]
targetControls = [Text]
a} :: GatingRule) (([Text] -> f [Text]) -> GatingRule -> f GatingRule)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GatingRule
-> f GatingRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
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.
gatingRule_controlPanelArn :: Lens.Lens' GatingRule Prelude.Text
gatingRule_controlPanelArn :: (Text -> f Text) -> GatingRule -> f GatingRule
gatingRule_controlPanelArn = (GatingRule -> Text)
-> (GatingRule -> Text -> GatingRule)
-> Lens GatingRule GatingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatingRule' {Text
controlPanelArn :: Text
$sel:controlPanelArn:GatingRule' :: GatingRule -> Text
controlPanelArn} -> Text
controlPanelArn) (\s :: GatingRule
s@GatingRule' {} Text
a -> GatingRule
s {$sel:controlPanelArn:GatingRule' :: Text
controlPanelArn = Text
a} :: GatingRule)

-- | The Amazon Resource Name (ARN) of the gating rule.
gatingRule_safetyRuleArn :: Lens.Lens' GatingRule Prelude.Text
gatingRule_safetyRuleArn :: (Text -> f Text) -> GatingRule -> f GatingRule
gatingRule_safetyRuleArn = (GatingRule -> Text)
-> (GatingRule -> Text -> GatingRule)
-> Lens GatingRule GatingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatingRule' {Text
safetyRuleArn :: Text
$sel:safetyRuleArn:GatingRule' :: GatingRule -> Text
safetyRuleArn} -> Text
safetyRuleArn) (\s :: GatingRule
s@GatingRule' {} Text
a -> GatingRule
s {$sel:safetyRuleArn:GatingRule' :: Text
safetyRuleArn = Text
a} :: GatingRule)

-- | The gating controls for the gating rule. That is, routing controls that
-- are evaluated by the rule configuration that you specify.
gatingRule_gatingControls :: Lens.Lens' GatingRule [Prelude.Text]
gatingRule_gatingControls :: ([Text] -> f [Text]) -> GatingRule -> f GatingRule
gatingRule_gatingControls = (GatingRule -> [Text])
-> (GatingRule -> [Text] -> GatingRule)
-> Lens GatingRule GatingRule [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatingRule' {[Text]
gatingControls :: [Text]
$sel:gatingControls:GatingRule' :: GatingRule -> [Text]
gatingControls} -> [Text]
gatingControls) (\s :: GatingRule
s@GatingRule' {} [Text]
a -> GatingRule
s {$sel:gatingControls:GatingRule' :: [Text]
gatingControls = [Text]
a} :: GatingRule) (([Text] -> f [Text]) -> GatingRule -> f GatingRule)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GatingRule
-> f GatingRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
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 designates how many controls must be enabled to allow you
-- to change (set or unset) the target controls.
gatingRule_ruleConfig :: Lens.Lens' GatingRule RuleConfig
gatingRule_ruleConfig :: (RuleConfig -> f RuleConfig) -> GatingRule -> f GatingRule
gatingRule_ruleConfig = (GatingRule -> RuleConfig)
-> (GatingRule -> RuleConfig -> GatingRule)
-> Lens GatingRule GatingRule RuleConfig RuleConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatingRule' {RuleConfig
ruleConfig :: RuleConfig
$sel:ruleConfig:GatingRule' :: GatingRule -> RuleConfig
ruleConfig} -> RuleConfig
ruleConfig) (\s :: GatingRule
s@GatingRule' {} RuleConfig
a -> GatingRule
s {$sel:ruleConfig:GatingRule' :: RuleConfig
ruleConfig = RuleConfig
a} :: GatingRule)

-- | 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.
gatingRule_waitPeriodMs :: Lens.Lens' GatingRule Prelude.Int
gatingRule_waitPeriodMs :: (Int -> f Int) -> GatingRule -> f GatingRule
gatingRule_waitPeriodMs = (GatingRule -> Int)
-> (GatingRule -> Int -> GatingRule)
-> Lens GatingRule GatingRule Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatingRule' {Int
waitPeriodMs :: Int
$sel:waitPeriodMs:GatingRule' :: GatingRule -> Int
waitPeriodMs} -> Int
waitPeriodMs) (\s :: GatingRule
s@GatingRule' {} Int
a -> GatingRule
s {$sel:waitPeriodMs:GatingRule' :: Int
waitPeriodMs = Int
a} :: GatingRule)

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

instance Core.FromJSON GatingRule where
  parseJSON :: Value -> Parser GatingRule
parseJSON =
    String
-> (Object -> Parser GatingRule) -> Value -> Parser GatingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GatingRule"
      ( \Object
x ->
          Status
-> [Text]
-> Text
-> Text
-> [Text]
-> RuleConfig
-> Int
-> Text
-> GatingRule
GatingRule'
            (Status
 -> [Text]
 -> Text
 -> Text
 -> [Text]
 -> RuleConfig
 -> Int
 -> Text
 -> GatingRule)
-> Parser Status
-> Parser
     ([Text]
      -> Text
      -> Text
      -> [Text]
      -> RuleConfig
      -> Int
      -> Text
      -> GatingRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Status
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Status")
            Parser
  ([Text]
   -> Text
   -> Text
   -> [Text]
   -> RuleConfig
   -> Int
   -> Text
   -> GatingRule)
-> Parser [Text]
-> Parser
     (Text -> Text -> [Text] -> RuleConfig -> Int -> Text -> GatingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TargetControls" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Text -> Text -> [Text] -> RuleConfig -> Int -> Text -> GatingRule)
-> Parser Text
-> Parser
     (Text -> [Text] -> RuleConfig -> Int -> Text -> GatingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ControlPanelArn")
            Parser (Text -> [Text] -> RuleConfig -> Int -> Text -> GatingRule)
-> Parser Text
-> Parser ([Text] -> RuleConfig -> Int -> Text -> GatingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SafetyRuleArn")
            Parser ([Text] -> RuleConfig -> Int -> Text -> GatingRule)
-> Parser [Text]
-> Parser (RuleConfig -> Int -> Text -> GatingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"GatingControls" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (RuleConfig -> Int -> Text -> GatingRule)
-> Parser RuleConfig -> Parser (Int -> Text -> GatingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser RuleConfig
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RuleConfig")
            Parser (Int -> Text -> GatingRule)
-> Parser Int -> Parser (Text -> GatingRule)
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
"WaitPeriodMs")
            Parser (Text -> GatingRule) -> Parser Text -> Parser GatingRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
      )

instance Prelude.Hashable GatingRule

instance Prelude.NFData GatingRule