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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(PortMapping -> PortMapping -> Bool)
-> (PortMapping -> PortMapping -> Bool) -> Eq PortMapping
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]
(Int -> ReadS PortMapping)
-> ReadS [PortMapping]
-> ReadPrec PortMapping
-> ReadPrec [PortMapping]
-> Read 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
(Int -> PortMapping -> ShowS)
-> (PortMapping -> String)
-> ([PortMapping] -> ShowS)
-> Show PortMapping
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. PortMapping -> Rep PortMapping x)
-> (forall x. Rep PortMapping x -> PortMapping)
-> Generic PortMapping
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' :: Maybe Bool -> Natural -> Natural -> PortMapping
PortMapping'
    { $sel:enableOnPublicIp:PortMapping' :: Maybe Bool
enableOnPublicIp = Maybe Bool
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 :: (Maybe Bool -> f (Maybe Bool)) -> PortMapping -> f PortMapping
portMapping_enableOnPublicIp = (PortMapping -> Maybe Bool)
-> (PortMapping -> Maybe Bool -> PortMapping)
-> Lens PortMapping PortMapping (Maybe Bool) (Maybe Bool)
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 :: (Natural -> f Natural) -> PortMapping -> f PortMapping
portMapping_jobPort = (PortMapping -> Natural)
-> (PortMapping -> Natural -> PortMapping)
-> Lens PortMapping PortMapping Natural Natural
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 :: (Natural -> f Natural) -> PortMapping -> f PortMapping
portMapping_applicationPort = (PortMapping -> Natural)
-> (PortMapping -> Natural -> PortMapping)
-> Lens PortMapping PortMapping Natural Natural
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 Core.FromJSON PortMapping where
  parseJSON :: Value -> Parser PortMapping
parseJSON =
    String
-> (Object -> Parser PortMapping) -> Value -> Parser PortMapping
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PortMapping"
      ( \Object
x ->
          Maybe Bool -> Natural -> Natural -> PortMapping
PortMapping'
            (Maybe Bool -> Natural -> Natural -> PortMapping)
-> Parser (Maybe Bool)
-> Parser (Natural -> Natural -> PortMapping)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"enableOnPublicIp")
            Parser (Natural -> Natural -> PortMapping)
-> Parser Natural -> Parser (Natural -> PortMapping)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"jobPort")
            Parser (Natural -> PortMapping)
-> Parser Natural -> Parser PortMapping
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"applicationPort")
      )

instance Prelude.Hashable PortMapping

instance Prelude.NFData PortMapping

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"enableOnPublicIp" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enableOnPublicIp,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"jobPort" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
jobPort),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"applicationPort" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
applicationPort)
          ]
      )