{-# 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.GroundStation.Types.SocketAddress
-- 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.GroundStation.Types.SocketAddress where

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

-- | Information about the socket address.
--
-- /See:/ 'newSocketAddress' smart constructor.
data SocketAddress = SocketAddress'
  { -- | Name of a socket address.
    SocketAddress -> Text
name :: Prelude.Text,
    -- | Port of a socket address.
    SocketAddress -> Int
port :: Prelude.Int
  }
  deriving (SocketAddress -> SocketAddress -> Bool
(SocketAddress -> SocketAddress -> Bool)
-> (SocketAddress -> SocketAddress -> Bool) -> Eq SocketAddress
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]
(Int -> ReadS SocketAddress)
-> ReadS [SocketAddress]
-> ReadPrec SocketAddress
-> ReadPrec [SocketAddress]
-> Read 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
(Int -> SocketAddress -> ShowS)
-> (SocketAddress -> String)
-> ([SocketAddress] -> ShowS)
-> Show SocketAddress
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. SocketAddress -> Rep SocketAddress x)
-> (forall x. Rep SocketAddress x -> SocketAddress)
-> Generic SocketAddress
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:
--
-- 'name', 'socketAddress_name' - Name of a socket address.
--
-- 'port', 'socketAddress_port' - Port of a socket address.
newSocketAddress ::
  -- | 'name'
  Prelude.Text ->
  -- | 'port'
  Prelude.Int ->
  SocketAddress
newSocketAddress :: Text -> Int -> SocketAddress
newSocketAddress Text
pName_ Int
pPort_ =
  SocketAddress' :: Text -> Int -> SocketAddress
SocketAddress' {$sel:name:SocketAddress' :: Text
name = Text
pName_, $sel:port:SocketAddress' :: Int
port = Int
pPort_}

-- | Name of a socket address.
socketAddress_name :: Lens.Lens' SocketAddress Prelude.Text
socketAddress_name :: (Text -> f Text) -> SocketAddress -> f SocketAddress
socketAddress_name = (SocketAddress -> Text)
-> (SocketAddress -> Text -> SocketAddress)
-> Lens SocketAddress SocketAddress Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SocketAddress' {Text
name :: Text
$sel:name:SocketAddress' :: SocketAddress -> Text
name} -> Text
name) (\s :: SocketAddress
s@SocketAddress' {} Text
a -> SocketAddress
s {$sel:name:SocketAddress' :: Text
name = Text
a} :: SocketAddress)

-- | Port of a socket address.
socketAddress_port :: Lens.Lens' SocketAddress Prelude.Int
socketAddress_port :: (Int -> f Int) -> SocketAddress -> f SocketAddress
socketAddress_port = (SocketAddress -> Int)
-> (SocketAddress -> Int -> SocketAddress)
-> Lens SocketAddress SocketAddress Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SocketAddress' {Int
port :: Int
$sel:port:SocketAddress' :: SocketAddress -> Int
port} -> Int
port) (\s :: SocketAddress
s@SocketAddress' {} Int
a -> SocketAddress
s {$sel:port:SocketAddress' :: Int
port = Int
a} :: SocketAddress)

instance Core.FromJSON SocketAddress where
  parseJSON :: Value -> Parser SocketAddress
parseJSON =
    String
-> (Object -> Parser SocketAddress)
-> Value
-> Parser SocketAddress
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SocketAddress"
      ( \Object
x ->
          Text -> Int -> SocketAddress
SocketAddress'
            (Text -> Int -> SocketAddress)
-> Parser Text -> Parser (Int -> SocketAddress)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name") Parser (Int -> SocketAddress) -> Parser Int -> Parser SocketAddress
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"port")
      )

instance Prelude.Hashable SocketAddress

instance Prelude.NFData SocketAddress

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