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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A set of port ranges for use in the rules in a rule group.
--
-- /See:/ 'newPortSet' smart constructor.
data PortSet = PortSet'
  { -- | The set of port ranges.
    PortSet -> Maybe [Text]
definition :: Prelude.Maybe [Prelude.Text]
  }
  deriving (PortSet -> PortSet -> Bool
(PortSet -> PortSet -> Bool)
-> (PortSet -> PortSet -> Bool) -> Eq PortSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortSet -> PortSet -> Bool
$c/= :: PortSet -> PortSet -> Bool
== :: PortSet -> PortSet -> Bool
$c== :: PortSet -> PortSet -> Bool
Prelude.Eq, ReadPrec [PortSet]
ReadPrec PortSet
Int -> ReadS PortSet
ReadS [PortSet]
(Int -> ReadS PortSet)
-> ReadS [PortSet]
-> ReadPrec PortSet
-> ReadPrec [PortSet]
-> Read PortSet
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortSet]
$creadListPrec :: ReadPrec [PortSet]
readPrec :: ReadPrec PortSet
$creadPrec :: ReadPrec PortSet
readList :: ReadS [PortSet]
$creadList :: ReadS [PortSet]
readsPrec :: Int -> ReadS PortSet
$creadsPrec :: Int -> ReadS PortSet
Prelude.Read, Int -> PortSet -> ShowS
[PortSet] -> ShowS
PortSet -> String
(Int -> PortSet -> ShowS)
-> (PortSet -> String) -> ([PortSet] -> ShowS) -> Show PortSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortSet] -> ShowS
$cshowList :: [PortSet] -> ShowS
show :: PortSet -> String
$cshow :: PortSet -> String
showsPrec :: Int -> PortSet -> ShowS
$cshowsPrec :: Int -> PortSet -> ShowS
Prelude.Show, (forall x. PortSet -> Rep PortSet x)
-> (forall x. Rep PortSet x -> PortSet) -> Generic PortSet
forall x. Rep PortSet x -> PortSet
forall x. PortSet -> Rep PortSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortSet x -> PortSet
$cfrom :: forall x. PortSet -> Rep PortSet x
Prelude.Generic)

-- |
-- Create a value of 'PortSet' 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:
--
-- 'definition', 'portSet_definition' - The set of port ranges.
newPortSet ::
  PortSet
newPortSet :: PortSet
newPortSet = PortSet' :: Maybe [Text] -> PortSet
PortSet' {$sel:definition:PortSet' :: Maybe [Text]
definition = Maybe [Text]
forall a. Maybe a
Prelude.Nothing}

-- | The set of port ranges.
portSet_definition :: Lens.Lens' PortSet (Prelude.Maybe [Prelude.Text])
portSet_definition :: (Maybe [Text] -> f (Maybe [Text])) -> PortSet -> f PortSet
portSet_definition = (PortSet -> Maybe [Text])
-> (PortSet -> Maybe [Text] -> PortSet)
-> Lens PortSet PortSet (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortSet' {Maybe [Text]
definition :: Maybe [Text]
$sel:definition:PortSet' :: PortSet -> Maybe [Text]
definition} -> Maybe [Text]
definition) (\s :: PortSet
s@PortSet' {} Maybe [Text]
a -> PortSet
s {$sel:definition:PortSet' :: Maybe [Text]
definition = Maybe [Text]
a} :: PortSet) ((Maybe [Text] -> f (Maybe [Text])) -> PortSet -> f PortSet)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> PortSet
-> f PortSet
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

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

instance Prelude.Hashable PortSet

instance Prelude.NFData PortSet

instance Core.ToJSON PortSet where
  toJSON :: PortSet -> Value
toJSON PortSet' {Maybe [Text]
definition :: Maybe [Text]
$sel:definition:PortSet' :: PortSet -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Definition" 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]
definition]
      )