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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(HttpContext -> HttpContext -> Bool)
-> (HttpContext -> HttpContext -> Bool) -> Eq HttpContext
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]
(Int -> ReadS HttpContext)
-> ReadS [HttpContext]
-> ReadPrec HttpContext
-> ReadPrec [HttpContext]
-> Read 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
(Int -> HttpContext -> ShowS)
-> (HttpContext -> String)
-> ([HttpContext] -> ShowS)
-> Show HttpContext
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. HttpContext -> Rep HttpContext x)
-> (forall x. Rep HttpContext x -> HttpContext)
-> Generic HttpContext
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' :: Maybe (HashMap Text Text) -> Maybe Text -> HttpContext
HttpContext'
    { $sel:headers:HttpContext' :: Maybe (HashMap Text Text)
headers = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:queryString:HttpContext' :: Maybe Text
queryString = Maybe Text
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 :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> HttpContext -> f HttpContext
httpContext_headers = (HttpContext -> Maybe (HashMap Text Text))
-> (HttpContext -> Maybe (HashMap Text Text) -> HttpContext)
-> Lens
     HttpContext
     HttpContext
     (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 (\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) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> HttpContext -> f HttpContext)
-> ((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)))
-> HttpContext
-> f HttpContext
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 query string keys and values in an HTTP authorization request.
httpContext_queryString :: Lens.Lens' HttpContext (Prelude.Maybe Prelude.Text)
httpContext_queryString :: (Maybe Text -> f (Maybe Text)) -> HttpContext -> f HttpContext
httpContext_queryString = (HttpContext -> Maybe Text)
-> (HttpContext -> Maybe Text -> HttpContext)
-> Lens HttpContext HttpContext (Maybe Text) (Maybe Text)
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

instance Prelude.NFData HttpContext

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"headers" 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)
headers,
            (Text
"queryString" 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
queryString
          ]
      )