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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(IPSet -> IPSet -> Bool) -> (IPSet -> IPSet -> Bool) -> Eq IPSet
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]
(Int -> ReadS IPSet)
-> ReadS [IPSet]
-> ReadPrec IPSet
-> ReadPrec [IPSet]
-> Read 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
(Int -> IPSet -> ShowS)
-> (IPSet -> String) -> ([IPSet] -> ShowS) -> Show IPSet
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. IPSet -> Rep IPSet x)
-> (forall x. Rep IPSet x -> IPSet) -> Generic IPSet
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' :: [Text] -> IPSet
IPSet' {$sel:definition:IPSet' :: [Text]
definition = [Text]
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 :: ([Text] -> f [Text]) -> IPSet -> f IPSet
iPSet_definition = (IPSet -> [Text])
-> (IPSet -> [Text] -> IPSet) -> Lens IPSet IPSet [Text] [Text]
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) (([Text] -> f [Text]) -> IPSet -> f IPSet)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> IPSet
-> f IPSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable IPSet

instance Prelude.NFData IPSet

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