{-# 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.RobOMaker.Types.PortMapping
-- 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.RobOMaker.Types.PortMapping 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

-- | An object representing a port mapping.
--
-- /See:/ 'newPortMapping' smart constructor.
data PortMapping = PortMapping'
  { -- | A Boolean indicating whether to enable this port mapping on public IP.
    PortMapping -> Maybe Bool
enableOnPublicIp :: Prelude.Maybe Prelude.Bool,
    -- | The port number on the simulation job instance to use as a remote
    -- connection point.
    PortMapping -> Natural
jobPort :: Prelude.Natural,
    -- | The port number on the application.
    PortMapping -> Natural
applicationPort :: Prelude.Natural
  }
  deriving (PortMapping -> PortMapping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortMapping -> PortMapping -> Bool
$c/= :: PortMapping -> PortMapping -> Bool
== :: PortMapping -> PortMapping -> Bool
$c== :: PortMapping -> PortMapping -> Bool
Prelude.Eq, ReadPrec [PortMapping]
ReadPrec PortMapping
Int -> ReadS PortMapping
ReadS [PortMapping]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortMapping]
$creadListPrec :: ReadPrec [PortMapping]
readPrec :: ReadPrec PortMapping
$creadPrec :: ReadPrec PortMapping
readList :: ReadS [PortMapping]
$creadList :: ReadS [PortMapping]
readsPrec :: Int -> ReadS PortMapping
$creadsPrec :: Int -> ReadS PortMapping
Prelude.Read, Int -> PortMapping -> ShowS
[PortMapping] -> ShowS
PortMapping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortMapping] -> ShowS
$cshowList :: [PortMapping] -> ShowS
show :: PortMapping -> String
$cshow :: PortMapping -> String
showsPrec :: Int -> PortMapping -> ShowS
$cshowsPrec :: Int -> PortMapping -> ShowS
Prelude.Show, forall x. Rep PortMapping x -> PortMapping
forall x. PortMapping -> Rep PortMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortMapping x -> PortMapping
$cfrom :: forall x. PortMapping -> Rep PortMapping x
Prelude.Generic)

-- |
-- Create a value of 'PortMapping' 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:
--
-- 'enableOnPublicIp', 'portMapping_enableOnPublicIp' - A Boolean indicating whether to enable this port mapping on public IP.
--
-- 'jobPort', 'portMapping_jobPort' - The port number on the simulation job instance to use as a remote
-- connection point.
--
-- 'applicationPort', 'portMapping_applicationPort' - The port number on the application.
newPortMapping ::
  -- | 'jobPort'
  Prelude.Natural ->
  -- | 'applicationPort'
  Prelude.Natural ->
  PortMapping
newPortMapping :: Natural -> Natural -> PortMapping
newPortMapping Natural
pJobPort_ Natural
pApplicationPort_ =
  PortMapping'
    { $sel:enableOnPublicIp:PortMapping' :: Maybe Bool
enableOnPublicIp = forall a. Maybe a
Prelude.Nothing,
      $sel:jobPort:PortMapping' :: Natural
jobPort = Natural
pJobPort_,
      $sel:applicationPort:PortMapping' :: Natural
applicationPort = Natural
pApplicationPort_
    }

-- | A Boolean indicating whether to enable this port mapping on public IP.
portMapping_enableOnPublicIp :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Bool)
portMapping_enableOnPublicIp :: Lens' PortMapping (Maybe Bool)
portMapping_enableOnPublicIp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Bool
enableOnPublicIp :: Maybe Bool
$sel:enableOnPublicIp:PortMapping' :: PortMapping -> Maybe Bool
enableOnPublicIp} -> Maybe Bool
enableOnPublicIp) (\s :: PortMapping
s@PortMapping' {} Maybe Bool
a -> PortMapping
s {$sel:enableOnPublicIp:PortMapping' :: Maybe Bool
enableOnPublicIp = Maybe Bool
a} :: PortMapping)

-- | The port number on the simulation job instance to use as a remote
-- connection point.
portMapping_jobPort :: Lens.Lens' PortMapping Prelude.Natural
portMapping_jobPort :: Lens' PortMapping Natural
portMapping_jobPort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Natural
jobPort :: Natural
$sel:jobPort:PortMapping' :: PortMapping -> Natural
jobPort} -> Natural
jobPort) (\s :: PortMapping
s@PortMapping' {} Natural
a -> PortMapping
s {$sel:jobPort:PortMapping' :: Natural
jobPort = Natural
a} :: PortMapping)

-- | The port number on the application.
portMapping_applicationPort :: Lens.Lens' PortMapping Prelude.Natural
portMapping_applicationPort :: Lens' PortMapping Natural
portMapping_applicationPort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Natural
applicationPort :: Natural
$sel:applicationPort:PortMapping' :: PortMapping -> Natural
applicationPort} -> Natural
applicationPort) (\s :: PortMapping
s@PortMapping' {} Natural
a -> PortMapping
s {$sel:applicationPort:PortMapping' :: Natural
applicationPort = Natural
a} :: PortMapping)

instance Data.FromJSON PortMapping where
  parseJSON :: Value -> Parser PortMapping
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PortMapping"
      ( \Object
x ->
          Maybe Bool -> Natural -> Natural -> PortMapping
PortMapping'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"enableOnPublicIp")
            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
"jobPort")
            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
"applicationPort")
      )

instance Prelude.Hashable PortMapping where
  hashWithSalt :: Int -> PortMapping -> Int
hashWithSalt Int
_salt PortMapping' {Natural
Maybe Bool
applicationPort :: Natural
jobPort :: Natural
enableOnPublicIp :: Maybe Bool
$sel:applicationPort:PortMapping' :: PortMapping -> Natural
$sel:jobPort:PortMapping' :: PortMapping -> Natural
$sel:enableOnPublicIp:PortMapping' :: PortMapping -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enableOnPublicIp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
jobPort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
applicationPort

instance Prelude.NFData PortMapping where
  rnf :: PortMapping -> ()
rnf PortMapping' {Natural
Maybe Bool
applicationPort :: Natural
jobPort :: Natural
enableOnPublicIp :: Maybe Bool
$sel:applicationPort:PortMapping' :: PortMapping -> Natural
$sel:jobPort:PortMapping' :: PortMapping -> Natural
$sel:enableOnPublicIp:PortMapping' :: PortMapping -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enableOnPublicIp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
jobPort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
applicationPort

instance Data.ToJSON PortMapping where
  toJSON :: PortMapping -> Value
toJSON PortMapping' {Natural
Maybe Bool
applicationPort :: Natural
jobPort :: Natural
enableOnPublicIp :: Maybe Bool
$sel:applicationPort:PortMapping' :: PortMapping -> Natural
$sel:jobPort:PortMapping' :: PortMapping -> Natural
$sel:enableOnPublicIp:PortMapping' :: PortMapping -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"enableOnPublicIp" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enableOnPublicIp,
            forall a. a -> Maybe a
Prelude.Just (Key
"jobPort" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
jobPort),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"applicationPort" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
applicationPort)
          ]
      )