{-# 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.Inspector2.Types.PortRangeFilter
-- 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.Inspector2.Types.PortRangeFilter 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

-- | An object that describes the details of a port range filter.
--
-- /See:/ 'newPortRangeFilter' smart constructor.
data PortRangeFilter = PortRangeFilter'
  { -- | The port number the port range begins at.
    PortRangeFilter -> Maybe Natural
beginInclusive :: Prelude.Maybe Prelude.Natural,
    -- | The port number the port range ends at.
    PortRangeFilter -> Maybe Natural
endInclusive :: Prelude.Maybe Prelude.Natural
  }
  deriving (PortRangeFilter -> PortRangeFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortRangeFilter -> PortRangeFilter -> Bool
$c/= :: PortRangeFilter -> PortRangeFilter -> Bool
== :: PortRangeFilter -> PortRangeFilter -> Bool
$c== :: PortRangeFilter -> PortRangeFilter -> Bool
Prelude.Eq, ReadPrec [PortRangeFilter]
ReadPrec PortRangeFilter
Int -> ReadS PortRangeFilter
ReadS [PortRangeFilter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortRangeFilter]
$creadListPrec :: ReadPrec [PortRangeFilter]
readPrec :: ReadPrec PortRangeFilter
$creadPrec :: ReadPrec PortRangeFilter
readList :: ReadS [PortRangeFilter]
$creadList :: ReadS [PortRangeFilter]
readsPrec :: Int -> ReadS PortRangeFilter
$creadsPrec :: Int -> ReadS PortRangeFilter
Prelude.Read, Int -> PortRangeFilter -> ShowS
[PortRangeFilter] -> ShowS
PortRangeFilter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortRangeFilter] -> ShowS
$cshowList :: [PortRangeFilter] -> ShowS
show :: PortRangeFilter -> String
$cshow :: PortRangeFilter -> String
showsPrec :: Int -> PortRangeFilter -> ShowS
$cshowsPrec :: Int -> PortRangeFilter -> ShowS
Prelude.Show, forall x. Rep PortRangeFilter x -> PortRangeFilter
forall x. PortRangeFilter -> Rep PortRangeFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortRangeFilter x -> PortRangeFilter
$cfrom :: forall x. PortRangeFilter -> Rep PortRangeFilter x
Prelude.Generic)

-- |
-- Create a value of 'PortRangeFilter' 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:
--
-- 'beginInclusive', 'portRangeFilter_beginInclusive' - The port number the port range begins at.
--
-- 'endInclusive', 'portRangeFilter_endInclusive' - The port number the port range ends at.
newPortRangeFilter ::
  PortRangeFilter
newPortRangeFilter :: PortRangeFilter
newPortRangeFilter =
  PortRangeFilter'
    { $sel:beginInclusive:PortRangeFilter' :: Maybe Natural
beginInclusive = forall a. Maybe a
Prelude.Nothing,
      $sel:endInclusive:PortRangeFilter' :: Maybe Natural
endInclusive = forall a. Maybe a
Prelude.Nothing
    }

-- | The port number the port range begins at.
portRangeFilter_beginInclusive :: Lens.Lens' PortRangeFilter (Prelude.Maybe Prelude.Natural)
portRangeFilter_beginInclusive :: Lens' PortRangeFilter (Maybe Natural)
portRangeFilter_beginInclusive = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortRangeFilter' {Maybe Natural
beginInclusive :: Maybe Natural
$sel:beginInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
beginInclusive} -> Maybe Natural
beginInclusive) (\s :: PortRangeFilter
s@PortRangeFilter' {} Maybe Natural
a -> PortRangeFilter
s {$sel:beginInclusive:PortRangeFilter' :: Maybe Natural
beginInclusive = Maybe Natural
a} :: PortRangeFilter)

-- | The port number the port range ends at.
portRangeFilter_endInclusive :: Lens.Lens' PortRangeFilter (Prelude.Maybe Prelude.Natural)
portRangeFilter_endInclusive :: Lens' PortRangeFilter (Maybe Natural)
portRangeFilter_endInclusive = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortRangeFilter' {Maybe Natural
endInclusive :: Maybe Natural
$sel:endInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
endInclusive} -> Maybe Natural
endInclusive) (\s :: PortRangeFilter
s@PortRangeFilter' {} Maybe Natural
a -> PortRangeFilter
s {$sel:endInclusive:PortRangeFilter' :: Maybe Natural
endInclusive = Maybe Natural
a} :: PortRangeFilter)

instance Data.FromJSON PortRangeFilter where
  parseJSON :: Value -> Parser PortRangeFilter
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PortRangeFilter"
      ( \Object
x ->
          Maybe Natural -> Maybe Natural -> PortRangeFilter
PortRangeFilter'
            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
"beginInclusive")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"endInclusive")
      )

instance Prelude.Hashable PortRangeFilter where
  hashWithSalt :: Int -> PortRangeFilter -> Int
hashWithSalt Int
_salt PortRangeFilter' {Maybe Natural
endInclusive :: Maybe Natural
beginInclusive :: Maybe Natural
$sel:endInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
$sel:beginInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
beginInclusive
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
endInclusive

instance Prelude.NFData PortRangeFilter where
  rnf :: PortRangeFilter -> ()
rnf PortRangeFilter' {Maybe Natural
endInclusive :: Maybe Natural
beginInclusive :: Maybe Natural
$sel:endInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
$sel:beginInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
beginInclusive
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
endInclusive

instance Data.ToJSON PortRangeFilter where
  toJSON :: PortRangeFilter -> Value
toJSON PortRangeFilter' {Maybe Natural
endInclusive :: Maybe Natural
beginInclusive :: Maybe Natural
$sel:endInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
$sel:beginInclusive:PortRangeFilter' :: PortRangeFilter -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"beginInclusive" 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 Natural
beginInclusive,
            (Key
"endInclusive" 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 Natural
endInclusive
          ]
      )