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

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

-- | A single IP address specification. This is used in the MatchAttributes
-- source and destination specifications.
--
-- /See:/ 'newAddress' smart constructor.
data Address = Address'
  { -- | Specify an IP address or a block of IP addresses in Classless
    -- Inter-Domain Routing (CIDR) notation. Network Firewall supports all
    -- address ranges for IPv4.
    --
    -- Examples:
    --
    -- -   To configure Network Firewall to inspect for the IP address
    --     192.0.2.44, specify @192.0.2.44\/32@.
    --
    -- -   To configure Network Firewall to inspect for 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>.
    Address -> Text
addressDefinition :: Prelude.Text
  }
  deriving (Address -> Address -> Bool
(Address -> Address -> Bool)
-> (Address -> Address -> Bool) -> Eq Address
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Address -> Address -> Bool
$c/= :: Address -> Address -> Bool
== :: Address -> Address -> Bool
$c== :: Address -> Address -> Bool
Prelude.Eq, ReadPrec [Address]
ReadPrec Address
Int -> ReadS Address
ReadS [Address]
(Int -> ReadS Address)
-> ReadS [Address]
-> ReadPrec Address
-> ReadPrec [Address]
-> Read Address
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Address]
$creadListPrec :: ReadPrec [Address]
readPrec :: ReadPrec Address
$creadPrec :: ReadPrec Address
readList :: ReadS [Address]
$creadList :: ReadS [Address]
readsPrec :: Int -> ReadS Address
$creadsPrec :: Int -> ReadS Address
Prelude.Read, Int -> Address -> ShowS
[Address] -> ShowS
Address -> String
(Int -> Address -> ShowS)
-> (Address -> String) -> ([Address] -> ShowS) -> Show Address
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Address] -> ShowS
$cshowList :: [Address] -> ShowS
show :: Address -> String
$cshow :: Address -> String
showsPrec :: Int -> Address -> ShowS
$cshowsPrec :: Int -> Address -> ShowS
Prelude.Show, (forall x. Address -> Rep Address x)
-> (forall x. Rep Address x -> Address) -> Generic Address
forall x. Rep Address x -> Address
forall x. Address -> Rep Address x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Address x -> Address
$cfrom :: forall x. Address -> Rep Address x
Prelude.Generic)

-- |
-- Create a value of 'Address' 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:
--
-- 'addressDefinition', 'address_addressDefinition' - Specify an IP address or a block of IP addresses in Classless
-- Inter-Domain Routing (CIDR) notation. Network Firewall supports all
-- address ranges for IPv4.
--
-- Examples:
--
-- -   To configure Network Firewall to inspect for the IP address
--     192.0.2.44, specify @192.0.2.44\/32@.
--
-- -   To configure Network Firewall to inspect for 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>.
newAddress ::
  -- | 'addressDefinition'
  Prelude.Text ->
  Address
newAddress :: Text -> Address
newAddress Text
pAddressDefinition_ =
  Address' :: Text -> Address
Address' {$sel:addressDefinition:Address' :: Text
addressDefinition = Text
pAddressDefinition_}

-- | Specify an IP address or a block of IP addresses in Classless
-- Inter-Domain Routing (CIDR) notation. Network Firewall supports all
-- address ranges for IPv4.
--
-- Examples:
--
-- -   To configure Network Firewall to inspect for the IP address
--     192.0.2.44, specify @192.0.2.44\/32@.
--
-- -   To configure Network Firewall to inspect for 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>.
address_addressDefinition :: Lens.Lens' Address Prelude.Text
address_addressDefinition :: (Text -> f Text) -> Address -> f Address
address_addressDefinition = (Address -> Text)
-> (Address -> Text -> Address) -> Lens Address Address Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Address' {Text
addressDefinition :: Text
$sel:addressDefinition:Address' :: Address -> Text
addressDefinition} -> Text
addressDefinition) (\s :: Address
s@Address' {} Text
a -> Address
s {$sel:addressDefinition:Address' :: Text
addressDefinition = Text
a} :: Address)

instance Core.FromJSON Address where
  parseJSON :: Value -> Parser Address
parseJSON =
    String -> (Object -> Parser Address) -> Value -> Parser Address
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Address"
      ( \Object
x ->
          Text -> Address
Address' (Text -> Address) -> Parser Text -> Parser Address
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AddressDefinition")
      )

instance Prelude.Hashable Address

instance Prelude.NFData Address

instance Core.ToJSON Address where
  toJSON :: Address -> Value
toJSON Address' {Text
addressDefinition :: Text
$sel:addressDefinition:Address' :: Address -> 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
"AddressDefinition" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
addressDefinition)
          ]
      )