module ReqMeth
  ( getM
  , putM
  , headM
  , postM
  , deleteM
  , optionsM
  , traceM
  , connectM
  , customRqMeth
  , methodList
  , RqMeth
  ) where

import Data.Char

newtype RqMeth = M String deriving (Eq, Ord)

instance Show RqMeth where
  show (M s) = s

getM :: RqMeth
putM :: RqMeth
headM :: RqMeth
postM :: RqMeth
deleteM :: RqMeth
optionsM :: RqMeth
traceM :: RqMeth
connectM :: RqMeth

getM = M "GET"
putM = M "PUT"
headM = M "HEAD"
postM = M "POST"
deleteM = M "DELETE"
optionsM = M "OPTIONS"
traceM = M "TRACE"
connectM = M "CONNECT"

methodList :: [RqMeth]
methodList =
  [ getM
  , putM
  , headM
  , postM
  , deleteM
  , optionsM
  , traceM
  , connectM ]

customRqMeth :: String -> RqMeth
customRqMeth s = let r = M $ map toUpper s in
  if elem r methodList then error "no custom request method" else r
