{-# 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-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.AssertionRule 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
import Amazonka.Route53RecoveryControlConfig.Types.Status

-- | An assertion rule enforces that, when you change a routing control
-- state, that the criteria that you set in the rule configuration is met.
-- Otherwise, the change to the routing control is not accepted. For
-- example, the criteria might be that at least one routing control state
-- is On after the transaction so that traffic continues to flow to at
-- least one cell for the application. This ensures that you avoid a
-- fail-open scenario.
--
-- /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 routing controls
    -- (AssertedControls) that designate how many routing control states must
    -- be ON as the result of a transaction. For example, if you have three
    -- assertion routing controls, you might specify ATLEAST 2 for your rule
    -- configuration. This means that at least two assertion routing control
    -- states must be ON, so that at least two Amazon Web Services Regions have
    -- traffic flowing to them.
    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
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]
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
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. 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 routing controls
-- (AssertedControls) that designate how many routing control states must
-- be ON as the result of a transaction. For example, if you have three
-- assertion routing controls, you might specify ATLEAST 2 for your rule
-- configuration. This means that at least two assertion routing control
-- states must be ON, so that at least two Amazon Web Services Regions have
-- traffic flowing to them.
--
-- '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'
      { $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 = 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 :: Lens' AssertionRule Status
assertionRule_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 :: Lens' AssertionRule Text
assertionRule_controlPanelArn = 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 :: Lens' AssertionRule Text
assertionRule_safetyRuleArn = 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 :: Lens' AssertionRule [Text]
assertionRule_assertedControls = 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) 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 assertion routing controls
-- (AssertedControls) that designate how many routing control states must
-- be ON as the result of a transaction. For example, if you have three
-- assertion routing controls, you might specify ATLEAST 2 for your rule
-- configuration. This means that at least two assertion routing control
-- states must be ON, so that at least two Amazon Web Services Regions have
-- traffic flowing to them.
assertionRule_ruleConfig :: Lens.Lens' AssertionRule RuleConfig
assertionRule_ruleConfig :: Lens' AssertionRule RuleConfig
assertionRule_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 :: Lens' AssertionRule Int
assertionRule_waitPeriodMs = 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 :: Lens' AssertionRule Text
assertionRule_name = 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 Data.FromJSON AssertionRule where
  parseJSON :: Value -> Parser AssertionRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AssertionRule"
      ( \Object
x ->
          Status
-> Text
-> Text
-> [Text]
-> RuleConfig
-> Int
-> Text
-> AssertionRule
AssertionRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Status")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ControlPanelArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"SafetyRuleArn")
            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
"AssertedControls"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"RuleConfig")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"WaitPeriodMs")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
      )

instance Prelude.Hashable AssertionRule where
  hashWithSalt :: Int -> AssertionRule -> Int
hashWithSalt Int
_salt AssertionRule' {Int
[Text]
Text
RuleConfig
Status
name :: Text
waitPeriodMs :: Int
ruleConfig :: RuleConfig
assertedControls :: [Text]
safetyRuleArn :: Text
controlPanelArn :: Text
status :: Status
$sel:name:AssertionRule' :: AssertionRule -> Text
$sel:waitPeriodMs:AssertionRule' :: AssertionRule -> Int
$sel:ruleConfig:AssertionRule' :: AssertionRule -> RuleConfig
$sel:assertedControls:AssertionRule' :: AssertionRule -> [Text]
$sel:safetyRuleArn:AssertionRule' :: AssertionRule -> Text
$sel:controlPanelArn:AssertionRule' :: AssertionRule -> Text
$sel:status:AssertionRule' :: AssertionRule -> Status
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Status
status
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
controlPanelArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
safetyRuleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
assertedControls
      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 AssertionRule where
  rnf :: AssertionRule -> ()
rnf AssertionRule' {Int
[Text]
Text
RuleConfig
Status
name :: Text
waitPeriodMs :: Int
ruleConfig :: RuleConfig
assertedControls :: [Text]
safetyRuleArn :: Text
controlPanelArn :: Text
status :: Status
$sel:name:AssertionRule' :: AssertionRule -> Text
$sel:waitPeriodMs:AssertionRule' :: AssertionRule -> Int
$sel:ruleConfig:AssertionRule' :: AssertionRule -> RuleConfig
$sel:assertedControls:AssertionRule' :: AssertionRule -> [Text]
$sel:safetyRuleArn:AssertionRule' :: AssertionRule -> Text
$sel:controlPanelArn:AssertionRule' :: AssertionRule -> Text
$sel:status:AssertionRule' :: AssertionRule -> Status
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Status
status
      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
safetyRuleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
assertedControls
      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