{-# 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.AssertionRule
-- 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.AssertionRule 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

-- | An assertion rule enforces that, when a routing control state is
-- changed, the criteria set by the rule configuration is met. Otherwise,
-- the change to the routing control is not accepted.
--
-- /See:/ 'newAssertionRule' smart constructor.
data AssertionRule = AssertionRule'
  { -- | The deployment status of an assertion rule. Status can be one of the
    -- following: PENDING, DEPLOYED, PENDING_DELETION.
    AssertionRule -> Status
status :: Status,
    -- | The Amazon Resource Name (ARN) of the control panel.
    AssertionRule -> Text
controlPanelArn :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the assertion rule.
    AssertionRule -> Text
safetyRuleArn :: Prelude.Text,
    -- | The routing controls that are part of transactions that are evaluated to
    -- determine if a request to change a routing control state is allowed. For
    -- example, you might include three routing controls, one for each of three
    -- Amazon Web Services Regions.
    AssertionRule -> [Text]
assertedControls :: [Prelude.Text],
    -- | The criteria that you set for specific assertion controls (routing
    -- controls) that designate how many controls must be enabled as the result
    -- of a transaction. For example, if you have three assertion controls, you
    -- might specify atleast 2 for your rule configuration. This means that at
    -- least two assertion controls must be enabled, so that at least two
    -- Amazon Web Services Regions are enabled.
    AssertionRule -> 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.
    AssertionRule -> Int
waitPeriodMs :: Prelude.Int,
    -- | Name of the assertion rule. You can use any non-white space character in
    -- the name.
    AssertionRule -> Text
name :: Prelude.Text
  }
  deriving (AssertionRule -> AssertionRule -> Bool
(AssertionRule -> AssertionRule -> Bool)
-> (AssertionRule -> AssertionRule -> Bool) -> Eq AssertionRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssertionRule -> AssertionRule -> Bool
$c/= :: AssertionRule -> AssertionRule -> Bool
== :: AssertionRule -> AssertionRule -> Bool
$c== :: AssertionRule -> AssertionRule -> Bool
Prelude.Eq, ReadPrec [AssertionRule]
ReadPrec AssertionRule
Int -> ReadS AssertionRule
ReadS [AssertionRule]
(Int -> ReadS AssertionRule)
-> ReadS [AssertionRule]
-> ReadPrec AssertionRule
-> ReadPrec [AssertionRule]
-> Read AssertionRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssertionRule]
$creadListPrec :: ReadPrec [AssertionRule]
readPrec :: ReadPrec AssertionRule
$creadPrec :: ReadPrec AssertionRule
readList :: ReadS [AssertionRule]
$creadList :: ReadS [AssertionRule]
readsPrec :: Int -> ReadS AssertionRule
$creadsPrec :: Int -> ReadS AssertionRule
Prelude.Read, Int -> AssertionRule -> ShowS
[AssertionRule] -> ShowS
AssertionRule -> String
(Int -> AssertionRule -> ShowS)
-> (AssertionRule -> String)
-> ([AssertionRule] -> ShowS)
-> Show AssertionRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssertionRule] -> ShowS
$cshowList :: [AssertionRule] -> ShowS
show :: AssertionRule -> String
$cshow :: AssertionRule -> String
showsPrec :: Int -> AssertionRule -> ShowS
$cshowsPrec :: Int -> AssertionRule -> ShowS
Prelude.Show, (forall x. AssertionRule -> Rep AssertionRule x)
-> (forall x. Rep AssertionRule x -> AssertionRule)
-> Generic AssertionRule
forall x. Rep AssertionRule x -> AssertionRule
forall x. AssertionRule -> Rep AssertionRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssertionRule x -> AssertionRule
$cfrom :: forall x. AssertionRule -> Rep AssertionRule x
Prelude.Generic)

-- |
-- Create a value of 'AssertionRule' 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', 'assertionRule_status' - The deployment status of an assertion rule. Status can be one of the
-- following: PENDING, DEPLOYED, PENDING_DELETION.
--
-- 'controlPanelArn', 'assertionRule_controlPanelArn' - The Amazon Resource Name (ARN) of the control panel.
--
-- 'safetyRuleArn', 'assertionRule_safetyRuleArn' - The Amazon Resource Name (ARN) of the assertion rule.
--
-- 'assertedControls', 'assertionRule_assertedControls' - The routing controls that are part of transactions that are evaluated to
-- determine if a request to change a routing control state is allowed. For
-- example, you might include three routing controls, one for each of three
-- Amazon Web Services Regions.
--
-- 'ruleConfig', 'assertionRule_ruleConfig' - The criteria that you set for specific assertion controls (routing
-- controls) that designate how many controls must be enabled as the result
-- of a transaction. For example, if you have three assertion controls, you
-- might specify atleast 2 for your rule configuration. This means that at
-- least two assertion controls must be enabled, so that at least two
-- Amazon Web Services Regions are enabled.
--
-- 'waitPeriodMs', 'assertionRule_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', 'assertionRule_name' - Name of the assertion rule. You can use any non-white space character in
-- the name.
newAssertionRule ::
  -- | 'status'
  Status ->
  -- | 'controlPanelArn'
  Prelude.Text ->
  -- | 'safetyRuleArn'
  Prelude.Text ->
  -- | 'ruleConfig'
  RuleConfig ->
  -- | 'waitPeriodMs'
  Prelude.Int ->
  -- | 'name'
  Prelude.Text ->
  AssertionRule
newAssertionRule :: Status
-> Text -> Text -> RuleConfig -> Int -> Text -> AssertionRule
newAssertionRule
  Status
pStatus_
  Text
pControlPanelArn_
  Text
