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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkFirewall.Types.TCPFlag
import qualified Amazonka.Prelude as Prelude

-- | TCP flags and masks to inspect packets for, used in stateless rules
-- MatchAttributes settings.
--
-- /See:/ 'newTCPFlagField' smart constructor.
data TCPFlagField = TCPFlagField'
  { -- | The set of flags to consider in the inspection. To inspect all flags in
    -- the valid values list, leave this with no setting.
    TCPFlagField -> Maybe [TCPFlag]
masks :: Prelude.Maybe [TCPFlag],
    -- | Used in conjunction with the @Masks@ setting to define the flags that
    -- must be set and flags that must not be set in order for the packet to
    -- match. This setting can only specify values that are also specified in
    -- the @Masks@ setting.
    --
    -- For the flags that are specified in the masks setting, the following
    -- must be true for the packet to match:
    --
    -- -   The ones that are set in this flags setting must be set in the
    --     packet.
    --
    -- -   The ones that are not set in this flags setting must also not be set
    --     in the packet.
    TCPFlagField -> [TCPFlag]
flags :: [TCPFlag]
  }
  deriving (TCPFlagField -> TCPFlagField -> Bool
(TCPFlagField -> TCPFlagField -> Bool)
-> (TCPFlagField -> TCPFlagField -> Bool) -> Eq TCPFlagField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TCPFlagField -> TCPFlagField -> Bool
$c/= :: TCPFlagField -> TCPFlagField -> Bool
== :: TCPFlagField -> TCPFlagField -> Bool
$c== :: TCPFlagField -> TCPFlagField -> Bool
Prelude.Eq, ReadPrec [TCPFlagField]
ReadPrec TCPFlagField
Int -> ReadS TCPFlagField
ReadS [TCPFlagField]
(Int -> ReadS TCPFlagField)
-> ReadS [TCPFlagField]
-> ReadPrec TCPFlagField
-> ReadPrec [TCPFlagField]
-> Read TCPFlagField
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TCPFlagField]
$creadListPrec :: ReadPrec [TCPFlagField]
readPrec :: ReadPrec TCPFlagField
$creadPrec :: ReadPrec TCPFlagField
readList :: ReadS [TCPFlagField]
$creadList :: ReadS [TCPFlagField]
readsPrec :: Int -> ReadS TCPFlagField
$creadsPrec :: Int -> ReadS TCPFlagField
Prelude.Read, Int -> TCPFlagField -> ShowS
[TCPFlagField] -> ShowS
TCPFlagField -> String
(Int -> TCPFlagField -> ShowS)
-> (TCPFlagField -> String)
-> ([TCPFlagField] -> ShowS)
-> Show TCPFlagField
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TCPFlagField] -> ShowS
$cshowList :: [TCPFlagField] -> ShowS
show :: TCPFlagField -> String
$cshow :: TCPFlagField -> String
showsPrec :: Int -> TCPFlagField -> ShowS
$cshowsPrec :: Int -> TCPFlagField -> ShowS
Prelude.Show, (forall x. TCPFlagField -> Rep TCPFlagField x)
-> (forall x. Rep TCPFlagField x -> TCPFlagField)
-> Generic TCPFlagField
forall x. Rep TCPFlagField x -> TCPFlagField
forall x. TCPFlagField -> Rep TCPFlagField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TCPFlagField x -> TCPFlagField
$cfrom :: forall x. TCPFlagField -> Rep TCPFlagField x
Prelude.Generic)

-- |
-- Create a value of 'TCPFlagField' 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:
--
-- 'masks', 'tCPFlagField_masks' - The set of flags to consider in the inspection. To inspect all flags in
-- the valid values list, leave this with no setting.
--
-- 'flags', 'tCPFlagField_flags' - Used in conjunction with the @Masks@ setting to define the flags that
-- must be set and flags that must not be set in order for the packet to
-- match. This setting can only specify values that are also specified in
-- the @Masks@ setting.
--
-- For the flags that are specified in the masks setting, the following
-- must be true for the packet to match:
--
-- -   The ones that are set in this flags setting must be set in the
--     packet.
--
-- -   The ones that are not set in this flags setting must also not be set
--     in the packet.
newTCPFlagField ::
  TCPFlagField
newTCPFlagField :: TCPFlagField
newTCPFlagField =
  TCPFlagField' :: Maybe [TCPFlag] -> [TCPFlag] -> TCPFlagField
