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

import Amazonka.AppSync.Types.AuthorizationConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an HTTP data source configuration.
--
-- /See:/ 'newHttpDataSourceConfig' smart constructor.
data HttpDataSourceConfig = HttpDataSourceConfig'
  { -- | The authorization config in case the HTTP endpoint requires
    -- authorization.
    HttpDataSourceConfig -> Maybe AuthorizationConfig
authorizationConfig :: Prelude.Maybe AuthorizationConfig,
    -- | The HTTP URL endpoint. You can either specify the domain name or IP, and
    -- port combination, and the URL scheme must be HTTP or HTTPS. If the port
    -- is not specified, 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
(HttpDataSourceConfig -> HttpDataSourceConfig -> Bool)
-> (HttpDataSourceConfig -> HttpDataSourceConfig -> Bool)
-> Eq HttpDataSourceConfig
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]
(Int -> ReadS HttpDataSourceConfig)
-> ReadS [HttpDataSourceConfig]
-> ReadPrec HttpDataSourceConfig
-> ReadPrec [HttpDataSourceConfig]
-> Read 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
(Int -> HttpDataSourceConfig -> ShowS)
-> (HttpDataSourceConfig -> String)
-> ([HttpDataSourceConfig] -> ShowS)
-> Show HttpDataSourceConfig
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. HttpDataSourceConfig -> Rep HttpDataSourceConfig x)
-> (forall x. Rep HttpDataSourceConfig x -> HttpDataSourceConfig)
-> Generic HttpDataSourceConfig
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 config in case the HTTP endpoint requires
-- authorization.
--
-- 'endpoint', 'httpDataSourceConfig_endpoint' - The HTTP URL endpoint. You can either specify the domain name or IP, and
-- port combination, and the URL scheme must be HTTP or HTTPS. If the port
-- is not specified, AppSync uses the default port 80 for the HTTP endpoint
-- and port 443 for HTTPS endpoints.
newHttpDataSourceConfig ::
  HttpDataSourceConfig
newHttpDataSourceConfig :: HttpDataSourceConfig
newHttpDataSourceConfig =
  HttpDataSourceConfig' :: Maybe AuthorizationConfig -> Maybe Text -> HttpDataSourceConfig
HttpDataSourceConfig'
    { $sel:authorizationConfig:HttpDataSourceConfig' :: Maybe AuthorizationConfig
authorizationConfig =
        Maybe AuthorizationConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:endpoint:HttpDataSourceConfig' :: Maybe Text
endpoint = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The authorization config in case the HTTP endpoint requires
-- authorization.
httpDataSourceConfig_authorizationConfig :: Lens.Lens' HttpDataSourceConfig (Prelude.Maybe AuthorizationConfig)
httpDataSourceConfig_authorizationConfig :: (Maybe AuthorizationConfig -> f (Maybe AuthorizationConfig))
-> HttpDataSourceConfig -> f HttpDataSourceConfig
httpDataSourceConfig_authorizationConfig = (HttpDataSourceConfig -> Maybe AuthorizationConfig)
-> (HttpDataSourceConfig
    -> Maybe AuthorizationConfig -> HttpDataSourceConfig)
-> Lens
     HttpDataSourceConfig
     HttpDataSourceConfig
     (Maybe AuthorizationConfig)
     (Maybe 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 either specify the domain name or IP, and
-- port combination, and the URL scheme must be HTTP or HTTPS. If the port
-- is not specified, 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 :: (Maybe Text -> f (Maybe Text))
-> HttpDataSourceConfig -> f HttpDataSourceConfig
httpDataSourceConfig_endpoint = (HttpDataSourceConfig -> Maybe Text)
-> (HttpDataSourceConfig -> Maybe Text -> HttpDataSourceConfig)
-> Lens
     HttpDataSourceConfig HttpDataSourceConfig (Maybe Text) (Maybe Text)
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 Core.FromJSON HttpDataSourceConfig where
  parseJSON :: Value -> Parser HttpDataSourceConfig
parseJSON =
    String
-> (Object -> Parser HttpDataSourceConfig)
-> Value
-> Parser HttpDataSourceConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HttpDataSourceConfig"
      ( \Object
x ->
          Maybe AuthorizationConfig -> Maybe Text -> HttpDataSourceConfig
HttpDataSourceConfig'
            (Maybe AuthorizationConfig -> Maybe Text -> HttpDataSourceConfig)
-> Parser (Maybe AuthorizationConfig)
-> Parser (Maybe Text -> HttpDataSourceConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AuthorizationConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"authorizationConfig")
            Parser (Maybe Text -> HttpDataSourceConfig)
-> Parser (Maybe Text) -> Parser HttpDataSourceConfig
forall (f :: * -> *) a b. Applicative f => 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
"endpoint")
      )

instance Prelude.Hashable HttpDataSourceConfig

instance Prelude.NFData HttpDataSourceConfig

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