-- | Generate responses based on their HTTP status
module WebGear.Core.Trait.Status (
  Status (..),

  -- * Create responses
  mkResponse,
  continue100,
  switchingProtocols101,
  ok200,
  created201,
  accepted202,
  nonAuthoritative203,
  noContent204,
  resetContent205,
  partialContent206,
  multipleChoices300,
  movedPermanently301,
  found302,
  seeOther303,
  notModified304,
  temporaryRedirect307,
  permanentRedirect308,
  badRequest400,
  unauthorized401,
  paymentRequired402,
  forbidden403,
  notFound404,
  methodNotAllowed405,
  notAcceptable406,
  proxyAuthenticationRequired407,
  requestTimeout408,
  conflict409,
  gone410,
  lengthRequired411,
  preconditionFailed412,
  requestEntityTooLarge413,
  requestURITooLong414,
  unsupportedMediaType415,
  requestedRangeNotSatisfiable416,
  expectationFailed417,
  imATeapot418,
  unprocessableEntity422,
  preconditionRequired428,
  tooManyRequests429,
  requestHeaderFieldsTooLarge431,
  internalServerError500,
  notImplemented501,
  badGateway502,
  serviceUnavailable503,
  gatewayTimeout504,
  httpVersionNotSupported505,
  networkAuthenticationRequired511,
) where

import qualified Network.HTTP.Types as HTTP
import WebGear.Core.Response (Response (..))
import WebGear.Core.Trait (Linked, Set, Trait (..), linkzero, plant)

-- | HTTP response status
newtype Status = Status HTTP.Status

instance Trait Status Response where
  type Attribute Status Response = HTTP.Status

