{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}

module Dormouse.Client.Status
  ( ok
  , created
  , accepted
  , nonAuthoritativeInformation
  , noContent
  , resetContent
  , partialContent
  , badRequest
  , notFound
  , internalServerError
  , pattern Informational
  , pattern Successful
  , pattern Redirect
  , pattern ClientError
  , pattern ServerError
  , pattern Ok
  , pattern Created
  , pattern Accepted
  , pattern NonAuthoritativeInformation
  , pattern NoContent
  , pattern ResetContent
  , pattern PartialContent
  , pattern BadRequest
  , pattern NotFound
  , pattern InternalServerError
  ) where

-- | Checks whether the status code is in the range of Informational (1xx) status codes
isInformational :: Int -> Bool
isInformational :: Int -> Bool
isInformational Int
x = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
100 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
200

-- | Checks whether the status code is in the range of Successful (2xx) status codes
isSuccessful :: Int -> Bool
isSuccessful :: Int -> Bool
isSuccessful Int
x = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
200 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
300

-- | Checks whether the status code is in the range of Redirect (3xx) status codes
isRedirect :: Int -> Bool
isRedirect :: Int -> Bool
isRedirect Int
x = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
300 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
400

-- | Checks whether the status code is in the range of Client Error (4xx) status codes
isClientError :: Int -> Bool
isClientError :: Int -> Bool
isClientError Int
x = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
400 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
500

-- | Checks whether the status code is in the range of Server Error (5xx) status codes
isServerError :: Int -> Bool
isServerError :: Int -> Bool
isServerError Int
x = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
500 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
600

ok :: Int
ok :: Int
ok = Int
200

created :: Int
created :: Int
created = Int
201

accepted :: Int
accepted :: Int
accepted = Int
202

nonAuthoritativeInformation :: Int
nonAuthoritativeInformation :: Int
nonAuthoritativeInformation = Int
203

noContent :: Int
noContent :: Int
noContent = Int
204

resetContent :: Int
resetContent :: Int
resetContent = Int
205

partialContent :: Int
partialContent :: Int
partialContent  = Int
206

badRequest :: Int
badRequest :: Int
badRequest = Int
400

notFound :: Int
notFound :: Int
notFound = Int
404

internalServerError :: Int
internalServerError :: Int
internalServerError = Int
500

-- | Matches for 1XX http status codes
pattern Informational :: Int
pattern $mInformational :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
Informational <- (isInformational -> True)

-- | Matches for 2XX http status codes
pattern Successful :: Int
pattern $mSuccessful :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
Successful <- (isSuccessful -> True)

-- | Matches for 3XX http status codes
pattern Redirect :: Int
pattern $mRedirect :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
Redirect <- (isRedirect -> True)

-- | Matches for 4XX http status codes
pattern ClientError :: Int
pattern $mClientError :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
ClientError <- (isClientError -> True)

-- | Matches for 5XX http status codes
pattern ServerError :: Int
pattern $mServerError :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
ServerError <- (isServerError -> True)

-- | Matches the 200 Ok status code
pattern Ok :: Int
pattern $mOk :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
Ok <- ((==) ok -> True)

-- | Matches the 201 Created status code
pattern Created :: Int
pattern $mCreated :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
Created <- ((==) created -> True)

-- | Matches the 202 Accepted status code
pattern Accepted :: Int
pattern $mAccepted :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
Accepted <- ((==) accepted -> True)

-- | Matches the 203 Non-Authoritative Information status code
pattern NonAuthoritativeInformation :: Int
pattern $mNonAuthoritativeInformation :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
NonAuthoritativeInformation <- ((==) nonAuthoritativeInformation -> True)

-- | Matches the 204 No Content status code
pattern NoContent :: Int
pattern $mNoContent :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
NoContent <- ((==) noContent -> True)

-- | Matches the 205 Reset Content status code
pattern ResetContent :: Int
pattern $mResetContent :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
ResetContent <- ((==) resetContent -> True)

-- | Matches the 206 Partial Content status code
pattern PartialContent :: Int
pattern $mPartialContent :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
PartialContent <- ((==) partialContent -> True)

-- | Matches the 400 Bad Request status code
pattern BadRequest :: Int
pattern $mBadRequest :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
BadRequest <- ((==) badRequest -> True)

-- | Matches the 404 Not Found status code
pattern NotFound :: Int
pattern $mNotFound :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
NotFound <- ((==) notFound -> True)

-- | Matches the 500 Internal Server Error status code
pattern InternalServerError :: Int
pattern $mInternalServerError :: forall r. Int -> (Void# -> r) -> (Void# -> r) -> r
InternalServerError <- ((==) internalServerError -> True)