{-# 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.WAF.Types.IPSetDescriptor
-- 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.WAF.Types.IPSetDescriptor 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
import Amazonka.WAF.Types.IPSetDescriptorType

-- | This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- Specifies the IP address type (@IPV4@ or @IPV6@) and the IP address
-- range (in CIDR format) that web requests originate from.
--
-- /See:/ 'newIPSetDescriptor' smart constructor.
data IPSetDescriptor = IPSetDescriptor'
  { -- | Specify @IPV4@ or @IPV6@.
    IPSetDescriptor -> IPSetDescriptorType
type' :: IPSetDescriptorType,
    -- | Specify an IPv4 address by using CIDR notation. For example:
    --
    -- -   To configure AWS WAF to allow, block, or count requests that
    --     originated from the IP address 192.0.2.44, specify @192.0.2.44\/32@.
    --
    -- -   To configure AWS WAF to allow, block, or count requests that
    --     originated from IP addresses from 192.0.2.0 to 192.0.2.255, specify
    --     @192.0.2.0\/24@.
    --
    -- For more information about CIDR notation, see the Wikipedia entry
    -- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
    --
    -- Specify an IPv6 address by using CIDR notation. For example:
    --
    -- -   To configure AWS WAF to allow, block, or count requests that
    --     originated from the IP address
    --     1111:0000:0000:0000:0000:0000:0000:0111, specify
    --     @1111:0000:0000:0000:0000:0000:0000:0111\/128@.
    --
    -- -   To configure AWS WAF to allow, block, or count requests that
    --     originated from IP addresses 1111:0000:0000:0000:0000:0000:0000:0000
    --     to 1111:0000:0000:0000:ffff:ffff:ffff:ffff, specify
    --     @1111:0000:0000:0000:0000:0000:0000:0000\/64@.
    IPSetDescriptor -> Text
value :: Prelude.Text
  }
  deriving (IPSetDescriptor -> IPSetDescriptor -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IPSetDescriptor -> IPSetDescriptor -> Bool
$c/= :: IPSetDescriptor -> IPSetDescriptor -> Bool
== :: IPSetDescriptor -> IPSetDescriptor -> Bool
$c== :: IPSetDescriptor -> IPSetDescriptor -> Bool
Prelude.Eq, ReadPrec [IPSetDescriptor]
ReadPrec IPSetDescriptor
Int -> ReadS IPSetDescriptor
ReadS [IPSetDescriptor]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IPSetDescriptor]
$creadListPrec :: ReadPrec [IPSetDescriptor]
readPrec :: ReadPrec IPSetDescriptor
$creadPrec :: ReadPrec IPSetDescriptor
readList :: ReadS [IPSetDescriptor]
$creadList :: ReadS [IPSetDescriptor]
readsPrec :: Int -> ReadS IPSetDescriptor
$creadsPrec :: Int -> ReadS IPSetDescriptor
Prelude.Read, Int -> IPSetDescriptor -> ShowS
[IPSetDescriptor] -> ShowS
IPSetDescriptor -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IPSetDescriptor] -> ShowS
$cshowList :: [IPSetDescriptor] -> ShowS
show :: IPSetDescriptor -> String
$cshow :: IPSetDescriptor -> String
showsPrec :: Int -> IPSetDescriptor -> ShowS
$cshowsPrec :: Int -> IPSetDescriptor -> ShowS
Prelude.Show, forall x. Rep IPSetDescriptor x -> IPSetDescriptor
forall x. IPSetDescriptor -> Rep IPSetDescriptor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IPSetDescriptor x -> IPSetDescriptor
$cfrom :: forall x. IPSetDescriptor -> Rep IPSetDescriptor x
Prelude.Generic)

-- |
-- Create a value of 'IPSetDescriptor' 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:
--
-- 'type'', 'iPSetDescriptor_type' - Specify @IPV4@ or @IPV6@.
--
-- 'value', 'iPSetDescriptor_value' - Specify an IPv4 address by using CIDR notation. For example:
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from the IP address 192.0.2.44, specify @192.0.2.44\/32@.
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from IP addresses from 192.0.2.0 to 192.0.2.255, specify
--     @192.0.2.0\/24@.
--
-- For more information about CIDR notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- Specify an IPv6 address by using CIDR notation. For example:
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from the IP address
--     1111:0000:0000:0000:0000:0000:0000:0111, specify
--     @1111:0000:0000:0000:0000:0000:0000:0111\/128@.
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from IP addresses 1111:0000:0000:0000:0000:0000:0000:0000
--     to 1111:0000:0000:0000:ffff:ffff:ffff:ffff, specify
--     @1111:0000:0000:0000:0000:0000:0000:0000\/64@.
newIPSetDescriptor ::
  -- | 'type''
  IPSetDescriptorType ->
  -- | 'value'
  Prelude.Text ->
  IPSetDescriptor
