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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ELBV2.Types.Action
import Amazonka.ELBV2.Types.RuleCondition
import qualified Amazonka.Prelude as Prelude

-- | Information about a rule.
--
-- /See:/ 'newRule' smart constructor.
data Rule = Rule'
  { -- | The actions. Each rule must include exactly one of the following types
    -- of actions: @forward@, @redirect@, or @fixed-response@, and it must be
    -- the last action to be performed.
    Rule -> Maybe [Action]
actions :: Prelude.Maybe [Action],
    -- | The conditions. Each rule can include zero or one of the following
    -- conditions: @http-request-method@, @host-header@, @path-pattern@, and
    -- @source-ip@, and zero or more of the following conditions: @http-header@
    -- and @query-string@.
    Rule -> Maybe [RuleCondition]
conditions :: Prelude.Maybe [RuleCondition],
    -- | Indicates whether this is the default rule.
    Rule -> Maybe Bool
isDefault :: Prelude.Maybe Prelude.Bool,
    -- | The priority.
    Rule -> Maybe Text
priority :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the rule.
    Rule -> Maybe Text
ruleArn :: Prelude.Maybe Prelude.Text
  }
  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:
--
-- 'actions', 'rule_actions' - The actions. Each rule must include exactly one of the following types
-- of actions: @forward@, @redirect@, or @fixed-response@, and it must be
-- the last action to be performed.
--
-- 'conditions', 'rule_conditions' - The conditions. Each rule can include zero or one of the following
-- conditions: @http-request-method@, @host-header@, @path-pattern@, and
-- @source-ip@, and zero or more of the following conditions: @http-header@
-- and @query-string@.
--
-- 'isDefault', 'rule_isDefault' - Indicates whether this is the default rule.
--
-- 'priority', 'rule_priority' - The priority.
--
-- 'ruleArn', 'rule_ruleArn' - The Amazon Resource Name (ARN) of the rule.
newRule ::
  Rule
newRule :: Rule
newRule =
  Rule'
    { $sel:actions:Rule' :: Maybe [Action]
actions = forall a. Maybe a
Prelude.Nothing,
      $sel:conditions:Rule' :: Maybe [RuleCondition]
conditions = forall a. Maybe a
Prelude.Nothing,
      $sel:isDefault:Rule' :: Maybe Bool
isDefault = forall a. Maybe a
Prelude.Nothing,
      $sel:priority:Rule' :: Maybe Text
priority = forall a. Maybe a
Prelude.Nothing,
      $sel:ruleArn:Rule' :: Maybe Text
ruleArn = forall a. Maybe a
Prelude.Nothing
    }

-- | The actions. Each rule must include exactly one of the following types
-- of actions: @forward@, @redirect@, or @fixed-response@, and it must be
-- the last action to be performed.
rule_actions :: Lens.Lens' Rule (Prelude.Maybe [Action])
rule_actions :: Lens' Rule (Maybe [Action])
rule_actions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe [Action]
actions :: Maybe [Action]
$sel:actions:Rule' :: Rule -> Maybe [Action]
actions} -> Maybe [Action]
actions) (\s :: Rule
s@Rule' {} Maybe [Action]
a -> Rule
s {$sel:actions:Rule' :: Maybe [Action]
actions = Maybe [Action]
a} :: Rule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The conditions. Each rule can include zero or one of the following
-- conditions: @http-request-method@, @host-header@, @path-pattern@, and
-- @source-ip@, and zero or more of the following conditions: @http-header@
-- and @query-string@.
rule_conditions :: Lens.Lens' Rule (Prelude.Maybe [RuleCondition])
rule_conditions :: Lens' Rule (Maybe [RuleCondition])
rule_conditions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe [RuleCondition]
conditions :: Maybe [RuleCondition]
$sel:conditions:Rule' :: Rule -> Maybe [RuleCondition]
conditions} -> Maybe [RuleCondition]
conditions) (\s :: Rule
s@Rule' {} Maybe [RuleCondition]
a -> Rule
s {$sel:conditions:Rule' :: Maybe [RuleCondition]
conditions = Maybe [RuleCondition]
a} :: Rule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Indicates whether this is the default rule.
rule_isDefault :: Lens.Lens' Rule (Prelude.Maybe Prelude.Bool)
rule_isDefault :: Lens' Rule (Maybe Bool)
rule_isDefault = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Bool
isDefault :: Maybe Bool
$sel:isDefault:Rule' :: Rule -> Maybe Bool
isDefault} -> Maybe Bool
isDefault) (\s :: Rule
s@Rule' {} Maybe Bool
a -> Rule
s {$sel:isDefault:Rule' :: Maybe Bool
isDefault = Maybe Bool
a} :: Rule)

-- | The priority.
rule_priority :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_priority :: Lens' Rule (Maybe Text)
rule_priority = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
priority :: Maybe Text
$sel:priority:Rule' :: Rule -> Maybe Text
priority} -> Maybe Text
priority) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:priority:Rule' :: Maybe Text
priority = Maybe Text
a} :: Rule)

-- | The Amazon Resource Name (ARN) of the rule.
rule_ruleArn :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_ruleArn :: Lens' Rule (Maybe Text)
rule_ruleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
ruleArn :: Maybe Text
$sel:ruleArn:Rule' :: Rule -> Maybe Text
ruleArn} -> Maybe Text
ruleArn) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:ruleArn:Rule' :: Maybe Text
ruleArn = Maybe Text
a} :: Rule)

instance Data.FromXML Rule where
  parseXML :: [Node] -> Either String Rule
parseXML [Node]
x =
    Maybe [Action]
-> Maybe [RuleCondition]
-> Maybe Bool
-> Maybe Text
-> Maybe Text
-> Rule
Rule'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Actions"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Conditions"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"IsDefault")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Priority")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"RuleArn")

instance Prelude.Hashable Rule where
  hashWithSalt :: Int -> Rule -> Int
hashWithSalt Int
_salt Rule' {Maybe Bool
Maybe [RuleCondition]
Maybe [Action]
Maybe Text
ruleArn :: Maybe Text
priority :: Maybe Text
isDefault :: Maybe Bool
conditions :: Maybe [RuleCondition]
actions :: Maybe [Action]
$sel:ruleArn:Rule' :: Rule -> Maybe Text
$sel:priority:Rule' :: Rule -> Maybe Text
$sel:isDefault:Rule' :: Rule -> Maybe Bool
$sel:conditions:Rule' :: Rule -> Maybe [RuleCondition]
$sel:actions:Rule' :: Rule -> Maybe [Action]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Action]
actions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [RuleCondition]
conditions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
isDefault
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
priority
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
ruleArn

instance Prelude.NFData Rule where
  rnf :: Rule -> ()
rnf Rule' {Maybe Bool
Maybe [RuleCondition]
Maybe [Action]
Maybe Text
ruleArn :: Maybe Text
priority :: Maybe Text
isDefault :: Maybe Bool
conditions :: Maybe [RuleCondition]
actions :: Maybe [Action]
$sel:ruleArn:Rule' :: Rule -> Maybe Text
$sel:priority:Rule' :: Rule -> Maybe Text
$sel:isDefault:Rule' :: Rule -> Maybe Bool
$sel:conditions:Rule' :: Rule -> Maybe [RuleCondition]
$sel:actions:Rule' :: Rule -> Maybe [Action]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Action]
actions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [RuleCondition]
conditions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
isDefault
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
priority
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
ruleArn