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

-- | A complex type for endpoints. A resource must be valid and active when
-- you add it as an endpoint.
--
-- /See:/ 'newEndpointConfiguration' smart constructor.
data EndpointConfiguration = EndpointConfiguration'
  { -- | Indicates whether client IP address preservation is enabled for an
    -- endpoint. The value is true or false. The default value is true for new
    -- accelerators.
    --
    -- If the value is set to true, the client\'s IP address is preserved in
    -- the @X-Forwarded-For@ request header as traffic travels to applications
    -- on the endpoint fronted by the accelerator.
    --
    -- Client IP address preservation is supported, in specific Amazon Web
    -- Services Regions, for endpoints that are Application Load Balancers and
    -- Amazon EC2 instances.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/global-accelerator/latest/dg/preserve-client-ip-address.html Preserve client IP addresses in Global Accelerator>
    -- in the /Global Accelerator Developer Guide/.
    EndpointConfiguration -> Maybe Bool
clientIPPreservationEnabled :: Prelude.Maybe Prelude.Bool,
    -- | An ID for the endpoint. If the endpoint is a Network Load Balancer or
    -- Application Load Balancer, this is the Amazon Resource Name (ARN) of the
    -- resource. If the endpoint is an Elastic IP address, this is the Elastic
    -- IP address allocation ID. For Amazon EC2 instances, this is the EC2
    -- instance ID. A resource must be valid and active when you add it as an
    -- endpoint.
    --
    -- An Application Load Balancer can be either internal or internet-facing.
    EndpointConfiguration -> Maybe Text
endpointId :: Prelude.Maybe Prelude.Text,
    -- | The weight associated with the endpoint. When you add weights to
    -- endpoints, you configure Global Accelerator to route traffic based on
    -- proportions that you specify. For example, you might specify endpoint
    -- weights of 4, 5, 5, and 6 (sum=20). The result is that 4\/20 of your
    -- traffic, on average, is routed to the first endpoint, 5\/20 is routed
    -- both to the second and third endpoints, and 6\/20 is routed to the last
    -- endpoint. For more information, see
    -- <https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoints-endpoint-weights.html Endpoint weights>
    -- in the /Global Accelerator Developer Guide/.
    EndpointConfiguration -> Maybe Natural
weight :: Prelude.Maybe Prelude.Natural
  }
  deriving (EndpointConfiguration -> EndpointConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EndpointConfiguration -> EndpointConfiguration -> Bool
$c/= :: EndpointConfiguration -> EndpointConfiguration -> Bool
== :: EndpointConfiguration -> EndpointConfiguration -> Bool
$c== :: EndpointConfiguration -> EndpointConfiguration -> Bool
Prelude.Eq, ReadPrec [EndpointConfiguration]
ReadPrec EndpointConfiguration
Int -> ReadS EndpointConfiguration
ReadS [EndpointConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EndpointConfiguration]
$creadListPrec :: ReadPrec [EndpointConfiguration]
readPrec :: ReadPrec EndpointConfiguration
$creadPrec :: ReadPrec EndpointConfiguration
readList :: ReadS [EndpointConfiguration]
$creadList :: ReadS [EndpointConfiguration]
readsPrec :: Int -> ReadS EndpointConfiguration
$creadsPrec :: Int -> ReadS EndpointConfiguration
Prelude.Read, Int -> EndpointConfiguration -> ShowS
[EndpointConfiguration] -> ShowS
EndpointConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EndpointConfiguration] -> ShowS
$cshowList :: [EndpointConfiguration] -> ShowS
show :: EndpointConfiguration -> String
$cshow :: EndpointConfiguration -> String
showsPrec :: Int -> EndpointConfiguration -> ShowS
$cshowsPrec :: Int -> EndpointConfiguration -> ShowS
Prelude.Show, forall x. Rep EndpointConfiguration x -> EndpointConfiguration
forall x. EndpointConfiguration -> Rep EndpointConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EndpointConfiguration x -> EndpointConfiguration
$cfrom :: forall x. EndpointConfiguration -> Rep EndpointConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'EndpointConfiguration' 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:
--
-- 'clientIPPreservationEnabled', 'endpointConfiguration_clientIPPreservationEnabled' - Indicates whether client IP address preservation is enabled for an
-- endpoint. The value is true or false. The default value is true for new
-- accelerators.
--
-- If the value is set to true, the client\'s IP address is preserved in
-- the @X-Forwarded-For@ request header as traffic travels to applications
-- on the endpoint fronted by the accelerator.
--
-- Client IP address preservation is supported, in specific Amazon Web
-- Services Regions, for endpoints that are Application Load Balancers and
-- Amazon EC2 instances.
--
-- For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/preserve-client-ip-address.html Preserve client IP addresses in Global Accelerator>
-- in the /Global Accelerator Developer Guide/.
--
-- 'endpointId', 'endpointConfiguration_endpointId' - An ID for the endpoint. If the endpoint is a Network Load Balancer or
-- Application Load Balancer, this is the Amazon Resource Name (ARN) of the
-- resource. If the endpoint is an Elastic IP address, this is the Elastic
-- IP address allocation ID. For Amazon EC2 instances, this is the EC2
-- instance ID. A resource must be valid and active when you add it as an
-- endpoint.
--
-- An Application Load Balancer can be either internal or internet-facing.
--
-- 'weight', 'endpointConfiguration_weight' - The weight associated with the endpoint. When you add weights to
-- endpoints, you configure Global Accelerator to route traffic based on
-- proportions that you specify. For example, you might specify endpoint
-- weights of 4, 5, 5, and 6 (sum=20). The result is that 4\/20 of your
-- traffic, on average, is routed to the first endpoint, 5\/20 is routed
-- both to the second and third endpoints, and 6\/20 is routed to the last
-- endpoint. For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoints-endpoint-weights.html Endpoint weights>
-- in the /Global Accelerator Developer Guide/.
newEndpointConfiguration ::
  EndpointConfiguration