newIPSetDescriptor :: IPSetDescriptorType -> Text -> IPSetDescriptor
newIPSetDescriptor IPSetDescriptorType
pType_ Text
pValue_ =
  IPSetDescriptor' {$sel:type':IPSetDescriptor' :: IPSetDescriptorType
type' = IPSetDescriptorType
pType_, $sel:value:IPSetDescriptor' :: Text
value = Text
pValue_}

-- | Specify @IPV4@ or @IPV6@.
iPSetDescriptor_type :: Lens.Lens' IPSetDescriptor IPSetDescriptorType
iPSetDescriptor_type :: Lens' IPSetDescriptor IPSetDescriptorType
iPSetDescriptor_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSetDescriptor' {IPSetDescriptorType
type' :: IPSetDescriptorType
$sel:type':IPSetDescriptor' :: IPSetDescriptor -> IPSetDescriptorType
type'} -> IPSetDescriptorType
type') (\s :: IPSetDescriptor
s@IPSetDescriptor' {} IPSetDescriptorType
a -> IPSetDescriptor
s {$sel:type':IPSetDescriptor' :: IPSetDescriptorType
type' = IPSetDescriptorType
a} :: IPSetDescriptor)

-- | Specify an IPv4 address by using CIDR notation. For example:
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from the IP address 192.0.2.44, specify @192.0.2.44\/32@.
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from IP addresses from 192.0.2.0 to 192.0.2.255, specify
--     @192.0.2.0\/24@.
--
-- For more information about CIDR notation, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing Classless Inter-Domain Routing>.
--
-- Specify an IPv6 address by using CIDR notation. For example:
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from the IP address
--     1111:0000:0000:0000:0000:0000:0000:0111, specify
--     @1111:0000:0000:0000:0000:0000:0000:0111\/128@.
--
-- -   To configure AWS WAF to allow, block, or count requests that
--     originated from IP addresses 1111:0000:0000:0000:0000:0000:0000:0000
--     to 1111:0000:0000:0000:ffff:ffff:ffff:ffff, specify
--     @1111:0000:0000:0000:0000:0000:0000:0000\/64@.
iPSetDescriptor_value :: Lens.Lens' IPSetDescriptor Prelude.Text
iPSetDescriptor_value :: Lens' IPSetDescriptor Text
iPSetDescriptor_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IPSetDescriptor' {Text
value :: Text
$sel:value:IPSetDescriptor' :: IPSetDescriptor -> Text
value} -> Text
value) (\s :: IPSetDescriptor
s@IPSetDescriptor' {} Text
a -> IPSetDescriptor
s {$sel:value:IPSetDescriptor' :: Text
value = Text
a} :: IPSetDescriptor)

instance Data.FromJSON IPSetDescriptor where
  parseJSON :: Value -> Parser IPSetDescriptor
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IPSetDescriptor"
      ( \Object
x ->
          IPSetDescriptorType -> Text -> IPSetDescriptor
IPSetDescriptor'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Type")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Value")
      )

instance Prelude.Hashable IPSetDescriptor where
  hashWithSalt :: Int -> IPSetDescriptor -> Int
hashWithSalt Int
_salt IPSetDescriptor' {Text
IPSetDescriptorType
value :: Text
type' :: IPSetDescriptorType
$sel:value:IPSetDescriptor' :: IPSetDescriptor -> Text
$sel:type':IPSetDescriptor' :: IPSetDescriptor -> IPSetDescriptorType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` IPSetDescriptorType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

instance Prelude.NFData IPSetDescriptor where
  rnf :: IPSetDescriptor -> ()
rnf IPSetDescriptor' {Text
IPSetDescriptorType
value :: Text
type' :: IPSetDescriptorType
$sel:value:IPSetDescriptor' :: IPSetDescriptor -> Text
$sel:type':IPSetDescriptor' :: IPSetDescriptor -> IPSetDescriptorType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf IPSetDescriptorType
type' seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value

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