{-# OPTIONS_HADDOCK not-home #-}

{- |
Module      : Servant.API.Routes.Internal.Header
Copyright   : (c) Frederick Pringle, 2024
License     : BSD-3-Clause
Maintainer  : freddyjepringle@gmail.com

Internal module, subject to change.
-}
module Servant.API.Routes.Internal.Header
  ( HeaderRep (..)
  )
where

import Data.Aeson
import Data.Text
import Data.Typeable
import "this" Servant.API.Routes.Utils

{- | Simple term-level representation of a 'Servant.API.Header.Header'.

A type-level @'Servant.API.Header.Header' (sym :: 'GHC.TypeLits.Symbol') typ@ should correspond to
@'HeaderRep' { _hName = str, _hType =  typRep }@, where @str@ is the term-level equivalent
of @sym@ and @typRep@ is the term-level representation of @typ@.
-}
data HeaderRep = HeaderRep
  { HeaderRep -> Text
_hName :: Text
  , HeaderRep -> TypeRep
_hType :: TypeRep
  }
  deriving (Int -> HeaderRep -> ShowS
[HeaderRep] -> ShowS
HeaderRep -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeaderRep] -> ShowS
$cshowList :: [HeaderRep] -> ShowS
show :: HeaderRep -> String
$cshow :: HeaderRep -> String
showsPrec :: Int -> HeaderRep -> ShowS
$cshowsPrec :: Int -> HeaderRep -> ShowS
Show, HeaderRep -> HeaderRep -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HeaderRep -> HeaderRep -> Bool
$c/= :: HeaderRep -> HeaderRep -> Bool
== :: HeaderRep -> HeaderRep -> Bool
$c== :: HeaderRep -> HeaderRep -> Bool
Eq)

instance ToJSON HeaderRep where
  toJSON :: HeaderRep -> Value
toJSON HeaderRep {TypeRep
Text
_hType :: TypeRep
_hName :: Text
_hType :: HeaderRep -> TypeRep
_hName :: HeaderRep -> Text
..} =
    [Pair] -> Value
object
      [ Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
_hName
      , Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TypeRep -> Value
typeRepToJSON TypeRep
_hType
      ]