TCPFlagField'
    { $sel:masks:TCPFlagField' :: Maybe [TCPFlag]
masks = Maybe [TCPFlag]
forall a. Maybe a
Prelude.Nothing,
      $sel:flags:TCPFlagField' :: [TCPFlag]
flags = [TCPFlag]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The set of flags to consider in the inspection. To inspect all flags in
-- the valid values list, leave this with no setting.
tCPFlagField_masks :: Lens.Lens' TCPFlagField (Prelude.Maybe [TCPFlag])
tCPFlagField_masks :: (Maybe [TCPFlag] -> f (Maybe [TCPFlag]))
-> TCPFlagField -> f TCPFlagField
tCPFlagField_masks = (TCPFlagField -> Maybe [TCPFlag])
-> (TCPFlagField -> Maybe [TCPFlag] -> TCPFlagField)
-> Lens
     TCPFlagField TCPFlagField (Maybe [TCPFlag]) (Maybe [TCPFlag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TCPFlagField' {Maybe [TCPFlag]
masks :: Maybe [TCPFlag]
$sel:masks:TCPFlagField' :: TCPFlagField -> Maybe [TCPFlag]
masks} -> Maybe [TCPFlag]
masks) (\s :: TCPFlagField
s@TCPFlagField' {} Maybe [TCPFlag]
a -> TCPFlagField
s {$sel:masks:TCPFlagField' :: Maybe [TCPFlag]
masks = Maybe [TCPFlag]
a} :: TCPFlagField) ((Maybe [TCPFlag] -> f (Maybe [TCPFlag]))
 -> TCPFlagField -> f TCPFlagField)
-> ((Maybe [TCPFlag] -> f (Maybe [TCPFlag]))
    -> Maybe [TCPFlag] -> f (Maybe [TCPFlag]))
-> (Maybe [TCPFlag] -> f (Maybe [TCPFlag]))
-> TCPFlagField
-> f TCPFlagField
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [TCPFlag] [TCPFlag] [TCPFlag] [TCPFlag]
-> Iso
     (Maybe [TCPFlag])
     (Maybe [TCPFlag])
     (Maybe [TCPFlag])
     (Maybe [TCPFlag])
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 [TCPFlag] [TCPFlag] [TCPFlag] [TCPFlag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Used in conjunction with the @Masks@ setting to define the flags that
-- must be set and flags that must not be set in order for the packet to
-- match. This setting can only specify values that are also specified in
-- the @Masks@ setting.
--
-- For the flags that are specified in the masks setting, the following
-- must be true for the packet to match:
--
-- -   The ones that are set in this flags setting must be set in the
--     packet.
--
-- -   The ones that are not set in this flags setting must also not be set
--     in the packet.
tCPFlagField_flags :: Lens.Lens' TCPFlagField [TCPFlag]
tCPFlagField_flags :: ([TCPFlag] -> f [TCPFlag]) -> TCPFlagField -> f TCPFlagField
tCPFlagField_flags = (TCPFlagField -> [TCPFlag])
-> (TCPFlagField -> [TCPFlag] -> TCPFlagField)
-> Lens TCPFlagField TCPFlagField [TCPFlag] [TCPFlag]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TCPFlagField' {[TCPFlag]
flags :: [TCPFlag]
$sel:flags:TCPFlagField' :: TCPFlagField -> [TCPFlag]
flags} -> [TCPFlag]
flags) (\s :: TCPFlagField
s@TCPFlagField' {} [TCPFlag]
a -> TCPFlagField
s {$sel:flags:TCPFlagField' :: [TCPFlag]
flags = [TCPFlag]
a} :: TCPFlagField) (([TCPFlag] -> f [TCPFlag]) -> TCPFlagField -> f TCPFlagField)
-> (([TCPFlag] -> f [TCPFlag]) -> [TCPFlag] -> f [TCPFlag])
-> ([TCPFlag] -> f [TCPFlag])
-> TCPFlagField
-> f TCPFlagField
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([TCPFlag] -> f [TCPFlag]) -> [TCPFlag] -> f [TCPFlag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON TCPFlagField where
  parseJSON :: Value -> Parser TCPFlagField
parseJSON =
    String
-> (Object -> Parser TCPFlagField) -> Value -> Parser TCPFlagField
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TCPFlagField"
      ( \Object
x ->
          Maybe [TCPFlag] -> [TCPFlag] -> TCPFlagField
TCPFlagField'
            (Maybe [TCPFlag] -> [TCPFlag] -> TCPFlagField)
-> Parser (Maybe [TCPFlag]) -> Parser ([TCPFlag] -> TCPFlagField)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [TCPFlag]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Masks" Parser (Maybe (Maybe [TCPFlag]))
-> Maybe [TCPFlag] -> Parser (Maybe [TCPFlag])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [TCPFlag]
forall a. Monoid a => a
Prelude.mempty)
            Parser ([TCPFlag] -> TCPFlagField)
-> Parser [TCPFlag] -> Parser TCPFlagField
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [TCPFlag])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Flags" Parser (Maybe [TCPFlag]) -> [TCPFlag] -> Parser [TCPFlag]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [TCPFlag]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable TCPFlagField

instance Prelude.NFData TCPFlagField

instance Core.ToJSON TCPFlagField where
  toJSON :: TCPFlagField -> Value
toJSON TCPFlagField' {[TCPFlag]
Maybe [TCPFlag]
flags :: [TCPFlag]
masks :: Maybe [TCPFlag]
$sel:flags:TCPFlagField' :: TCPFlagField -> [TCPFlag]
$sel:masks:TCPFlagField' :: TCPFlagField -> Maybe [TCPFlag]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Masks" Text -> [TCPFlag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([TCPFlag] -> Pair) -> Maybe [TCPFlag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [TCPFlag]
masks,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Flags" Text -> [TCPFlag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [TCPFlag]
flags)
          ]
      )