{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudWatchEvents.Types.HttpParameters 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

-- | 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 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),
    -- | 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)
  }
  deriving (HttpParameters -> HttpParameters -> Bool
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]
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
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. 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:
--
-- 'headerParameters', 'httpParameters_headerParameters' - The headers that need to be sent as part of request invoking the API
-- Gateway REST API or EventBridge ApiDestination.
--
-- '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.
newHttpParameters ::
  HttpParameters
newHttpParameters :: HttpParameters
newHttpParameters =
  HttpParameters'
    { $sel:headerParameters:HttpParameters' :: Maybe (HashMap Text Text)
headerParameters = forall a. Maybe a
Prelude.Nothing,
      $sel:pathParameterValues:HttpParameters' :: Maybe [Text]
pathParameterValues = forall a. Maybe a
Prelude.Nothing,
      $sel:queryStringParameters:HttpParameters' :: Maybe (HashMap Text Text)
queryStringParameters = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' HttpParameters (Maybe (HashMap Text Text))
httpParameters_headerParameters = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: Lens' HttpParameters (Maybe [Text])
httpParameters_pathParameterValues = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' HttpParameters (Maybe (HashMap Text Text))
httpParameters_queryStringParameters = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON HttpParameters where
  parseJSON :: Value -> Parser HttpParameters
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HttpParameters"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe [Text] -> Maybe (HashMap Text Text) -> HttpParameters
HttpParameters'
            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
"HeaderParameters"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"PathParameterValues"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"QueryStringParameters"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable HttpParameters where
  hashWithSalt :: Int -> HttpParameters -> Int
hashWithSalt Int
_salt HttpParameters' {Maybe [Text]
Maybe (HashMap Text Text)
queryStringParameters :: Maybe (HashMap Text Text)
pathParameterValues :: Maybe [Text]
headerParameters :: Maybe (HashMap Text Text)
$sel:queryStringParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
$sel:pathParameterValues:HttpParameters' :: HttpParameters -> Maybe [Text]
$sel:headerParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
headerParameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
pathParameterValues
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
queryStringParameters

instance Prelude.NFData HttpParameters where
  rnf :: HttpParameters -> ()
rnf HttpParameters' {Maybe [Text]
Maybe (HashMap Text Text)
queryStringParameters :: Maybe (HashMap Text Text)
pathParameterValues :: Maybe [Text]
headerParameters :: Maybe (HashMap Text Text)
$sel:queryStringParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
$sel:pathParameterValues:HttpParameters' :: HttpParameters -> Maybe [Text]
$sel:headerParameters:HttpParameters' :: HttpParameters -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
headerParameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
pathParameterValues
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
queryStringParameters

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