-- |
-- Module       : Web.Skell.Responsible
-- Description  : Typeclass for respons
-- Copyright    : 2014, Peter Harpending.
-- License      : BSD3
-- Maintainer   : Peter Harpending <pharpend2@gmail.com>
-- Stability    : experimental
-- Portability  : archlinux
--

module Web.Skell.Responsible where

import qualified Data.Map.Lazy as M
import qualified Data.ByteString as Bs
import qualified Data.ByteString.Lazy as Bl
import           Network.HTTP.Types
import           Network.Wai

-- |Things that generate a response
class Responsible a where
  respond :: a -> Request -> Response

-- |Things that generate a response, but need IO to do so
class Irresponsible a where
  respondIO :: a -> Request -> IO Response

-- |Given a content type, such as @"text/html"@, and a 'Bl.Bytestring'
-- response, send a response with status 200.
respond200 :: Bs.ByteString -> Bl.ByteString -> Response
respond200 contentType = responseLBS status200 [(hContentType, contentType)]

-- |Given a content type, such as @"text/html"@, and a 'Bl.Bytestring'
-- response, send a response with status 403.
respond403 :: Bs.ByteString -> Bl.ByteString -> Response
respond403 contentType = responseLBS status403 [(hContentType, contentType)]

-- |Given a content type, such as @"text/html"@, and a 'Bl.Bytestring'
-- response, send a response with status 404.
respond404 :: Bs.ByteString -> Bl.ByteString -> Response
respond404 contentType = responseLBS status404 [(hContentType, contentType)]

-- |Given a content type, such as @"text/html"@, and a 'Bl.Bytestring'
-- response, send a response with status 405.
respond405 :: Bs.ByteString -> Bl.ByteString -> Response
respond405 contentType = responseLBS status405 [(hContentType, contentType)]