package httptest

import "github.com/labstack/echo/v4"

// MustGET is similar to GET() but the response http code must be 200.
func MustGET[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.GET, path, opts...)
	must200(path, rec)
	return rec, rec.GetBody()
}

// MustPOST is similar to POST() but the response http code must be 200.
func MustPOST[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.POST, path, opts...)
	must200(path, rec)
	return rec, rec.GetBody()
}

// MustPUT is similar to PUT() but the response http code must be 200.
func MustPUT[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.PUT, path, opts...)
	must200(path, rec)
	return rec, rec.GetBody()
}

// MustDELETE is similar to DELETE() but the response http code must be 200.
func MustDELETE[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.DELETE, path, opts...)
	must200(path, rec)
	return rec, rec.GetBody()
}

// MustHEAD is similar to HEAD() but the response http code must be 200.
func MustHEAD(e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[any]) {
	rec = HEAD(e, path, opts...)
	must200(path, rec)
	return rec
}

// MustPATCH is similar to PATCH() but the response http code must be 200.
func MustPATCH[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.PATCH, path, opts...)
	must200(path, rec)
	return rec, rec.GetBody()
}

func GET[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.GET, path, opts...)
	return rec, rec.GetBody()
}

func POST[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.POST, path, opts...)
	return rec, rec.GetBody()
}

func PUT[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.PUT, path, opts...)
	return rec, rec.GetBody()
}

func DELETE[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.DELETE, path, opts...)
	return rec, rec.GetBody()
}

func HEAD(e *echo.Echo, path string, opts ...requestOpts) *ResponseRecorder[any] {
	return Serve[any](e, echo.HEAD, path, opts...)
}

func PATCH[B any](e *echo.Echo, path string, opts ...requestOpts) (rec *ResponseRecorder[B], body B) {
	rec = Serve[B](e, echo.PATCH, path, opts...)
	return rec, rec.GetBody()
}
