{-# 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.CloudWatchEvents.Types.HttpParameters
-- 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.CloudWatchEvents.Types.HttpParameters where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | These are custom parameter to be used when the target is an API Gateway
-- REST APIs or EventBridge ApiDestinations. In the latter case, these are
-- merged with any InvocationParameters specified on the Connection, with
-- any values from the Connection taking precedence.
--
-- /See:/ 'newHttpParameters' smart constructor.
data HttpParameters = HttpParameters'
  { -- | The path parameter values to be used to populate API Gateway REST API or
    -- EventBridge ApiDestination path wildcards (\"*\").
    HttpParameters -> Maybe [Text]
pathParameterValues :: Prelude.Maybe [Prelude.Text],
    -- | The query string keys\/values that need to be sent as part of request
    -- invoking the API Gateway REST API or EventBridge ApiDestination.
    HttpParameters -> Maybe (HashMap Text Text)
queryStringParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The headers that need to be sent as part of request invoking the API
    -- Gateway REST API or EventBridge ApiDestination.
    HttpParameters -> Maybe (HashMap Text Text)
headerParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (HttpParameters -> HttpParameters -> Bool
(HttpParameters -> HttpParameters -> Bool)
-> (HttpParameters -> HttpParameters -> Bool) -> Eq HttpParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpParameters -> HttpParameters -> Bool
$c/= :: HttpParameters -> HttpParameters -> Bool
== :: HttpParameters -> HttpParameters -> Bool
$c== :: HttpParameters -> HttpParameters -> Bool
Prelude.Eq, ReadPrec [HttpParameters]
ReadPrec HttpParameters
Int -> ReadS HttpParameters
ReadS [HttpParameters]
(Int -> ReadS HttpParameters)
-> ReadS [HttpParameters]
-> ReadPrec HttpParameters
-> ReadPrec [HttpParameters]
-> Read HttpParameters
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpParameters]
$creadListPrec :: ReadPrec [HttpParameters]
readPrec :: ReadPrec HttpParameters
$creadPrec :: ReadPrec HttpParameters
readList :: ReadS [HttpParameters]
$creadList :: ReadS [HttpParameters]
readsPrec :: Int -> ReadS HttpParameters
$creadsPrec :: Int -> ReadS HttpParameters
Prelude.Read, Int -> HttpParameters -> ShowS
[HttpParameters] -> ShowS
HttpParameters -> String
(Int -> HttpParameters -> ShowS)
-> (HttpParameters -> String)
-> ([HttpParameters] -> ShowS)
-> Show HttpParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpParameters] -> ShowS
$cshowList :: [HttpParameters] -> ShowS
show :: HttpParameters -> String
$cshow :: HttpParameters -> String
showsPrec :: Int -> HttpParameters -> ShowS
$cshowsPrec :: Int -> HttpParameters -> ShowS
Prelude.Show, (forall x. HttpParameters -> Rep HttpParameters x)
-> (forall x. Rep HttpParameters x -> HttpParameters)
-> Generic HttpParameters
forall x. Rep HttpParameters x -> HttpParameters
forall x. HttpParameters -> Rep HttpParameters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpParameters x -> HttpParameters
$cfrom :: forall x. HttpParameters -> Rep HttpParameters x
Prelude.Generic)

-- |
-- Create a value of 'HttpParameters' 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:
--
-- 'pathParameterValues', 'httpParameters_pathParameterValues' - The path parameter values to be used to populate API Gateway REST API or
-- EventBridge ApiDestination path wildcards (\"*\").
--
-- 'queryStringParameters', 'httpParameters_queryStringParameters' - The query string keys\/values that need to be sent as part of request
-- invoking the API Gateway REST API or EventBridge ApiDestination.
--
-- 'headerParameters', 'httpParameters_headerParameters' - The headers that need to be sent as part of request invoking the API
-- Gateway REST API or EventBridge ApiDestination.
newHttpParameters ::
  HttpParameters
newHttpParameters :: HttpParameters
newHttpParameters =
  HttpParameters' :: Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text)
-> HttpParameters
HttpParameters'
    { $sel:pathParameterValues:HttpParameters' :: Maybe [Text]
pathParameterValues =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:queryStringParameters:HttpParameters' :: Maybe (HashMap Text Text)
queryStringParameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:headerParameters:HttpParameters' :: Maybe (HashMap Text Text)
headerParameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | The path parameter values to be used to populate API Gateway REST API or
-- EventBridge ApiDestination path wildcards (\"*\").
httpParameters_pathParameterValues :: Lens.Lens' HttpParameters (Prelude.Maybe [Prelude.Text])
httpParameters_pathParameterValues :: (Maybe [Text] -> f (Maybe [Text]))
-> HttpParameters -> f HttpParameters
httpParameters_pathParameterValues = (HttpParameters -> Maybe [Text])
-> (HttpParameters -> Maybe [Text] -> HttpParameters)
-> Lens HttpParameters HttpParameters (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpParameters' {Maybe [Text]
pathParameterValues :: Maybe [Text]
$sel:pathParameterValues:HttpParameters' :: HttpParameters -> Maybe [Text]
pathParameterValues} -> Maybe [Text]
pathParameterValues) (\s :: HttpParameters
s@HttpParameters' {} Maybe [Text]
a -> HttpParameters
s {$sel:pathParameterValues:HttpParameters' :: Maybe [Text]
pathParameterValues = Maybe [Text]
a} :: HttpParameters) ((Maybe [Text] -> f (Maybe [Text]))
 -> HttpParameters -> f HttpParameters)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> HttpParameters
-> f HttpParameters
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The query string keys\/values that need to be sent as part of request
-- invoking the API Gateway REST API or EventBridge ApiDestination.
httpParameters_queryStringParameters :: Lens.Lens' HttpParameters (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
httpParameters_queryStringParameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> HttpParameters -> f HttpParameters
httpParameters_queryStringParameters = (HttpParameters -> Maybe (HashMap Text Text))
-> (HttpParameters -> Maybe (HashMap Text Text) -> HttpParameters)
-> Lens
     HttpParameters
     HttpParameters
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpParameters' {Maybe (HashMap Text Text)
queryStringParameters :: Maybe (HashMap Text Text)
$sel:queryStringParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
queryStringParameters} -> Maybe (HashMap Text Text)
queryStringParameters) (\s :: HttpParameters
s@HttpParameters' {} Maybe (HashMap Text Text)
a -> HttpParameters
s {$sel:queryStringParameters:HttpParameters' :: Maybe (HashMap Text Text)
queryStringParameters = Maybe (HashMap Text Text)
a} :: HttpParameters) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> HttpParameters -> f HttpParameters)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> HttpParameters
-> f HttpParameters
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The headers that need to be sent as part of request invoking the API
-- Gateway REST API or EventBridge ApiDestination.
httpParameters_headerParameters :: Lens.Lens' HttpParameters (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
httpParameters_headerParameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> HttpParameters -> f HttpParameters
httpParameters_headerParameters = (HttpParameters -> Maybe (HashMap Text Text))
-> (HttpParameters -> Maybe (HashMap Text Text) -> HttpParameters)
-> Lens
     HttpParameters
     HttpParameters
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpParameters' {Maybe (HashMap Text Text)
headerParameters :: Maybe (HashMap Text Text)
$sel:headerParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
headerParameters} -> Maybe (HashMap Text Text)
headerParameters) (\s :: HttpParameters
s@HttpParameters' {} Maybe (HashMap Text Text)
a -> HttpParameters
s {$sel:headerParameters:HttpParameters' :: Maybe (HashMap Text Text)
headerParameters = Maybe (HashMap Text Text)
a} :: HttpParameters) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> HttpParameters -> f HttpParameters)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> HttpParameters
-> f HttpParameters
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON HttpParameters where
  parseJSON :: Value -> Parser HttpParameters
