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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 identity the target application. The AWS
    -- 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 AWS 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
(DestinationConfig -> DestinationConfig -> Bool)
-> (DestinationConfig -> DestinationConfig -> Bool)
-> Eq DestinationConfig
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]
(Int -> ReadS DestinationConfig)
-> ReadS [DestinationConfig]
-> ReadPrec DestinationConfig
-> ReadPrec [DestinationConfig]
-> Read 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
(Int -> DestinationConfig -> ShowS)
-> (DestinationConfig -> String)
-> ([DestinationConfig] -> ShowS)
-> Show DestinationConfig
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. DestinationConfig -> Rep DestinationConfig x)
-> (forall x. Rep DestinationConfig x -> DestinationConfig)
-> Generic DestinationConfig
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 identity the target application. The AWS
-- 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 AWS 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' :: Maybe Text -> NonEmpty Text -> DestinationConfig
DestinationConfig'
    { $sel:thingName:DestinationConfig' :: Maybe Text
thingName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:services:DestinationConfig' :: NonEmpty Text
services = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
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 :: (Maybe Text -> f (Maybe Text))
-> DestinationConfig -> f DestinationConfig
destinationConfig_thingName = (DestinationConfig -> Maybe Text)
-> (DestinationConfig -> Maybe Text -> DestinationConfig)
-> Lens
     DestinationConfig DestinationConfig (Maybe Text) (Maybe Text)
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 identity the target application. The AWS
-- 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 AWS 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 :: (NonEmpty Text -> f (NonEmpty Text))
-> DestinationConfig -> f DestinationConfig
destinationConfig_services = (DestinationConfig -> NonEmpty Text)
-> (DestinationConfig -> NonEmpty Text -> DestinationConfig)
-> Lens
     DestinationConfig DestinationConfig (NonEmpty Text) (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text))
 -> DestinationConfig -> f DestinationConfig)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> DestinationConfig
-> f DestinationConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable DestinationConfig

instance Prelude.NFData DestinationConfig

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"thingName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
thingName,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"services" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
services)
          ]
      )