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

import Amazonka.AppMesh.Types.PortProtocol
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents a port mapping.
--
-- /See:/ 'newPortMapping' smart constructor.
data PortMapping = PortMapping'
  { -- | The port used for the port mapping.
    PortMapping -> Natural
port :: Prelude.Natural,
    -- | The protocol used for the port mapping. Specify one protocol.
    PortMapping -> PortProtocol
protocol :: PortProtocol
  }
  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:
--
-- 'port', 'portMapping_port' - The port used for the port mapping.
--
-- 'protocol', 'portMapping_protocol' - The protocol used for the port mapping. Specify one protocol.
newPortMapping ::
  -- | 'port'
  Prelude.Natural ->
  -- | 'protocol'
  PortProtocol ->
  PortMapping
newPortMapping :: Natural -> PortProtocol -> PortMapping
newPortMapping Natural
pPort_ PortProtocol
pProtocol_ =
  PortMapping' :: Natural -> PortProtocol -> PortMapping
PortMapping' {$sel:port:PortMapping' :: Natural
port = Natural
pPort_, $sel:protocol:PortMapping' :: PortProtocol
protocol = PortProtocol
pProtocol_}

-- | The port used for the port mapping.
portMapping_port :: Lens.Lens' PortMapping Prelude.Natural
portMapping_port :: (Natural -> f Natural) -> PortMapping -> f PortMapping
portMapping_port = (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
port :: Natural
$sel:port:PortMapping' :: PortMapping -> Natural
port} -> Natural
port) (\s :: PortMapping
s@PortMapping' {} Natural
a -> PortMapping
s {$sel:port:PortMapping' :: Natural
port = Natural
a} :: PortMapping)

-- | The protocol used for the port mapping. Specify one protocol.
portMapping_protocol :: Lens.Lens' PortMapping PortProtocol
portMapping_protocol :: (PortProtocol -> f PortProtocol) -> PortMapping -> f PortMapping
portMapping_protocol = (PortMapping -> PortProtocol)
-> (PortMapping -> PortProtocol -> PortMapping)
-> Lens PortMapping PortMapping PortProtocol PortProtocol
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {PortProtocol
protocol :: PortProtocol
$sel:protocol:PortMapping' :: PortMapping -> PortProtocol
protocol} -> PortProtocol
protocol) (\s :: PortMapping
s@PortMapping' {} PortProtocol
a -> PortMapping
s {$sel:protocol:PortMapping' :: PortProtocol
protocol = PortProtocol
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 ->
          Natural -> PortProtocol -> PortMapping
PortMapping'
            (Natural -> PortProtocol -> PortMapping)
-> Parser Natural -> Parser (PortProtocol -> PortMapping)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"port")
            Parser (PortProtocol -> PortMapping)
-> Parser PortProtocol -> Parser PortMapping
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PortProtocol
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"protocol")
      )

instance Prelude.Hashable PortMapping

instance Prelude.NFData PortMapping

instance Core.ToJSON PortMapping where
  toJSON :: PortMapping -> Value
toJSON PortMapping' {Natural
PortProtocol
protocol :: PortProtocol
port :: Natural
$sel:protocol:PortMapping' :: PortMapping -> PortProtocol
$sel:port:PortMapping' :: PortMapping -> Natural
..} =
    [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
"port" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
port),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"protocol" Text -> PortProtocol -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PortProtocol
protocol)
          ]
      )