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

-- | A safety rule. A safety rule can be an assertion rule or a gating rule.
--
-- /See:/ 'newRule' smart constructor.
data Rule = Rule'
  { -- | 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 state 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.
    Rule -> Maybe AssertionRule
assertion :: Prelude.Maybe AssertionRule,
    -- | A gating rule verifies that a gating routing control or set of gating
    -- routing controls, evaluates as true, based on a rule configuration that
    -- you specify, which allows a set of routing control state changes to
    -- complete.
    --
    -- For example, if you specify one gating routing control and you set the
    -- Type in the rule configuration to OR, that indicates that you must set
    -- the gating routing control to On for the rule to evaluate as true; that
    -- is, for the gating control \"switch\" to be \"On\". When you do that,
    -- then you can update the routing control states for the target routing
    -- controls that you specify in the gating rule.
    Rule -> Maybe GatingRule
gating :: Prelude.Maybe GatingRule
  }
  deriving (Rule -> Rule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rule -> Rule -> Bool
$c/= :: Rule -> Rule -> Bool
== :: Rule -> Rule -> Bool
$c== :: Rule -> Rule -> Bool
Prelude.Eq, ReadPrec [Rule]
ReadPrec Rule
Int -> ReadS Rule
ReadS [Rule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Rule]
$creadListPrec :: ReadPrec [Rule]
readPrec :: ReadPrec Rule
$creadPrec :: ReadPrec Rule
readList :: ReadS [Rule]
$creadList :: ReadS [Rule]
readsPrec :: Int -> ReadS Rule
$creadsPrec :: Int -> ReadS Rule
Prelude.Read, Int -> Rule -> ShowS
[Rule] -> ShowS
Rule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rule] -> ShowS
$cshowList :: [Rule] -> ShowS
show :: Rule -> String
$cshow :: Rule -> String
showsPrec :: Int -> Rule -> ShowS
$cshowsPrec :: Int -> Rule -> ShowS
Prelude.Show, forall x. Rep Rule x -> Rule
forall x. Rule -> Rep Rule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rule x -> Rule
$cfrom :: forall x. Rule -> Rep Rule x
Prelude.Generic)

-- |
-- Create a value of 'Rule' 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:
--
-- 'assertion', 'rule_assertion' - 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 state 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.
--
-- 'gating', 'rule_gating' - A gating rule verifies that a gating routing control or set of gating
-- routing controls, evaluates as true, based on a rule configuration that
-- you specify, which allows a set of routing control state changes to
-- complete.
--
-- For example, if you specify one gating routing control and you set the
-- Type in the rule configuration to OR, that indicates that you must set
-- the gating routing control to On for the rule to evaluate as true; that
-- is, for the gating control \"switch\" to be \"On\". When you do that,
-- then you can update the routing control states for the target routing
-- controls that you specify in the gating rule.
newRule ::
  Rule
newRule :: Rule
newRule =
  Rule'
    { $sel:assertion:Rule' :: Maybe AssertionRule
assertion = forall a. Maybe a
Prelude.Nothing,
      $sel:gating:Rule' :: Maybe GatingRule
gating = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 state 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.
rule_assertion :: Lens.Lens' Rule (Prelude.Maybe AssertionRule)
rule_assertion :: Lens' Rule (Maybe AssertionRule)
rule_assertion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe AssertionRule
assertion :: Maybe AssertionRule
$sel:assertion:Rule' :: Rule -> Maybe AssertionRule
assertion} -> Maybe AssertionRule
assertion) (\s :: Rule
s@Rule' {} Maybe AssertionRule
a -> Rule
s {$sel:assertion:Rule' :: Maybe AssertionRule
assertion = Maybe AssertionRule
a} :: Rule)

-- | A gating rule verifies that a gating routing control or set of gating
-- routing controls, evaluates as true, based on a rule configuration that
-- you specify, which allows a set of routing control state changes to
-- complete.
--
-- For example, if you specify one gating routing control and you set the
-- Type in the rule configuration to OR, that indicates that you must set
-- the gating routing control to On for the rule to evaluate as true; that
-- is, for the gating control \"switch\" to be \"On\". When you do that,
-- then you can update the routing control states for the target routing
-- controls that you specify in the gating rule.
rule_gating :: Lens.Lens' Rule (Prelude.Maybe GatingRule)
rule_gating :: Lens' Rule (Maybe GatingRule)
rule_gating = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe GatingRule
gating :: Maybe GatingRule
$sel:gating:Rule' :: Rule -> Maybe GatingRule
gating} -> Maybe GatingRule
gating) (\s :: Rule
s@Rule' {} Maybe GatingRule
a -> Rule
s {$sel:gating:Rule' :: Maybe GatingRule
gating = Maybe GatingRule
a} :: Rule)

instance Data.FromJSON Rule where
  parseJSON :: Value -> Parser Rule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Rule"
      ( \Object
x ->
          Maybe AssertionRule -> Maybe GatingRule -> Rule
Rule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ASSERTION")
            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
"GATING")
      )

instance Prelude.Hashable Rule where
  hashWithSalt :: Int -> Rule -> Int
hashWithSalt Int
_salt Rule' {Maybe GatingRule
Maybe AssertionRule
gating :: Maybe GatingRule
assertion :: Maybe AssertionRule
$sel:gating:Rule' :: Rule -> Maybe GatingRule
$sel:assertion:Rule' :: Rule -> Maybe AssertionRule
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AssertionRule
assertion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe GatingRule
gating

instance Prelude.NFData Rule where
  rnf :: Rule -> ()
rnf Rule' {Maybe GatingRule
Maybe AssertionRule
gating :: Maybe GatingRule
assertion :: Maybe AssertionRule
$sel:gating:Rule' :: Rule -> Maybe GatingRule
$sel:assertion:Rule' :: Rule -> Maybe AssertionRule
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AssertionRule
assertion
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe GatingRule
gating