-- | Generate a response with the specified status
mkResponse :: Set h Status Response => HTTP.Status -> h () (Linked '[Status] Response)
mkResponse :: forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
status = proc () -> do
  let response :: Linked '[] Response
response = forall a. a -> Linked '[] a
linkzero forall a b. (a -> b) -> a -> b
$ Status
-> HashMap HeaderName ByteString -> Maybe ByteString -> Response
Response Status
status [] forall a. Maybe a
Nothing
  forall t (ts :: [*]) (h :: * -> * -> *) a.
Set h t a =>
t -> h (Linked ts a, Attribute t a) (Linked (t : ts) a)
plant (Status -> Status
Status Status
status) -< (Linked '[] Response
response, Status
status)

-- | Continue 100 response
continue100 :: Set h Status Response => h () (Linked '[Status] Response)
continue100 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
continue100 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.continue100

-- | Switching Protocols 101 response
switchingProtocols101 :: Set h Status Response => h () (Linked '[Status] Response)
switchingProtocols101 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
switchingProtocols101 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.switchingProtocols101

-- | OK 200 response
ok200 :: Set h Status Response => h () (Linked '[Status] Response)
ok200 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
ok200 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.ok200

-- | Created 201 response
created201 :: Set h Status Response => h () (Linked '[Status] Response)
created201 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
created201 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.created201

-- | Accepted 202 response
accepted202 :: Set h Status Response => h () (Linked '[Status] Response)
accepted202 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
accepted202 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.accepted202

-- | Non-Authoritative 203 response
nonAuthoritative203 :: Set h Status Response => h () (Linked '[Status] Response)
nonAuthoritative203 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
nonAuthoritative203 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.nonAuthoritative203

-- | No Content 204 response
noContent204 :: Set h Status Response => h () (Linked '[Status] Response)
noContent204 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
noContent204 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.noContent204

-- | Reset Content 205 response
resetContent205 :: Set h Status Response => h () (Linked '[Status] Response)
resetContent205 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
resetContent205 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.resetContent205

-- | Partial Content 206 response
partialContent206 :: Set h Status Response => h () (Linked '[Status] Response)
partialContent206 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
partialContent206 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.partialContent206

-- | Multiple Choices 300 response
multipleChoices300 :: Set h Status Response => h () (Linked '[Status] Response)
multipleChoices300 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
multipleChoices300 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.multipleChoices300

-- | Moved Permanently 301 response
movedPermanently301 :: Set h Status Response => h () (Linked '[Status] Response)
movedPermanently301 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
movedPermanently301 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.movedPermanently301

-- | Found 302 response
found302 :: Set h Status Response => h () (Linked '[Status] Response)
found302 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
found302 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.found302

-- | See Other 303 response
seeOther303 :: Set h Status Response => h () (Linked '[Status] Response)
seeOther303 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
seeOther303 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.seeOther303

-- | Not Modified 304 response
notModified304 :: Set h Status Response => h () (Linked '[Status] Response)
notModified304 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
notModified304 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notModified304

-- | Temporary Redirect 307 response
temporaryRedirect307 :: Set h Status Response => h () (Linked '[Status] Response)
temporaryRedirect307 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
temporaryRedirect307 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.temporaryRedirect307

-- | Permanent Redirect 308 response
permanentRedirect308 :: Set h Status Response => h () (Linked '[Status] Response)
permanentRedirect308 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
permanentRedirect308 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.permanentRedirect308

-- | Bad Request 400 response
badRequest400 :: Set h Status Response => h () (Linked '[Status] Response)
badRequest400 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
badRequest400 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.badRequest400

-- | Unauthorized 401 response
unauthorized401 :: Set h Status Response => h () (Linked '[Status] Response)
unauthorized401 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
unauthorized401 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.unauthorized401

-- | Payment Required 402 response
paymentRequired402 :: Set h Status Response => h () (Linked '[Status] Response)
paymentRequired402 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
paymentRequired402 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.paymentRequired402

-- | Forbidden 403 response
forbidden403 :: Set h Status Response => h () (Linked '[Status] Response)
forbidden403 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
forbidden403 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.forbidden403

-- | Not Found 404 response
notFound404 :: Set h Status Response => h () (Linked '[Status] Response)
notFound404 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
notFound404 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notFound404

-- | Method Not Allowed 405 response
methodNotAllowed405 :: Set h Status Response => h () (Linked '[Status] Response)
methodNotAllowed405 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
methodNotAllowed405 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.methodNotAllowed405

-- | Not Acceptable 406 response
notAcceptable406 :: Set h Status Response => h () (Linked '[Status] Response)
notAcceptable406 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
notAcceptable406 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notAcceptable406

-- | Proxy Authentication Required 407 response
proxyAuthenticationRequired407 :: Set h Status Response => h () (Linked '[Status] Response)
proxyAuthenticationRequired407 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
proxyAuthenticationRequired407 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.proxyAuthenticationRequired407

-- | Request Timeout 408 response
requestTimeout408 :: Set h Status Response => h () (Linked '[Status] Response)
requestTimeout408 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
requestTimeout408 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestTimeout408

-- | Conflict 409 response
conflict409 :: Set h Status Response => h () (Linked '[Status] Response)
conflict409 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
conflict409 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.conflict409

-- | Gone 410 response
gone410 :: Set h Status Response => h () (Linked '[Status] Response)
gone410 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
gone410 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.gone410

-- | Length Required 411 response
lengthRequired411 :: Set h Status Response => h () (Linked '[Status] Response)
lengthRequired411 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
lengthRequired411 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.lengthRequired411

-- | Precondition Failed 412 response
preconditionFailed412 :: Set h Status Response => h () (Linked '[Status] Response)
preconditionFailed412 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
preconditionFailed412 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.preconditionFailed412

-- | Request Entity Too Large 413 response
requestEntityTooLarge413 :: Set h Status Response => h () (Linked '[Status] Response)
requestEntityTooLarge413 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
requestEntityTooLarge413 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestEntityTooLarge413

-- | Request URI Too Long 414 response
requestURITooLong414 :: Set h Status Response => h () (Linked '[Status] Response)
requestURITooLong414 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
requestURITooLong414 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestURITooLong414

-- | Unsupported Media Type 415 response
unsupportedMediaType415 :: Set h Status Response => h () (Linked '[Status] Response)
unsupportedMediaType415 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
unsupportedMediaType415 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.unsupportedMediaType415

-- | Requested Range Not Satisfiable 416 response
requestedRangeNotSatisfiable416 :: Set h Status Response => h () (Linked '[Status] Response)
requestedRangeNotSatisfiable416 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
requestedRangeNotSatisfiable416 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestedRangeNotSatisfiable416

-- | Expectation Failed 417 response
expectationFailed417 :: Set h Status Response => h () (Linked '[Status] Response)
expectationFailed417 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
expectationFailed417 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.expectationFailed417

-- | I'm A Teapot 418 response
imATeapot418 :: Set h Status Response => h () (Linked '[Status] Response)
imATeapot418 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
imATeapot418 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.imATeapot418

-- | Unprocessable Entity 422 response
unprocessableEntity422 :: Set h Status Response => h () (Linked '[Status] Response)
unprocessableEntity422 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
unprocessableEntity422 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.unprocessableEntity422

-- | Precondition Required 428 response
preconditionRequired428 :: Set h Status Response => h () (Linked '[Status] Response)
preconditionRequired428 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
preconditionRequired428 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.preconditionRequired428

-- | Too Many Requests 429 response
tooManyRequests429 :: Set h Status Response => h () (Linked '[Status] Response)
tooManyRequests429 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
tooManyRequests429 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.tooManyRequests429

-- | Request Header Fields Too Large 431 response
requestHeaderFieldsTooLarge431 :: Set h Status Response => h () (Linked '[Status] Response)
requestHeaderFieldsTooLarge431 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
requestHeaderFieldsTooLarge431 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestHeaderFieldsTooLarge431

-- | Internal Server Error 500 response
internalServerError500 :: Set h Status Response => h () (Linked '[Status] Response)
internalServerError500 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
internalServerError500 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.internalServerError500

-- | Not Implemented 501 response
notImplemented501 :: Set h Status Response => h () (Linked '[Status] Response)
notImplemented501 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
notImplemented501 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notImplemented501

-- | Bad Gateway 502 response
badGateway502 :: Set h Status Response => h () (Linked '[Status] Response)
badGateway502 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
badGateway502 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.badGateway502

-- | Service Unavailable 503 response
serviceUnavailable503 :: Set h Status Response => h () (Linked '[Status] Response)
serviceUnavailable503 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
serviceUnavailable503 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.serviceUnavailable503

-- | Gateway Timeout 504 response
gatewayTimeout504 :: Set h Status Response => h () (Linked '[Status] Response)
gatewayTimeout504 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
gatewayTimeout504 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.gatewayTimeout504

-- | HTTP Version Not Supported 505 response
httpVersionNotSupported505 :: Set h Status Response => h () (Linked '[Status] Response)
httpVersionNotSupported505 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
httpVersionNotSupported505 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.httpVersionNotSupported505

-- | Network Authentication Required 511 response
networkAuthenticationRequired511 :: Set h Status Response => h () (Linked '[Status] Response)
networkAuthenticationRequired511 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (Linked '[Status] Response)
networkAuthenticationRequired511 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.networkAuthenticationRequired511