{-# 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.GlobalAccelerator.Types.PortOverride
-- 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.GlobalAccelerator.Types.PortOverride where

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

-- | Override specific listener ports used to route traffic to endpoints that
-- are part of an endpoint group. For example, you can create a port
-- override in which the listener receives user traffic on ports 80 and
-- 443, but your accelerator routes that traffic to ports 1080 and 1443,
-- respectively, on the endpoints.
--
-- For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoint-groups-port-override.html Port overrides>
-- in the /AWS Global Accelerator Developer Guide/.
--
-- /See:/ 'newPortOverride' smart constructor.
data PortOverride = PortOverride'
  { -- | The endpoint port that you want a listener port to be mapped to. This is
    -- the port on the endpoint, such as the Application Load Balancer or
    -- Amazon EC2 instance.
    PortOverride -> Maybe Natural
endpointPort :: Prelude.Maybe Prelude.Natural,
    -- | The listener port that you want to map to a specific endpoint port. This
    -- is the port that user traffic arrives to the Global Accelerator on.
    PortOverride -> Maybe Natural
listenerPort :: Prelude.Maybe Prelude.Natural
  }
  deriving (PortOverride -> PortOverride -> Bool
(PortOverride -> PortOverride -> Bool)
-> (PortOverride -> PortOverride -> Bool) -> Eq PortOverride
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortOverride -> PortOverride -> Bool
$c/= :: PortOverride -> PortOverride -> Bool
== :: PortOverride -> PortOverride -> Bool
$c== :: PortOverride -> PortOverride -> Bool
Prelude.Eq, ReadPrec [PortOverride]
ReadPrec PortOverride
Int -> ReadS PortOverride
ReadS [PortOverride]
(Int -> ReadS PortOverride)
-> ReadS [PortOverride]
-> ReadPrec PortOverride
-> ReadPrec [PortOverride]
-> Read PortOverride
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortOverride]
$creadListPrec :: ReadPrec [PortOverride]
readPrec :: ReadPrec PortOverride
$creadPrec :: ReadPrec PortOverride
readList :: ReadS [PortOverride]
$creadList :: ReadS [PortOverride]
readsPrec :: Int -> ReadS PortOverride
$creadsPrec :: Int -> ReadS PortOverride
Prelude.Read, Int -> PortOverride -> ShowS
[PortOverride] -> ShowS
PortOverride -> String
(Int -> PortOverride -> ShowS)
-> (PortOverride -> String)
-> ([PortOverride] -> ShowS)
-> Show PortOverride
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortOverride] -> ShowS
$cshowList :: [PortOverride] -> ShowS
show :: PortOverride -> String
$cshow :: PortOverride -> String
showsPrec :: Int -> PortOverride -> ShowS
$cshowsPrec :: Int -> PortOverride -> ShowS
Prelude.Show, (forall x. PortOverride -> Rep PortOverride x)
-> (forall x. Rep PortOverride x -> PortOverride)
-> Generic PortOverride
forall x. Rep PortOverride x -> PortOverride
forall x. PortOverride -> Rep PortOverride x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortOverride x -> PortOverride
$cfrom :: forall x. PortOverride -> Rep PortOverride x
Prelude.Generic)

-- |
-- Create a value of 'PortOverride' 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:
--
-- 'endpointPort', 'portOverride_endpointPort' - The endpoint port that you want a listener port to be mapped to. This is
-- the port on the endpoint, such as the Application Load Balancer or
-- Amazon EC2 instance.
--
-- 'listenerPort', 'portOverride_listenerPort' - The listener port that you want to map to a specific endpoint port. This
-- is the port that user traffic arrives to the Global Accelerator on.
newPortOverride ::
  PortOverride
newPortOverride :: PortOverride
newPortOverride =
  PortOverride' :: Maybe Natural -> Maybe Natural -> PortOverride
PortOverride'
    { $sel:endpointPort:PortOverride' :: Maybe Natural
endpointPort = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:listenerPort:PortOverride' :: Maybe Natural
listenerPort = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The endpoint port that you want a listener port to be mapped to. This is
-- the port on the endpoint, such as the Application Load Balancer or
-- Amazon EC2 instance.
portOverride_endpointPort :: Lens.Lens' PortOverride (Prelude.Maybe Prelude.Natural)
portOverride_endpointPort :: (Maybe Natural -> f (Maybe Natural))
-> PortOverride -> f PortOverride
portOverride_endpointPort = (PortOverride -> Maybe Natural)
-> (PortOverride -> Maybe Natural -> PortOverride)
-> Lens PortOverride PortOverride (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortOverride' {Maybe Natural
endpointPort :: Maybe Natural
$sel:endpointPort:PortOverride' :: PortOverride -> Maybe Natural
endpointPort} -> Maybe Natural
endpointPort) (\s :: PortOverride
s@PortOverride' {} Maybe Natural
a -> PortOverride
s {$sel:endpointPort:PortOverride' :: Maybe Natural
endpointPort = Maybe Natural
a} :: PortOverride)

-- | The listener port that you want to map to a specific endpoint port. This
-- is the port that user traffic arrives to the Global Accelerator on.
portOverride_listenerPort :: Lens.Lens' PortOverride (Prelude.Maybe Prelude.Natural)
portOverride_listenerPort :: (Maybe Natural -> f (Maybe Natural))
-> PortOverride -> f PortOverride
portOverride_listenerPort = (PortOverride -> Maybe Natural)
-> (PortOverride -> Maybe Natural -> PortOverride)
-> Lens PortOverride PortOverride (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortOverride' {Maybe Natural
listenerPort :: Maybe Natural
$sel:listenerPort:PortOverride' :: PortOverride -> Maybe Natural
listenerPort} -> Maybe Natural
listenerPort) (\s :: PortOverride
s@PortOverride' {} Maybe Natural
a -> PortOverride
s {$sel:listenerPort:PortOverride' :: Maybe Natural
listenerPort = Maybe Natural
a} :: PortOverride)

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

instance Prelude.Hashable PortOverride

instance Prelude.NFData PortOverride

instance Core.ToJSON PortOverride where
  toJSON :: PortOverride -> Value
toJSON PortOverride' {Maybe Natural
listenerPort :: Maybe Natural
endpointPort :: Maybe Natural
$sel:listenerPort:PortOverride' :: PortOverride -> Maybe Natural
$sel:endpointPort:PortOverride' :: PortOverride -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EndpointPort" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
endpointPort,
            (Text
"ListenerPort" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
listenerPort
          ]
      )