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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EC2.Internal
import qualified Amazonka.Prelude as Prelude

-- | Describes a range of ports.
--
-- /See:/ 'newPortRange' smart constructor.
data PortRange = PortRange'
  { -- | The first port in the range.
    PortRange -> Maybe Int
from :: Prelude.Maybe Prelude.Int,
    -- | The last port in the range.
    PortRange -> Maybe Int
to :: Prelude.Maybe Prelude.Int
  }
  deriving (PortRange -> PortRange -> Bool
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]
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
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. 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:
--
-- 'from', 'portRange_from' - The first port in the range.
--
-- 'to', 'portRange_to' - The last port in the range.
newPortRange ::
  PortRange
newPortRange :: PortRange
newPortRange =
  PortRange'
    { $sel:from:PortRange' :: Maybe Int
from = forall a. Maybe a
Prelude.Nothing,
      $sel:to:PortRange' :: Maybe Int
to = forall a. Maybe a
Prelude.Nothing
    }

-- | The first port in the range.
portRange_from :: Lens.Lens' PortRange (Prelude.Maybe Prelude.Int)
portRange_from :: Lens' PortRange (Maybe Int)
portRange_from = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortRange' {Maybe Int
from :: Maybe Int
$sel:from:PortRange' :: PortRange -> Maybe Int
from} -> Maybe Int
from) (\s :: PortRange
s@PortRange' {} Maybe Int
a -> PortRange
s {$sel:from:PortRange' :: Maybe Int
from = Maybe Int
a} :: PortRange)

-- | The last port in the range.
portRange_to :: Lens.Lens' PortRange (Prelude.Maybe Prelude.Int)
portRange_to :: Lens' PortRange (Maybe Int)
portRange_to = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortRange' {Maybe Int
to :: Maybe Int
$sel:to:PortRange' :: PortRange -> Maybe Int
to} -> Maybe Int
to) (\s :: PortRange
s@PortRange' {} Maybe Int
a -> PortRange
s {$sel:to:PortRange' :: Maybe Int
to = Maybe Int
a} :: PortRange)

instance Data.FromXML PortRange where
  parseXML :: [Node] -> Either String PortRange
parseXML [Node]
x =
    Maybe Int -> Maybe Int -> PortRange
PortRange'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"from")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"to")

instance Prelude.Hashable PortRange where
  hashWithSalt :: Int -> PortRange -> Int
hashWithSalt Int
_salt PortRange' {Maybe Int
to :: Maybe Int
from :: Maybe Int
$sel:to:PortRange' :: PortRange -> Maybe Int
$sel:from:PortRange' :: PortRange -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
from
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
to

instance Prelude.NFData PortRange where
  rnf :: PortRange -> ()
rnf PortRange' {Maybe Int
to :: Maybe Int
from :: Maybe Int
$sel:to:PortRange' :: PortRange -> Maybe Int
$sel:from:PortRange' :: PortRange -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
from seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
to

instance Data.ToQuery PortRange where
  toQuery :: PortRange -> QueryString
toQuery PortRange' {Maybe Int
to :: Maybe Int
from :: Maybe Int
$sel:to:PortRange' :: PortRange -> Maybe Int
$sel:from:PortRange' :: PortRange -> Maybe Int
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"From" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Int
from, ByteString
"To" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Int
to]