{-# 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.NetworkFirewall.Types.RuleOption
-- 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.NetworkFirewall.Types.RuleOption 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

-- | Additional settings for a stateful rule. This is part of the
-- StatefulRule configuration.
--
-- /See:/ 'newRuleOption' smart constructor.
data RuleOption = RuleOption'
  { RuleOption -> Maybe [Text]
settings :: Prelude.Maybe [Prelude.Text],
    RuleOption -> Text
keyword :: Prelude.Text
  }
  deriving (RuleOption -> RuleOption -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuleOption -> RuleOption -> Bool
$c/= :: RuleOption -> RuleOption -> Bool
== :: RuleOption -> RuleOption -> Bool
$c== :: RuleOption -> RuleOption -> Bool
Prelude.Eq, ReadPrec [RuleOption]
ReadPrec RuleOption
Int -> ReadS RuleOption
ReadS [RuleOption]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuleOption]
$creadListPrec :: ReadPrec [RuleOption]
readPrec :: ReadPrec RuleOption
$creadPrec :: ReadPrec RuleOption
readList :: ReadS [RuleOption]
$creadList :: ReadS [RuleOption]
readsPrec :: Int -> ReadS RuleOption
$creadsPrec :: Int -> ReadS RuleOption
Prelude.Read, Int -> RuleOption -> ShowS
[RuleOption] -> ShowS
RuleOption -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuleOption] -> ShowS
$cshowList :: [RuleOption] -> ShowS
show :: RuleOption -> String
$cshow :: RuleOption -> String
showsPrec :: Int -> RuleOption -> ShowS
$cshowsPrec :: Int -> RuleOption -> ShowS
Prelude.Show, forall x. Rep RuleOption x -> RuleOption
forall x. RuleOption -> Rep RuleOption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuleOption x -> RuleOption
$cfrom :: forall x. RuleOption -> Rep RuleOption x
Prelude.Generic)

-- |
-- Create a value of 'RuleOption' 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:
--
-- 'settings', 'ruleOption_settings' -
--
-- 'keyword', 'ruleOption_keyword' -
newRuleOption ::
  -- | 'keyword'
  Prelude.Text ->
  RuleOption
newRuleOption :: Text -> RuleOption
newRuleOption Text
pKeyword_ =
  RuleOption'
    { $sel:settings:RuleOption' :: Maybe [Text]
settings = forall a. Maybe a
Prelude.Nothing,
      $sel:keyword:RuleOption' :: Text
keyword = Text
pKeyword_
    }

ruleOption_settings :: Lens.Lens' RuleOption (Prelude.Maybe [Prelude.Text])
ruleOption_settings :: Lens' RuleOption (Maybe [Text])
ruleOption_settings = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleOption' {Maybe [Text]
settings :: Maybe [Text]
$sel:settings:RuleOption' :: RuleOption -> Maybe [Text]
settings} -> Maybe [Text]
settings) (\s :: RuleOption
s@RuleOption' {} Maybe [Text]
a -> RuleOption
s {$sel:settings:RuleOption' :: Maybe [Text]
settings = Maybe [Text]
a} :: RuleOption) 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

ruleOption_keyword :: Lens.Lens' RuleOption Prelude.Text
ruleOption_keyword :: Lens' RuleOption Text
ruleOption_keyword = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleOption' {Text
keyword :: Text
$sel:keyword:RuleOption' :: RuleOption -> Text
keyword} -> Text
keyword) (\s :: RuleOption
s@RuleOption' {} Text
a -> RuleOption
s {$sel:keyword:RuleOption' :: Text
keyword = Text
a} :: RuleOption)

instance Data.FromJSON RuleOption where
  parseJSON :: Value -> Parser RuleOption
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RuleOption"
      ( \Object
x ->
          Maybe [Text] -> Text -> RuleOption
RuleOption'
            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
"Settings" 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
"Keyword")
      )

instance Prelude.Hashable RuleOption where
  hashWithSalt :: Int -> RuleOption -> Int
hashWithSalt Int
_salt RuleOption' {Maybe [Text]
Text
keyword :: Text
settings :: Maybe [Text]
$sel:keyword:RuleOption' :: RuleOption -> Text
$sel:settings:RuleOption' :: RuleOption -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
settings
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
keyword

instance Prelude.NFData RuleOption where
  rnf :: RuleOption -> ()
rnf RuleOption' {Maybe [Text]
Text
keyword :: Text
settings :: Maybe [Text]
$sel:keyword:RuleOption' :: RuleOption -> Text
$sel:settings:RuleOption' :: RuleOption -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
settings
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
keyword

instance Data.ToJSON RuleOption where
  toJSON :: RuleOption -> Value
toJSON RuleOption' {Maybe [Text]
Text
keyword :: Text
settings :: Maybe [Text]
$sel:keyword:RuleOption' :: RuleOption -> Text
$sel:settings:RuleOption' :: RuleOption -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Settings" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
settings,
            forall a. a -> Maybe a
Prelude.Just (Key
"Keyword" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
keyword)
          ]
      )