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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(RuleOption -> RuleOption -> Bool)
-> (RuleOption -> RuleOption -> Bool) -> Eq RuleOption
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]
(Int -> ReadS RuleOption)
-> ReadS [RuleOption]
-> ReadPrec RuleOption
-> ReadPrec [RuleOption]
-> Read 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
(Int -> RuleOption -> ShowS)
-> (RuleOption -> String)
-> ([RuleOption] -> ShowS)
-> Show RuleOption
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. RuleOption -> Rep RuleOption x)
-> (forall x. Rep RuleOption x -> RuleOption) -> Generic RuleOption
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' :: Maybe [Text] -> Text -> RuleOption
RuleOption'
    { $sel:settings:RuleOption' :: Maybe [Text]
settings = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:keyword:RuleOption' :: Text
keyword = Text
pKeyword_
    }

-- |
ruleOption_settings :: Lens.Lens' RuleOption (Prelude.Maybe [Prelude.Text])
ruleOption_settings :: (Maybe [Text] -> f (Maybe [Text])) -> RuleOption -> f RuleOption
ruleOption_settings = (RuleOption -> Maybe [Text])
-> (RuleOption -> Maybe [Text] -> RuleOption)
-> Lens RuleOption RuleOption (Maybe [Text]) (Maybe [Text])
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) ((Maybe [Text] -> f (Maybe [Text])) -> RuleOption -> f RuleOption)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> RuleOption
-> f RuleOption
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
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 :: (Text -> f Text) -> RuleOption -> f RuleOption
ruleOption_keyword = (RuleOption -> Text)
-> (RuleOption -> Text -> RuleOption)
-> Lens RuleOption RuleOption Text Text
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 Core.FromJSON RuleOption where
  parseJSON :: Value -> Parser RuleOption
parseJSON =
    String
-> (Object -> Parser RuleOption) -> Value -> Parser RuleOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RuleOption"
      ( \Object
x ->
          Maybe [Text] -> Text -> RuleOption
RuleOption'
            (Maybe [Text] -> Text -> RuleOption)
-> Parser (Maybe [Text]) -> Parser (Text -> RuleOption)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Settings" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> RuleOption) -> Parser Text -> Parser RuleOption
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Keyword")
      )

instance Prelude.Hashable RuleOption

instance Prelude.NFData RuleOption

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Settings" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
settings,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Keyword" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
keyword)
          ]
      )