{-# 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.EMR.Types.PortRange
-- 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.EMR.Types.PortRange where

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

-- | A list of port ranges that are permitted to allow inbound traffic from
-- all public IP addresses. To specify a single port, use the same value
-- for @MinRange@ and @MaxRange@.
--
-- /See:/ 'newPortRange' smart constructor.
data PortRange = PortRange'
  { -- | The smallest port number in a specified range of port numbers.
    PortRange -> Maybe Int
maxRange :: Prelude.Maybe Prelude.Int,
    -- | The smallest port number in a specified range of port numbers.
    PortRange -> Int
minRange :: Prelude.Int
  }
  deriving (PortRange -> PortRange -> Bool
(PortRange -> PortRange -> Bool)
-> (PortRange -> PortRange -> Bool) -> Eq PortRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortRange -> PortRange -> Bool
$c/= :: PortRange -> PortRange -> Bool
== :: PortRange -> PortRange -> Bool
$c== :: PortRange -> PortRange -> Bool
Prelude.Eq, ReadPrec [PortRange]
ReadPrec PortRange
Int -> ReadS PortRange
ReadS [PortRange]
(Int -> ReadS PortRange)
-> ReadS [PortRange]
-> ReadPrec PortRange
-> ReadPrec [PortRange]
-> Read PortRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortRange]
$creadListPrec :: ReadPrec [PortRange]
readPrec :: ReadPrec PortRange
$creadPrec :: ReadPrec PortRange
readList :: ReadS [PortRange]
$creadList :: ReadS [PortRange]
readsPrec :: Int -> ReadS PortRange
$creadsPrec :: Int -> ReadS PortRange
Prelude.Read, Int -> PortRange -> ShowS
[PortRange] -> ShowS
PortRange -> String
(Int -> PortRange -> ShowS)
-> (PortRange -> String)
-> ([PortRange] -> ShowS)
-> Show PortRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortRange] -> ShowS
$cshowList :: [PortRange] -> ShowS
show :: PortRange -> String
$cshow :: PortRange -> String
showsPrec :: Int -> PortRange -> ShowS
$cshowsPrec :: Int -> PortRange -> ShowS
Prelude.Show, (forall x. PortRange -> Rep PortRange x)
-> (forall x. Rep PortRange x -> PortRange) -> Generic PortRange
forall x. Rep PortRange x -> PortRange
forall x. PortRange -> Rep PortRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortRange x -> PortRange
$cfrom :: forall x. PortRange -> Rep PortRange x
Prelude.Generic)

-- |
-- Create a value of 'PortRange' 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:
--
-- 'maxRange', 'portRange_maxRange' - The smallest port number in a specified range of port numbers.
--
-- 'minRange', 'portRange_minRange' - The smallest port number in a specified range of port numbers.
newPortRange ::
  -- | 'minRange'
  Prelude.Int ->
  PortRange
newPortRange :: Int -> PortRange
newPortRange Int
pMinRange_ =
  PortRange' :: Maybe Int -> Int -> PortRange
PortRange'
    { $sel:maxRange:PortRange' :: Maybe Int
maxRange = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:minRange:PortRange' :: Int
minRange = Int
pMinRange_
    }

-- | The smallest port number in a specified range of port numbers.
portRange_maxRange :: Lens.Lens' PortRange (Prelude.Maybe Prelude.Int)
portRange_maxRange :: (Maybe Int -> f (Maybe Int)) -> PortRange -> f PortRange
portRange_maxRange = (PortRange -> Maybe Int)
-> (PortRange -> Maybe Int -> PortRange)
-> Lens PortRange PortRange (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortRange' {Maybe Int
maxRange :: Maybe Int
$sel:maxRange:PortRange' :: PortRange -> Maybe Int
maxRange} -> Maybe Int
maxRange) (\s :: PortRange
s@PortRange' {} Maybe Int
a -> PortRange
s {$sel:maxRange:PortRange' :: Maybe Int
maxRange = Maybe Int
a} :: PortRange)

-- | The smallest port number in a specified range of port numbers.
portRange_minRange :: Lens.Lens' PortRange Prelude.Int
portRange_minRange :: (Int -> f Int) -> PortRange -> f PortRange
portRange_minRange = (PortRange -> Int)
-> (PortRange -> Int -> PortRange)
-> Lens PortRange PortRange Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortRange' {Int
minRange :: Int
$sel:minRange:PortRange' :: PortRange -> Int
minRange} -> Int
minRange) (\s :: PortRange
s@PortRange' {} Int
a -> PortRange
s {$sel:minRange:PortRange' :: Int
minRange = Int
a} :: PortRange)

instance Core.FromJSON PortRange where
  parseJSON :: Value -> Parser PortRange
parseJSON =
    String -> (Object -> Parser PortRange) -> Value -> Parser PortRange
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PortRange"
      ( \Object
x ->
          Maybe Int -> Int -> PortRange
PortRange'
            (Maybe Int -> Int -> PortRange)
-> Parser (Maybe Int) -> Parser (Int -> PortRange)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MaxRange")
            Parser (Int -> PortRange) -> Parser Int -> Parser PortRange
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MinRange")
      )

instance Prelude.Hashable PortRange

instance Prelude.NFData PortRange

instance Core.ToJSON PortRange where
  toJSON :: PortRange -> Value
toJSON PortRange' {Int
Maybe Int
minRange :: Int
maxRange :: Maybe Int
$sel:minRange:PortRange' :: PortRange -> Int
$sel:maxRange:PortRange' :: PortRange -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MaxRange" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
maxRange,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MinRange" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
minRange)
          ]
      )