{-# 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.IoT.Types.HttpContext
-- 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.IoT.Types.HttpContext 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

-- | Specifies the HTTP context to use for the test authorizer request.
--
-- /See:/ 'newHttpContext' smart constructor.
data HttpContext = HttpContext'
  { -- | The header keys and values in an HTTP authorization request.
    HttpContext -> Maybe (HashMap Text Text)
headers :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The query string keys and values in an HTTP authorization request.
    HttpContext -> Maybe Text
queryString :: Prelude.Maybe Prelude.Text
  }
  deriving (HttpContext -> HttpContext -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpContext -> HttpContext -> Bool
$c/= :: HttpContext -> HttpContext -> Bool
== :: HttpContext -> HttpContext -> Bool
$c== :: HttpContext -> HttpContext -> Bool
Prelude.Eq, ReadPrec [HttpContext]
ReadPrec HttpContext
Int -> ReadS HttpContext
ReadS [HttpContext]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpContext]
$creadListPrec :: ReadPrec [HttpContext]
readPrec :: ReadPrec HttpContext
$creadPrec :: ReadPrec HttpContext
readList :: ReadS [HttpContext]
$creadList :: ReadS [HttpContext]
readsPrec :: Int -> ReadS HttpContext
$creadsPrec :: Int -> ReadS HttpContext
Prelude.Read, Int -> HttpContext -> ShowS
[HttpContext] -> ShowS
HttpContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpContext] -> ShowS
$cshowList :: [HttpContext] -> ShowS
show :: HttpContext -> String
$cshow :: HttpContext -> String
showsPrec :: Int -> HttpContext -> ShowS
$cshowsPrec :: Int -> HttpContext -> ShowS
Prelude.Show, forall x. Rep HttpContext x -> HttpContext
forall x. HttpContext -> Rep HttpContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpContext x -> HttpContext
$cfrom :: forall x. HttpContext -> Rep HttpContext x
Prelude.Generic)

-- |
-- Create a value of 'HttpContext' 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:
--
-- 'headers', 'httpContext_headers' - The header keys and values in an HTTP authorization request.
--
-- 'queryString', 'httpContext_queryString' - The query string keys and values in an HTTP authorization request.
newHttpContext ::
  HttpContext
newHttpContext :: HttpContext
newHttpContext =
  HttpContext'
    { $sel:headers:HttpContext' :: Maybe (HashMap Text Text)
headers = forall a. Maybe a
Prelude.Nothing,
      $sel:queryString:HttpContext' :: Maybe Text
queryString = forall a. Maybe a
Prelude.Nothing
    }

-- | The header keys and values in an HTTP authorization request.
httpContext_headers :: Lens.Lens' HttpContext (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
httpContext_headers :: Lens' HttpContext (Maybe (HashMap Text Text))
httpContext_headers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpContext' {Maybe (HashMap Text Text)
headers :: Maybe (HashMap Text Text)
$sel:headers:HttpContext' :: HttpContext -> Maybe (HashMap Text Text)
headers} -> Maybe (HashMap Text Text)
headers) (\s :: HttpContext
s@HttpContext' {} Maybe (HashMap Text Text)
a -> HttpContext
s {$sel:headers:HttpContext' :: Maybe (HashMap Text Text)
headers = Maybe (HashMap Text Text)
a} :: HttpContext) 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 and values in an HTTP authorization request.
httpContext_queryString :: Lens.Lens' HttpContext (Prelude.Maybe Prelude.Text)
httpContext_queryString :: Lens' HttpContext (Maybe Text)
httpContext_queryString = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpContext' {Maybe Text
queryString :: Maybe Text
$sel:queryString:HttpContext' :: HttpContext -> Maybe Text
queryString} -> Maybe Text
queryString) (\s :: HttpContext
s@HttpContext' {} Maybe Text
a -> HttpContext
s {$sel:queryString:HttpContext' :: Maybe Text
queryString = Maybe Text
a} :: HttpContext)

instance Prelude.Hashable HttpContext where
  hashWithSalt :: Int -> HttpContext -> Int
hashWithSalt Int
_salt HttpContext' {Maybe Text
Maybe (HashMap Text Text)
queryString :: Maybe Text
headers :: Maybe (HashMap Text Text)
$sel:queryString:HttpContext' :: HttpContext -> Maybe Text
$sel:headers:HttpContext' :: HttpContext -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
headers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
queryString

instance Prelude.NFData HttpContext where
  rnf :: HttpContext -> ()
rnf HttpContext' {Maybe Text
Maybe (HashMap Text Text)
queryString :: Maybe Text
headers :: Maybe (HashMap Text Text)
$sel:queryString:HttpContext' :: HttpContext -> Maybe Text
$sel:headers:HttpContext' :: HttpContext -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
headers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
queryString

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