{-# 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.SocketAddress
-- 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.SocketAddress 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 IP address\/port combination.
--
-- /See:/ 'newSocketAddress' smart constructor.
data SocketAddress = SocketAddress'
  { -- | The IP address for the socket address.
    SocketAddress -> Maybe Text
ipAddress :: Prelude.Maybe Prelude.Text,
    -- | The port for the socket address.
    SocketAddress -> Maybe Natural
port :: Prelude.Maybe Prelude.Natural
  }
  deriving (SocketAddress -> SocketAddress -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SocketAddress -> SocketAddress -> Bool
$c/= :: SocketAddress -> SocketAddress -> Bool
== :: SocketAddress -> SocketAddress -> Bool
$c== :: SocketAddress -> SocketAddress -> Bool
Prelude.Eq, ReadPrec [SocketAddress]
ReadPrec SocketAddress
Int -> ReadS SocketAddress
ReadS [SocketAddress]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SocketAddress]
$creadListPrec :: ReadPrec [SocketAddress]
readPrec :: ReadPrec SocketAddress
$creadPrec :: ReadPrec SocketAddress
readList :: ReadS [SocketAddress]
$creadList :: ReadS [SocketAddress]
readsPrec :: Int -> ReadS SocketAddress
$creadsPrec :: Int -> ReadS SocketAddress
Prelude.Read, Int -> SocketAddress -> ShowS
[SocketAddress] -> ShowS
SocketAddress -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SocketAddress] -> ShowS
$cshowList :: [SocketAddress] -> ShowS
show :: SocketAddress -> String
$cshow :: SocketAddress -> String
showsPrec :: Int -> SocketAddress -> ShowS
$cshowsPrec :: Int -> SocketAddress -> ShowS
Prelude.Show, forall x. Rep SocketAddress x -> SocketAddress
forall x. SocketAddress -> Rep SocketAddress x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SocketAddress x -> SocketAddress
$cfrom :: forall x. SocketAddress -> Rep SocketAddress x
Prelude.Generic)

-- |
-- Create a value of 'SocketAddress' 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:
--
-- 'ipAddress', 'socketAddress_ipAddress' - The IP address for the socket address.
--
-- 'port', 'socketAddress_port' - The port for the socket address.
newSocketAddress ::
  SocketAddress
newSocketAddress :: SocketAddress
newSocketAddress =
  SocketAddress'
    { $sel:ipAddress:SocketAddress' :: Maybe Text
ipAddress = forall a. Maybe a
Prelude.Nothing,
      $sel:port:SocketAddress' :: Maybe Natural
port = forall a. Maybe a
Prelude.Nothing
    }

-- | The IP address for the socket address.
socketAddress_ipAddress :: Lens.Lens' SocketAddress (Prelude.Maybe Prelude.Text)
socketAddress_ipAddress :: Lens' SocketAddress (Maybe Text)
socketAddress_ipAddress = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SocketAddress' {Maybe Text
ipAddress :: Maybe Text
$sel:ipAddress:SocketAddress' :: SocketAddress -> Maybe Text
ipAddress} -> Maybe Text
ipAddress) (\s :: SocketAddress
s@SocketAddress' {} Maybe Text
a -> SocketAddress
s {$sel:ipAddress:SocketAddress' :: Maybe Text
ipAddress = Maybe Text
a} :: SocketAddress)

-- | The port for the socket address.
socketAddress_port :: Lens.Lens' SocketAddress (Prelude.Maybe Prelude.Natural)
socketAddress_port :: Lens' SocketAddress (Maybe Natural)
socketAddress_port = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SocketAddress' {Maybe Natural
port :: Maybe Natural
$sel:port:SocketAddress' :: SocketAddress -> Maybe Natural
port} -> Maybe Natural
port) (\s :: SocketAddress
s@SocketAddress' {} Maybe Natural
a -> SocketAddress
s {$sel:port:SocketAddress' :: Maybe Natural
port = Maybe Natural
a} :: SocketAddress)

instance Data.FromJSON SocketAddress where
  parseJSON :: Value -> Parser SocketAddress
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SocketAddress"
      ( \Object
x ->
          Maybe Text -> Maybe Natural -> SocketAddress
SocketAddress'
            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
"IpAddress")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Port")
      )

instance Prelude.Hashable SocketAddress where
  hashWithSalt :: Int -> SocketAddress -> Int
hashWithSalt Int
_salt SocketAddress' {Maybe Natural
Maybe Text
port :: Maybe Natural
ipAddress :: Maybe Text
$sel:port:SocketAddress' :: SocketAddress -> Maybe Natural
$sel:ipAddress:SocketAddress' :: SocketAddress -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
ipAddress
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
port

instance Prelude.NFData SocketAddress where
  rnf :: SocketAddress -> ()
rnf SocketAddress' {Maybe Natural
Maybe Text
port :: Maybe Natural
ipAddress :: Maybe Text
$sel:port:SocketAddress' :: SocketAddress -> Maybe Natural
$sel:ipAddress:SocketAddress' :: SocketAddress -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
ipAddress
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
port