{-# 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.AppSync.Types.HttpDataSourceConfig
-- 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.AppSync.Types.HttpDataSourceConfig where

import Amazonka.AppSync.Types.AuthorizationConfig
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

-- | Describes an HTTP data source configuration.
--
-- /See:/ 'newHttpDataSourceConfig' smart constructor.
data HttpDataSourceConfig = HttpDataSourceConfig'
  { -- | The authorization configuration in case the HTTP endpoint requires
    -- authorization.
    HttpDataSourceConfig -> Maybe AuthorizationConfig
authorizationConfig :: Prelude.Maybe AuthorizationConfig,
    -- | The HTTP URL endpoint. You can specify either the domain name or IP, and
    -- port combination, and the URL scheme must be HTTP or HTTPS. If you
    -- don\'t specify the port, AppSync uses the default port 80 for the HTTP
    -- endpoint and port 443 for HTTPS endpoints.
    HttpDataSourceConfig -> Maybe Text
endpoint :: Prelude.Maybe Prelude.Text
  }
  deriving (HttpDataSourceConfig -> HttpDataSourceConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpDataSourceConfig -> HttpDataSourceConfig -> Bool
$c/= :: HttpDataSourceConfig -> HttpDataSourceConfig -> Bool
== :: HttpDataSourceConfig -> HttpDataSourceConfig -> Bool
$c== :: HttpDataSourceConfig -> HttpDataSourceConfig -> Bool
Prelude.Eq, ReadPrec [HttpDataSourceConfig]
ReadPrec HttpDataSourceConfig
Int -> ReadS HttpDataSourceConfig
ReadS [HttpDataSourceConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpDataSourceConfig]
$creadListPrec :: ReadPrec [HttpDataSourceConfig]
readPrec :: ReadPrec HttpDataSourceConfig
$creadPrec :: ReadPrec HttpDataSourceConfig
readList :: ReadS [HttpDataSourceConfig]
$creadList :: ReadS [HttpDataSourceConfig]
readsPrec :: Int -> ReadS HttpDataSourceConfig
$creadsPrec :: Int -> ReadS HttpDataSourceConfig
Prelude.Read, Int -> HttpDataSourceConfig -> ShowS
[HttpDataSourceConfig] -> ShowS
HttpDataSourceConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpDataSourceConfig] -> ShowS
$cshowList :: [HttpDataSourceConfig] -> ShowS
show :: HttpDataSourceConfig -> String
$cshow :: HttpDataSourceConfig -> String
showsPrec :: Int -> HttpDataSourceConfig -> ShowS
$cshowsPrec :: Int -> HttpDataSourceConfig -> ShowS
Prelude.Show, forall x. Rep HttpDataSourceConfig x -> HttpDataSourceConfig
forall x. HttpDataSourceConfig -> Rep HttpDataSourceConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpDataSourceConfig x -> HttpDataSourceConfig
$cfrom :: forall x. HttpDataSourceConfig -> Rep HttpDataSourceConfig x
Prelude.Generic)

-- |
-- Create a value of 'HttpDataSourceConfig' 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:
--
-- 'authorizationConfig', 'httpDataSourceConfig_authorizationConfig' - The authorization configuration in case the HTTP endpoint requires
-- authorization.
--
-- 'endpoint', 'httpDataSourceConfig_endpoint' - The HTTP URL endpoint. You can specify either the domain name or IP, and
-- port combination, and the URL scheme must be HTTP or HTTPS. If you
-- don\'t specify the port, AppSync uses the default port 80 for the HTTP
-- endpoint and port 443 for HTTPS endpoints.
newHttpDataSourceConfig ::
  HttpDataSourceConfig
newHttpDataSourceConfig :: HttpDataSourceConfig
newHttpDataSourceConfig =
  HttpDataSourceConfig'
    { $sel:authorizationConfig:HttpDataSourceConfig' :: Maybe AuthorizationConfig
authorizationConfig =
        forall a. Maybe a
Prelude.Nothing,
      $sel:endpoint:HttpDataSourceConfig' :: Maybe Text
endpoint = forall a. Maybe a
Prelude.Nothing
    }