newEndpointConfiguration :: EndpointConfiguration
newEndpointConfiguration =
  EndpointConfiguration'
    { $sel:clientIPPreservationEnabled:EndpointConfiguration' :: Maybe Bool
clientIPPreservationEnabled =
        forall a. Maybe a
Prelude.Nothing,
      $sel:endpointId:EndpointConfiguration' :: Maybe Text
endpointId = forall a. Maybe a
Prelude.Nothing,
      $sel:weight:EndpointConfiguration' :: Maybe Natural
weight = forall a. Maybe a
Prelude.Nothing
    }

-- | Indicates whether client IP address preservation is enabled for an
-- endpoint. The value is true or false. The default value is true for new
-- accelerators.
--
-- If the value is set to true, the client\'s IP address is preserved in
-- the @X-Forwarded-For@ request header as traffic travels to applications
-- on the endpoint fronted by the accelerator.
--
-- Client IP address preservation is supported, in specific Amazon Web
-- Services Regions, for endpoints that are Application Load Balancers and
-- Amazon EC2 instances.
--
-- For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/preserve-client-ip-address.html Preserve client IP addresses in Global Accelerator>
-- in the /Global Accelerator Developer Guide/.
endpointConfiguration_clientIPPreservationEnabled :: Lens.Lens' EndpointConfiguration (Prelude.Maybe Prelude.Bool)
endpointConfiguration_clientIPPreservationEnabled :: Lens' EndpointConfiguration (Maybe Bool)
endpointConfiguration_clientIPPreservationEnabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointConfiguration' {Maybe Bool
clientIPPreservationEnabled :: Maybe Bool
$sel:clientIPPreservationEnabled:EndpointConfiguration' :: EndpointConfiguration -> Maybe Bool
clientIPPreservationEnabled} -> Maybe Bool
clientIPPreservationEnabled) (\s :: EndpointConfiguration
s@EndpointConfiguration' {} Maybe Bool
a -> EndpointConfiguration
s {$sel:clientIPPreservationEnabled:EndpointConfiguration' :: Maybe Bool
clientIPPreservationEnabled = Maybe Bool
a} :: EndpointConfiguration)

