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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | 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.
    Rule -> Maybe GatingRule
gating :: Prelude.Maybe GatingRule,
    -- | 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.
    Rule -> Maybe AssertionRule
assertion :: Prelude.Maybe AssertionRule
  }
  deriving (Rule -> Rule -> Bool
(Rule -> Rule -> Bool) -> (Rule -> Rule -> Bool) -> Eq Rule
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]
(Int -> ReadS Rule)
-> ReadS [Rule] -> ReadPrec Rule -> ReadPrec [Rule] -> Read 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
(Int -> Rule -> ShowS)
-> (Rule -> String) -> ([Rule] -> ShowS) -> Show Rule
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. Rule -> Rep Rule x)
-> (forall x. Rep Rule x -> Rule) -> Generic Rule
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:
--
-- 'gating', 'rule_gating' - 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.
--
-- '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 is not accepted.
newRule ::
  Rule
newRule :: Rule
newRule =
  Rule' :: Maybe GatingRule -> Maybe AssertionRule -> Rule
Rule'
    { $sel:gating:Rule' :: Maybe GatingRule
gating = Maybe GatingRule
forall a. Maybe a
Prelude.Nothing,
      $sel:assertion:Rule' :: Maybe AssertionRule
assertion = Maybe AssertionRule
forall a. Maybe a
Prelude.Nothing
    }

-- | 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.
rule_gating :: Lens.Lens' Rule (Prelude.Maybe GatingRule)
rule_gating :: (Maybe GatingRule -> f (Maybe GatingRule)) -> Rule -> f Rule
rule_gating = (Rule -> Maybe GatingRule)
-> (Rule -> Maybe GatingRule -> Rule)
-> Lens Rule Rule (Maybe GatingRule) (Maybe GatingRule)
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)

-- | 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.
rule_assertion :: Lens.Lens' Rule (Prelude.Maybe AssertionRule)
rule_assertion :: (Maybe AssertionRule -> f (Maybe AssertionRule)) -> Rule -> f Rule
rule_assertion = (Rule -> Maybe AssertionRule)
-> (Rule -> Maybe AssertionRule -> Rule)
-> Lens Rule Rule (Maybe AssertionRule) (Maybe AssertionRule)
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)

instance Core.FromJSON Rule where
  parseJSON :: Value -> Parser Rule
parseJSON =
    String -> (Object -> Parser Rule) -> Value -> Parser Rule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Rule"
      ( \Object
x ->
          Maybe GatingRule -> Maybe AssertionRule -> Rule
Rule'
            (Maybe GatingRule -> Maybe AssertionRule -> Rule)
-> Parser (Maybe GatingRule)
-> Parser (Maybe AssertionRule -> Rule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe GatingRule)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"GATING")
            Parser (Maybe AssertionRule -> Rule)
-> Parser (Maybe AssertionRule) -> Parser Rule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AssertionRule)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ASSERTION")
      )

instance Prelude.Hashable Rule

instance Prelude.NFData Rule