{-# 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.IPSet
-- 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.IPSet 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

-- | A list of IP addresses and address ranges, in CIDR notation. This is
-- part of a RuleVariables.
--
-- /See:/ 'newIPSet' smart constructor.
data IPSet = IPSet'
  { -- | The list of IP addresses and address ranges, in CIDR notation.
    IPSet -> [Text]
definition :: [Prelude.Text]
  }
  deriving (IPSet -> IPSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IPSet -> IPSet -> Bool
$c/= :: IPSet -> IPSet -> Bool
== :: IPSet -> IPSet -> Bool
$c== :: IPSet -> IPSet -> Bool
Prelude.Eq, ReadPrec [IPSet]
ReadPrec IPSet
Int -> ReadS IPSet
ReadS [IPSet]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IPSet]
$creadListPrec :: ReadPrec [IPSet]
readPrec :: ReadPrec IPSet
$creadPrec :: ReadPrec IPSet
readList :: ReadS [IPSet]
$creadList :: ReadS [IPSet]
readsPrec :: Int -> ReadS IPSet
$creadsPrec :: Int -> ReadS IPSet
Prelude.Read, Int -> IPSet -> ShowS
[IPSet] -> ShowS
IPSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IPSet] -> ShowS
$cshowList :: [IPSet] -> ShowS
show :: IPSet -> String
$cshow :: IPSet -> String
showsPrec :: Int -> IPSet -> ShowS
$cshowsPrec :: Int -> IPSet -> ShowS
Prelude.Show, forall x. Rep IPSet x -> IPSet
forall x. IPSet -> Rep IPSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IPSet x -> IPSet
$cfrom :: forall x. IPSet -> Rep IPSet x
Prelude.Generic)

-- |
-- Create a value of 'IPSet' 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', 'iPSet_definition' - The list of IP addresses and address ranges, in CIDR notation.
newIPSet ::
  IPSet
newIPSet :: IPSet
newIPSet = IPSet' {$sel:definition:IPSet' :: [Text]
definition = forall a. Monoid a => a
Prelude.mempty}

-- | The list of IP addresses and address ranges, in CIDR notation.
iPSet_definition :: Lens.Lens' IPSet [Prelude.Text]
iPSet_definition :: Lens' IPSet [Text]
iPSet_definition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSet' {[Text]
definition :: [Text]
$sel:definition:IPSet' :: IPSet -> [Text]
definition} -> [Text]
definition) (\s :: IPSet
s@IPSet' {} [Text]
a -> IPSet
s {$sel:definition:IPSet' :: [Text]
definition = [Text]
a} :: IPSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable IPSet where
  hashWithSalt :: Int -> IPSet -> Int
hashWithSalt Int
_salt IPSet' {[Text]
definition :: [Text]
$sel:definition:IPSet' :: IPSet -> [Text]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
definition

instance Prelude.NFData IPSet where
  rnf :: IPSet -> ()
rnf IPSet' {[Text]
definition :: [Text]
$sel:definition:IPSet' :: IPSet -> [Text]
..} = forall a. NFData a => a -> ()
Prelude.rnf [Text]
definition

instance Data.ToJSON IPSet where
  toJSON :: IPSet -> Value
toJSON IPSet' {[Text]
definition :: [Text]
$sel:definition:IPSet' :: IPSet -> [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Definition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
definition)]
      )