{-# 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.IoTSecureTunneling.Types.DestinationConfig
-- 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.IoTSecureTunneling.Types.DestinationConfig 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

-- | The destination configuration.
--
-- /See:/ 'newDestinationConfig' smart constructor.
data DestinationConfig = DestinationConfig'
  { -- | The name of the IoT thing to which you want to connect.
    DestinationConfig -> Maybe Text
thingName :: Prelude.Maybe Prelude.Text,
    -- | A list of service names that identify the target application. The IoT
    -- client running on the destination device reads this value and uses it to
    -- look up a port or an IP address and a port. The IoT client instantiates
    -- the local proxy, which uses this information to connect to the
    -- destination application.
    DestinationConfig -> NonEmpty Text
services :: Prelude.NonEmpty Prelude.Text
  }
  deriving (DestinationConfig -> DestinationConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DestinationConfig -> DestinationConfig -> Bool
$c/= :: DestinationConfig -> DestinationConfig -> Bool
== :: DestinationConfig -> DestinationConfig -> Bool
$c== :: DestinationConfig -> DestinationConfig -> Bool
Prelude.Eq, ReadPrec [DestinationConfig]
ReadPrec DestinationConfig
Int -> ReadS DestinationConfig
ReadS [DestinationConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DestinationConfig]
$creadListPrec :: ReadPrec [DestinationConfig]
readPrec :: ReadPrec DestinationConfig
$creadPrec :: ReadPrec DestinationConfig
readList :: ReadS [DestinationConfig]
$creadList :: ReadS [DestinationConfig]
readsPrec :: Int -> ReadS DestinationConfig
$creadsPrec :: Int -> ReadS DestinationConfig
Prelude.Read, Int -> DestinationConfig -> ShowS
[DestinationConfig] -> ShowS
DestinationConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DestinationConfig] -> ShowS
$cshowList :: [DestinationConfig] -> ShowS
show :: DestinationConfig -> String
$cshow :: DestinationConfig -> String
showsPrec :: Int -> DestinationConfig -> ShowS
$cshowsPrec :: Int -> DestinationConfig -> ShowS
Prelude.Show, forall x. Rep DestinationConfig x -> DestinationConfig
forall x. DestinationConfig -> Rep DestinationConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DestinationConfig x -> DestinationConfig
$cfrom :: forall x. DestinationConfig -> Rep DestinationConfig x
Prelude.Generic)

-- |
-- Create a value of 'DestinationConfig' 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:
--
-- 'thingName', 'destinationConfig_thingName' - The name of the IoT thing to which you want to connect.
--
-- 'services', 'destinationConfig_services' - A list of service names that identify the target application. The IoT
-- client running on the destination device reads this value and uses it to
-- look up a port or an IP address and a port. The IoT client instantiates
-- the local proxy, which uses this information to connect to the
-- destination application.
newDestinationConfig ::
  -- | 'services'
  Prelude.NonEmpty Prelude.Text ->
  DestinationConfig
newDestinationConfig :: NonEmpty Text -> DestinationConfig
newDestinationConfig NonEmpty Text
pServices_ =
  DestinationConfig'
    { $sel:thingName:DestinationConfig' :: Maybe Text
thingName = forall a. Maybe a
Prelude.Nothing,
      $sel:services:DestinationConfig' :: NonEmpty Text
services = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pServices_
    }

-- | The name of the IoT thing to which you want to connect.
destinationConfig_thingName :: Lens.Lens' DestinationConfig (Prelude.Maybe Prelude.Text)
destinationConfig_thingName :: Lens' DestinationConfig (Maybe Text)
destinationConfig_thingName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DestinationConfig' {Maybe Text
thingName :: Maybe Text
$sel:thingName:DestinationConfig' :: DestinationConfig -> Maybe Text
thingName} -> Maybe Text
thingName) (\s :: DestinationConfig
s@DestinationConfig' {} Maybe Text
a -> DestinationConfig
s {$sel:thingName:DestinationConfig' :: Maybe Text
thingName = Maybe Text
a} :: DestinationConfig)

-- | A list of service names that identify the target application. The IoT
-- client running on the destination device reads this value and uses it to
-- look up a port or an IP address and a port. The IoT client instantiates
-- the local proxy, which uses this information to connect to the
-- destination application.
destinationConfig_services :: Lens.Lens' DestinationConfig (Prelude.NonEmpty Prelude.Text)
destinationConfig_services :: Lens' DestinationConfig (NonEmpty Text)
destinationConfig_services = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DestinationConfig' {NonEmpty Text
services :: NonEmpty Text
$sel:services:DestinationConfig' :: DestinationConfig -> NonEmpty Text
services} -> NonEmpty Text
services) (\s :: DestinationConfig
s@DestinationConfig' {} NonEmpty Text
a -> DestinationConfig
s {$sel:services:DestinationConfig' :: NonEmpty Text
services = NonEmpty Text
a} :: DestinationConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable DestinationConfig where
  hashWithSalt :: Int -> DestinationConfig -> Int
hashWithSalt Int
_salt DestinationConfig' {Maybe Text
NonEmpty Text
services :: NonEmpty Text
thingName :: Maybe Text
$sel:services:DestinationConfig' :: DestinationConfig -> NonEmpty Text
$sel:thingName:DestinationConfig' :: DestinationConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
thingName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
services

instance Prelude.NFData DestinationConfig where
  rnf :: DestinationConfig -> ()
rnf DestinationConfig' {Maybe Text
NonEmpty Text
services :: NonEmpty Text
thingName :: Maybe Text
$sel:services:DestinationConfig' :: DestinationConfig -> NonEmpty Text
$sel:thingName:DestinationConfig' :: DestinationConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
thingName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
services

instance Data.ToJSON DestinationConfig where
  toJSON :: DestinationConfig -> Value
toJSON DestinationConfig' {Maybe Text
NonEmpty Text
services :: NonEmpty Text
thingName :: Maybe Text
$sel:services:DestinationConfig' :: DestinationConfig -> NonEmpty Text
$sel:thingName:DestinationConfig' :: DestinationConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"thingName" 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
thingName,
            forall a. a -> Maybe a
Prelude.Just (Key
"services" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
services)
          ]
      )