{-# 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.ServiceCatalog.Types.SourceConnection
-- 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.ServiceCatalog.Types.SourceConnection 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
import Amazonka.ServiceCatalog.Types.SourceConnectionParameters
import Amazonka.ServiceCatalog.Types.SourceType

-- | A top level @ProductViewDetail@ response containing details about the
-- product’s connection. Service Catalog returns this field for the
-- @CreateProduct@, @UpdateProduct@, @DescribeProductAsAdmin@, and
-- @SearchProductAsAdmin@ APIs. This response contains the same fields as
-- the @ConnectionParameters@ request, with the addition of the @LastSync@
-- response.
--
-- /See:/ 'newSourceConnection' smart constructor.
data SourceConnection = SourceConnection'
  { -- | The only supported @SourceConnection@ type is Codestar.
    SourceConnection -> Maybe SourceType
type' :: Prelude.Maybe SourceType,
    -- | The connection details based on the connection @Type@.
    SourceConnection -> SourceConnectionParameters
connectionParameters :: SourceConnectionParameters
  }
  deriving (SourceConnection -> SourceConnection -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceConnection -> SourceConnection -> Bool
$c/= :: SourceConnection -> SourceConnection -> Bool
== :: SourceConnection -> SourceConnection -> Bool
$c== :: SourceConnection -> SourceConnection -> Bool
Prelude.Eq, ReadPrec [SourceConnection]
ReadPrec SourceConnection
Int -> ReadS SourceConnection
ReadS [SourceConnection]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SourceConnection]
$creadListPrec :: ReadPrec [SourceConnection]
readPrec :: ReadPrec SourceConnection
$creadPrec :: ReadPrec SourceConnection
readList :: ReadS [SourceConnection]
$creadList :: ReadS [SourceConnection]
readsPrec :: Int -> ReadS SourceConnection
$creadsPrec :: Int -> ReadS SourceConnection
Prelude.Read, Int -> SourceConnection -> ShowS
[SourceConnection] -> ShowS
SourceConnection -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceConnection] -> ShowS
$cshowList :: [SourceConnection] -> ShowS
show :: SourceConnection -> String
$cshow :: SourceConnection -> String
showsPrec :: Int -> SourceConnection -> ShowS
$cshowsPrec :: Int -> SourceConnection -> ShowS
Prelude.Show, forall x. Rep SourceConnection x -> SourceConnection
forall x. SourceConnection -> Rep SourceConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceConnection x -> SourceConnection
$cfrom :: forall x. SourceConnection -> Rep SourceConnection x
Prelude.Generic)

-- |
-- Create a value of 'SourceConnection' 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:
--
-- 'type'', 'sourceConnection_type' - The only supported @SourceConnection@ type is Codestar.
--
-- 'connectionParameters', 'sourceConnection_connectionParameters' - The connection details based on the connection @Type@.
newSourceConnection ::
  -- | 'connectionParameters'
  SourceConnectionParameters ->
  SourceConnection
newSourceConnection :: SourceConnectionParameters -> SourceConnection
newSourceConnection SourceConnectionParameters
pConnectionParameters_ =
  SourceConnection'
    { $sel:type':SourceConnection' :: Maybe SourceType
type' = forall a. Maybe a
Prelude.Nothing,
      $sel:connectionParameters:SourceConnection' :: SourceConnectionParameters
connectionParameters = SourceConnectionParameters
pConnectionParameters_
    }

-- | The only supported @SourceConnection@ type is Codestar.
sourceConnection_type :: Lens.Lens' SourceConnection (Prelude.Maybe SourceType)
sourceConnection_type :: Lens' SourceConnection (Maybe SourceType)
sourceConnection_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceConnection' {Maybe SourceType
type' :: Maybe SourceType
$sel:type':SourceConnection' :: SourceConnection -> Maybe SourceType
type'} -> Maybe SourceType
type') (\s :: SourceConnection
s@SourceConnection' {} Maybe SourceType
a -> SourceConnection
s {$sel:type':SourceConnection' :: Maybe SourceType
type' = Maybe SourceType
a} :: SourceConnection)

-- | The connection details based on the connection @Type@.
sourceConnection_connectionParameters :: Lens.Lens' SourceConnection SourceConnectionParameters
sourceConnection_connectionParameters :: Lens' SourceConnection SourceConnectionParameters
sourceConnection_connectionParameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceConnection' {SourceConnectionParameters
connectionParameters :: SourceConnectionParameters
$sel:connectionParameters:SourceConnection' :: SourceConnection -> SourceConnectionParameters
connectionParameters} -> SourceConnectionParameters
connectionParameters) (\s :: SourceConnection
s@SourceConnection' {} SourceConnectionParameters
a -> SourceConnection
s {$sel:connectionParameters:SourceConnection' :: SourceConnectionParameters
connectionParameters = SourceConnectionParameters
a} :: SourceConnection)

instance Prelude.Hashable SourceConnection where
  hashWithSalt :: Int -> SourceConnection -> Int
hashWithSalt Int
_salt SourceConnection' {Maybe SourceType
SourceConnectionParameters
connectionParameters :: SourceConnectionParameters
type' :: Maybe SourceType
$sel:connectionParameters:SourceConnection' :: SourceConnection -> SourceConnectionParameters
$sel:type':SourceConnection' :: SourceConnection -> Maybe SourceType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SourceType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SourceConnectionParameters
connectionParameters

instance Prelude.NFData SourceConnection where
  rnf :: SourceConnection -> ()
rnf SourceConnection' {Maybe SourceType
SourceConnectionParameters
connectionParameters :: SourceConnectionParameters
type' :: Maybe SourceType
$sel:connectionParameters:SourceConnection' :: SourceConnection -> SourceConnectionParameters
$sel:type':SourceConnection' :: SourceConnection -> Maybe SourceType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe SourceType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SourceConnectionParameters
connectionParameters

instance Data.ToJSON SourceConnection where
  toJSON :: SourceConnection -> Value
toJSON SourceConnection' {Maybe SourceType
SourceConnectionParameters
connectionParameters :: SourceConnectionParameters
type' :: Maybe SourceType
$sel:connectionParameters:SourceConnection' :: SourceConnection -> SourceConnectionParameters
$sel:type':SourceConnection' :: SourceConnection -> Maybe SourceType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Type" 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 SourceType
type',
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"ConnectionParameters"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SourceConnectionParameters
connectionParameters
              )
          ]
      )