{-# LANGUAGE DeriveFunctor #-}

module Web.Minion.Response.Status where

import Network.HTTP.Types
import Network.HTTP.Types qualified as Http
import Network.Wai qualified as Wai
import Web.Minion

newtype WithStatus status a = WithStatus
  {forall {k} (status :: k) a. WithStatus status a -> a
body :: a}
  deriving ((forall a b.
 (a -> b) -> WithStatus status a -> WithStatus status b)
-> (forall a b. a -> WithStatus status b -> WithStatus status a)
-> Functor (WithStatus status)
forall k (status :: k) a b.
a -> WithStatus status b -> WithStatus status a
forall k (status :: k) a b.
(a -> b) -> WithStatus status a -> WithStatus status b
forall a b. a -> WithStatus status b -> WithStatus status a
forall a b. (a -> b) -> WithStatus status a -> WithStatus status b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall k (status :: k) a b.
(a -> b) -> WithStatus status a -> WithStatus status b
fmap :: forall a b. (a -> b) -> WithStatus status a -> WithStatus status b
$c<$ :: forall k (status :: k) a b.
a -> WithStatus status b -> WithStatus status a
<$ :: forall a b. a -> WithStatus status b -> WithStatus status a
Functor)

instance (ToResponse m a, Monad m, IsStatus status) => ToResponse m (WithStatus status a) where
  toResponse :: [ByteString] -> WithStatus status a -> m Response
toResponse [ByteString]
accept WithStatus{a
$sel:body:WithStatus :: forall {k} (status :: k) a. WithStatus status a -> a
body :: a
..} =
    (Status -> Status) -> Response -> Response
Wai.mapResponseStatus (Status -> Status -> Status
forall a b. a -> b -> a
const (Status -> Status -> Status) -> Status -> Status -> Status
forall a b. (a -> b) -> a -> b
$ forall (status :: k). IsStatus status => Status
forall {k} (status :: k). IsStatus status => Status
status @status)
      (Response -> Response) -> m Response -> m Response
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ByteString] -> a -> m Response
forall (m :: * -> *) r.
ToResponse m r =>
[ByteString] -> r -> m Response
toResponse [ByteString]
accept a
body

instance (CanRespond a) => CanRespond (WithStatus status a) where
  canRespond :: [ByteString] -> Bool
canRespond = forall o. CanRespond o => [ByteString] -> Bool
forall {k} (o :: k). CanRespond o => [ByteString] -> Bool
canRespond @a

class IsStatus status where
  status :: Http.Status

data Continue

instance IsStatus Continue where
  status :: Status
status = Status
status100

data SwitchingProtocols
instance IsStatus SwitchingProtocols where
  status :: Status
status = Status
status101

data OK
instance IsStatus OK where
  status :: Status
status = Status
status200

data Created
instance IsStatus Created where
  status :: Status
status = Status
status201

data Accepted
instance IsStatus Accepted where
  status :: Status
status = Status
status202

data NonAuthoritativeInformation
instance IsStatus NonAuthoritativeInformation where
  status :: Status
status = Status
status203

data NoContent
instance IsStatus NoContent where
  status :: Status
status = Status
status204

data ResetContent
instance IsStatus ResetContent where
  status :: Status
status = Status
status205

data PartialContent
instance IsStatus PartialContent where
  status :: Status
status = Status
status206

data MultipleChoices
instance IsStatus MultipleChoices where
  status :: Status
status = Status
status300

data MovedPermanently
instance IsStatus MovedPermanently where
  status :: Status
status = Status
status301

data Found
instance IsStatus Found where
  status :: Status
status = Status
status302

data SeeOther
instance IsStatus SeeOther where
  status :: Status
status = Status
status303

data NotModified
instance IsStatus NotModified where
  status :: Status
status = Status
status304

data UseProxy
instance IsStatus UseProxy where
  status :: Status
status = Status
status305

data TemporaryRedirect
instance IsStatus TemporaryRedirect where
  status :: Status
status = Status
status307

data PermanentRedirect
instance IsStatus PermanentRedirect where
  status :: Status
status = Status
status308

data BadRequest
instance IsStatus BadRequest where
  status :: Status
status = Status
status400

data Unauthorized
instance IsStatus Unauthorized where
  status :: Status
status = Status
status401

data PaymentRequired
instance IsStatus PaymentRequired where
  status :: Status
status = Status
status402

data Forbidden
instance IsStatus Forbidden where
  status :: Status
status = Status
status403

data NotFound
instance IsStatus NotFound where
  status :: Status
status = Status
status404

data MethodNotAllowed
instance IsStatus MethodNotAllowed where
  status :: Status
status = Status
status405

data NotAcceptable
instance IsStatus NotAcceptable where
  status :: Status
status = Status
status406

data ProxyAuthenticationRequired
instance IsStatus ProxyAuthenticationRequired where
  status :: Status
status = Status
status407

data RequestTimeout
instance IsStatus RequestTimeout where
  status :: Status
status = Status
status408

data Conflict
instance IsStatus Conflict where
  status :: Status
status = Status
status409

data Gone
instance IsStatus Gone where
  status :: Status
status = Status
status410

data LengthRequired
instance IsStatus LengthRequired where
  status :: Status
status = Status
status411

data PreconditionFailed
instance IsStatus PreconditionFailed where
  status :: Status
status = Status
status412

data PayloadTooLarge
instance IsStatus PayloadTooLarge where
  status :: Status
status = Status
status413

data URITooLong
instance IsStatus URITooLong where
  status :: Status
status = Status
status414

data UnsupportedMediaType
instance IsStatus UnsupportedMediaType where
  status :: Status
status = Status
status415

data RangeNotSatisfiable
instance IsStatus RangeNotSatisfiable where
  status :: Status
status = Status
status416

data ExpectationFailed
instance IsStatus ExpectationFailed where
  status :: Status
status = Status
status417

data ImATeapot
instance IsStatus ImATeapot where
  status :: Status
status = Status
status418

data UnprocessableEntity
instance IsStatus UnprocessableEntity where
  status :: Status
status = Status
status422

data PreconditionRequired
instance IsStatus PreconditionRequired where
  status :: Status
status = Status
status428

data TooManyRequests
instance IsStatus TooManyRequests where
  status :: Status
status = Status
status429

data RequestHeaderFieldsTooLarge
instance IsStatus RequestHeaderFieldsTooLarge where
  status :: Status
status = Status
status431

data InternalServerError
instance IsStatus InternalServerError where
  status :: Status
status = Status
status500

data NotImplemented
instance IsStatus NotImplemented where
  status :: Status
status = Status
status501

data BadGateway
instance IsStatus BadGateway where
  status :: Status
status = Status
status502

data ServiceUnavailable
instance IsStatus ServiceUnavailable where
  status :: Status
status = Status
status503

data GatewayTimeout
instance IsStatus GatewayTimeout where
  status :: Status
status = Status
status504

data HTTPVersionNotSupported
instance IsStatus HTTPVersionNotSupported where
  status :: Status
status = Status
status505

data NetworkAuthenticationRequired
instance IsStatus NetworkAuthenticationRequired where
  status :: Status
status = Status
status511