-- | An ID for the endpoint. If the endpoint is a Network Load Balancer or
-- Application Load Balancer, this is the Amazon Resource Name (ARN) of the
-- resource. If the endpoint is an Elastic IP address, this is the Elastic
-- IP address allocation ID. For Amazon EC2 instances, this is the EC2
-- instance ID. A resource must be valid and active when you add it as an
-- endpoint.
--
-- An Application Load Balancer can be either internal or internet-facing.
endpointConfiguration_endpointId :: Lens.Lens' EndpointConfiguration (Prelude.Maybe Prelude.Text)
endpointConfiguration_endpointId :: Lens' EndpointConfiguration (Maybe Text)
endpointConfiguration_endpointId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointConfiguration' {Maybe Text
endpointId :: Maybe Text
$sel:endpointId:EndpointConfiguration' :: EndpointConfiguration -> Maybe Text
endpointId} -> Maybe Text
endpointId) (\s :: EndpointConfiguration
s@EndpointConfiguration' {} Maybe Text
a -> EndpointConfiguration
s {$sel:endpointId:EndpointConfiguration' :: Maybe Text
endpointId = Maybe Text
a} :: EndpointConfiguration)

-- | The weight associated with the endpoint. When you add weights to
-- endpoints, you configure Global Accelerator to route traffic based on
-- proportions that you specify. For example, you might specify endpoint
-- weights of 4, 5, 5, and 6 (sum=20). The result is that 4\/20 of your
-- traffic, on average, is routed to the first endpoint, 5\/20 is routed
-- both to the second and third endpoints, and 6\/20 is routed to the last
-- endpoint. For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoints-endpoint-weights.html Endpoint weights>
-- in the /Global Accelerator Developer Guide/.
endpointConfiguration_weight :: Lens.Lens' EndpointConfiguration (Prelude.Maybe Prelude.Natural)
endpointConfiguration_weight :: Lens' EndpointConfiguration (Maybe Natural)
endpointConfiguration_weight = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointConfiguration' {Maybe Natural
weight :: Maybe Natural
$sel:weight:EndpointConfiguration' :: EndpointConfiguration -> Maybe Natural
weight} -> Maybe Natural
weight) (\s :: EndpointConfiguration
s@EndpointConfiguration' {} Maybe Natural
a -> EndpointConfiguration
s {$sel:weight:EndpointConfiguration' :: Maybe Natural
weight = Maybe Natural
a} :: EndpointConfiguration)

instance Prelude.Hashable EndpointConfiguration where
  hashWithSalt :: Int -> EndpointConfiguration -> Int
hashWithSalt Int
_salt EndpointConfiguration' {Maybe Bool
Maybe Natural
Maybe Text
weight :: Maybe Natural
endpointId :: Maybe Text
clientIPPreservationEnabled :: Maybe Bool
$sel:weight:EndpointConfiguration' :: EndpointConfiguration -> Maybe Natural
$sel:endpointId:EndpointConfiguration' :: EndpointConfiguration -> Maybe Text
$sel:clientIPPreservationEnabled:EndpointConfiguration' :: EndpointConfiguration -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
clientIPPreservationEnabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
endpointId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
weight

instance Prelude.NFData EndpointConfiguration where
  rnf :: EndpointConfiguration -> ()
rnf EndpointConfiguration' {Maybe Bool
Maybe Natural
Maybe Text
weight :: Maybe Natural
endpointId :: Maybe Text
clientIPPreservationEnabled :: Maybe Bool
$sel:weight:EndpointConfiguration' :: EndpointConfiguration -> Maybe Natural
$sel:endpointId:EndpointConfiguration' :: EndpointConfiguration -> Maybe Text
$sel:clientIPPreservationEnabled:EndpointConfiguration' :: EndpointConfiguration -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
clientIPPreservationEnabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
endpointId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
weight

instance Data.ToJSON EndpointConfiguration where
  toJSON :: EndpointConfiguration -> Value
toJSON EndpointConfiguration' {Maybe Bool
Maybe Natural
Maybe Text
weight :: Maybe Natural
endpointId :: Maybe Text
clientIPPreservationEnabled :: Maybe Bool
$sel:weight:EndpointConfiguration' :: EndpointConfiguration -> Maybe Natural
$sel:endpointId:EndpointConfiguration' :: EndpointConfiguration -> Maybe Text
$sel:clientIPPreservationEnabled:EndpointConfiguration' :: EndpointConfiguration -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ClientIPPreservationEnabled" 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
clientIPPreservationEnabled,
            (Key
"EndpointId" 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 Text
endpointId,
            (Key
"Weight" 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 Natural
weight
          ]
      )