-- | The authorization configuration in case the HTTP endpoint requires
-- authorization.
httpDataSourceConfig_authorizationConfig :: Lens.Lens' HttpDataSourceConfig (Prelude.Maybe AuthorizationConfig)
httpDataSourceConfig_authorizationConfig :: Lens' HttpDataSourceConfig (Maybe AuthorizationConfig)
httpDataSourceConfig_authorizationConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpDataSourceConfig' {Maybe AuthorizationConfig
authorizationConfig :: Maybe AuthorizationConfig
$sel:authorizationConfig:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe AuthorizationConfig
authorizationConfig} -> Maybe AuthorizationConfig
authorizationConfig) (\s :: HttpDataSourceConfig
s@HttpDataSourceConfig' {} Maybe AuthorizationConfig
a -> HttpDataSourceConfig
s {$sel:authorizationConfig:HttpDataSourceConfig' :: Maybe AuthorizationConfig
authorizationConfig = Maybe AuthorizationConfig
a} :: HttpDataSourceConfig)

-- | The HTTP URL endpoint. You can specify either the domain name or IP, and
-- port combination, and the URL scheme must be HTTP or HTTPS. If you
-- don\'t specify the port, AppSync uses the default port 80 for the HTTP
-- endpoint and port 443 for HTTPS endpoints.
httpDataSourceConfig_endpoint :: Lens.Lens' HttpDataSourceConfig (Prelude.Maybe Prelude.Text)
httpDataSourceConfig_endpoint :: Lens' HttpDataSourceConfig (Maybe Text)
httpDataSourceConfig_endpoint = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpDataSourceConfig' {Maybe Text
endpoint :: Maybe Text
$sel:endpoint:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe Text
endpoint} -> Maybe Text
endpoint) (\s :: HttpDataSourceConfig
s@HttpDataSourceConfig' {} Maybe Text
a -> HttpDataSourceConfig
s {$sel:endpoint:HttpDataSourceConfig' :: Maybe Text
endpoint = Maybe Text
a} :: HttpDataSourceConfig)

instance Data.FromJSON HttpDataSourceConfig where
  parseJSON :: Value -> Parser HttpDataSourceConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HttpDataSourceConfig"
      ( \Object
x ->
          Maybe AuthorizationConfig -> Maybe Text -> HttpDataSourceConfig
HttpDataSourceConfig'
            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
"authorizationConfig")
            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
"endpoint")
      )

instance Prelude.Hashable HttpDataSourceConfig where
  hashWithSalt :: Int -> HttpDataSourceConfig -> Int
hashWithSalt Int
_salt HttpDataSourceConfig' {Maybe Text
Maybe AuthorizationConfig
endpoint :: Maybe Text
authorizationConfig :: Maybe AuthorizationConfig
$sel:endpoint:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe Text
$sel:authorizationConfig:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe AuthorizationConfig
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AuthorizationConfig
authorizationConfig
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
endpoint

instance Prelude.NFData HttpDataSourceConfig where
  rnf :: HttpDataSourceConfig -> ()
rnf HttpDataSourceConfig' {Maybe Text
Maybe AuthorizationConfig
endpoint :: Maybe Text
authorizationConfig :: Maybe AuthorizationConfig
$sel:endpoint:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe Text
$sel:authorizationConfig:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe AuthorizationConfig
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AuthorizationConfig
authorizationConfig
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
endpoint

instance Data.ToJSON HttpDataSourceConfig where
  toJSON :: HttpDataSourceConfig -> Value
toJSON HttpDataSourceConfig' {Maybe Text
Maybe AuthorizationConfig
endpoint :: Maybe Text
authorizationConfig :: Maybe AuthorizationConfig
$sel:endpoint:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe Text
$sel:authorizationConfig:HttpDataSourceConfig' :: HttpDataSourceConfig -> Maybe AuthorizationConfig
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"authorizationConfig" 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 AuthorizationConfig
authorizationConfig,
            (Key
"endpoint" 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
endpoint
          ]
      )