pSafetyRuleArn_
  RuleConfig
pRuleConfig_
  Int
pWaitPeriodMs_
  Text
pName_ =
    AssertionRule' :: Status
-> Text
-> Text
-> [Text]
-> RuleConfig
-> Int
-> Text
-> AssertionRule
AssertionRule'
      { $sel:status:AssertionRule' :: Status
status = Status
pStatus_,
        $sel:controlPanelArn:AssertionRule' :: Text
controlPanelArn = Text
pControlPanelArn_,
        $sel:safetyRuleArn:AssertionRule' :: Text
safetyRuleArn = Text
pSafetyRuleArn_,
        $sel:assertedControls:AssertionRule' :: [Text]
assertedControls = [Text]
forall a. Monoid a => a
Prelude.mempty,
        $sel:ruleConfig:AssertionRule' :: RuleConfig
ruleConfig = RuleConfig
pRuleConfig_,
        $sel:waitPeriodMs:AssertionRule' :: Int
waitPeriodMs = Int
pWaitPeriodMs_,
        $sel:name:AssertionRule' :: Text
name = Text
pName_
      }

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

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

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

-- | The routing controls that are part of transactions that are evaluated to
-- determine if a request to change a routing control state is allowed. For
-- example, you might include three routing controls, one for each of three
-- Amazon Web Services Regions.
assertionRule_assertedControls :: Lens.Lens' AssertionRule [Prelude.Text]
assertionRule_assertedControls :: ([Text] -> f [Text]) -> AssertionRule -> f AssertionRule
assertionRule_assertedControls = (AssertionRule -> [Text])
-> (AssertionRule -> [Text] -> AssertionRule)
-> Lens AssertionRule AssertionRule [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssertionRule' {[Text]
assertedControls :: [Text]
$sel:assertedControls:AssertionRule' :: AssertionRule -> [Text]
assertedControls} -> [Text]
assertedControls) (\s :: AssertionRule
s@AssertionRule' {} [Text]
a -> AssertionRule
s {$sel:assertedControls:AssertionRule' :: [Text]
assertedControls = [Text]
a} :: AssertionRule) (([Text] -> f [Text]) -> AssertionRule -> f AssertionRule)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AssertionRule
-> f AssertionRule
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 assertion controls (routing
-- controls) that designate how many controls must be enabled as the result
-- of a transaction. For example, if you have three assertion controls, you
-- might specify atleast 2 for your rule configuration. This means that at
-- least two assertion controls must be enabled, so that at least two
-- Amazon Web Services Regions are enabled.
assertionRule_ruleConfig :: Lens.Lens' AssertionRule RuleConfig
assertionRule_ruleConfig :: (RuleConfig -> f RuleConfig) -> AssertionRule -> f AssertionRule
assertionRule_ruleConfig = (AssertionRule -> RuleConfig)
-> (AssertionRule -> RuleConfig -> AssertionRule)
-> Lens AssertionRule AssertionRule RuleConfig RuleConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssertionRule' {RuleConfig
ruleConfig :: RuleConfig
$sel:ruleConfig:AssertionRule' :: AssertionRule -> RuleConfig
ruleConfig} -> RuleConfig
ruleConfig) (\s :: AssertionRule
s@AssertionRule' {} RuleConfig
a -> AssertionRule
s {$sel:ruleConfig:AssertionRule' :: RuleConfig
ruleConfig = RuleConfig
a} :: AssertionRule)

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

-- | Name of the assertion rule. You can use any non-white space character in
-- the name.
assertionRule_name :: Lens.Lens' AssertionRule Prelude.Text
assertionRule_name :: (Text -> f Text) -> AssertionRule -> f AssertionRule
assertionRule_name = (AssertionRule -> Text)
-> (AssertionRule -> Text -> AssertionRule)
-> Lens AssertionRule AssertionRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssertionRule' {Text
name :: Text
$sel:name:AssertionRule' :: AssertionRule -> Text
name} -> Text
name) (\s :: AssertionRule
s@AssertionRule' {} Text
a -> AssertionRule
s {$sel:name:AssertionRule' :: Text
name = Text
a} :: AssertionRule)

instance Core.FromJSON AssertionRule where
  parseJSON :: Value -> Parser AssertionRule
parseJSON =
    String
-> (Object -> Parser AssertionRule)
-> Value
-> Parser AssertionRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AssertionRule"
      ( \Object
x ->
          Status
-> Text
-> Text
-> [Text]
-> RuleConfig
-> Int
-> Text
-> AssertionRule
AssertionRule'
            (Status
 -> Text
 -> Text
 -> [Text]
 -> RuleConfig
 -> Int
 -> Text
 -> AssertionRule)
-> Parser Status
-> Parser
     (Text
      -> Text -> [Text] -> RuleConfig -> Int -> Text -> AssertionRule)
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] -> RuleConfig -> Int -> Text -> AssertionRule)
-> Parser Text
-> Parser
     (Text -> [Text] -> RuleConfig -> Int -> Text -> AssertionRule)
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 -> AssertionRule)
-> Parser Text
-> Parser ([Text] -> RuleConfig -> Int -> Text -> AssertionRule)
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 -> AssertionRule)
-> Parser [Text]
-> Parser (RuleConfig -> Int -> Text -> AssertionRule)
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
"AssertedControls"
                            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 -> AssertionRule)
-> Parser RuleConfig -> Parser (Int -> Text -> AssertionRule)
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 -> AssertionRule)
-> Parser Int -> Parser (Text -> AssertionRule)
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 -> AssertionRule)
-> Parser Text -> Parser AssertionRule
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 AssertionRule

instance Prelude.NFData AssertionRule