parseJSON =
    String
-> (Object -> Parser HttpParameters)
-> Value
-> Parser HttpParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HttpParameters"
      ( \Object
x ->
          Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text)
-> HttpParameters
HttpParameters'
            (Maybe [Text]
 -> Maybe (HashMap Text Text)
 -> Maybe (HashMap Text Text)
 -> HttpParameters)
-> Parser (Maybe [Text])
-> Parser
     (Maybe (HashMap Text Text)
      -> Maybe (HashMap Text Text) -> HttpParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PathParameterValues"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser
  (Maybe (HashMap Text Text)
   -> Maybe (HashMap Text Text) -> HttpParameters)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Maybe (HashMap Text Text) -> HttpParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"QueryStringParameters"
                            Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe (HashMap Text Text) -> HttpParameters)
-> Parser (Maybe (HashMap Text Text)) -> Parser HttpParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"HeaderParameters"
                            Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable HttpParameters

instance Prelude.NFData HttpParameters

instance Core.ToJSON HttpParameters where
  toJSON :: HttpParameters -> Value
toJSON HttpParameters' {Maybe [Text]
Maybe (HashMap Text Text)
headerParameters :: Maybe (HashMap Text Text)
queryStringParameters :: Maybe (HashMap Text Text)
pathParameterValues :: Maybe [Text]
$sel:headerParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
$sel:queryStringParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
$sel:pathParameterValues:HttpParameters' :: HttpParameters -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PathParameterValues" 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]
pathParameterValues,
            (Text
"QueryStringParameters" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
queryStringParameters,
            (Text
"HeaderParameters" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
headerParameters
          ]
      )