package response

import (
	"testing"

	"github.com/gofiber/fiber/v2"
	"github.com/valyala/fasthttp"
)

// BenchmarkSuccess 测试成功响应性能
func BenchmarkSuccess(b *testing.B) {
	app := fiber.New()

	b.Run("WithData", func(b *testing.B) {
		data := map[string]interface{}{
			"id":   "123",
			"name": "测试用户",
			"age":  25,
		}

		b.ResetTimer()
		for i := 0; i < b.N; i++ {
			ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
			_ = Success(ctx, data)
			app.ReleaseCtx(ctx)
		}
	})

	b.Run("NoData", func(b *testing.B) {
		b.ResetTimer()
		for i := 0; i < b.N; i++ {
			ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
			_ = Success(ctx, nil)
			app.ReleaseCtx(ctx)
		}
	})
}

// BenchmarkError 基准测试已被删除 - Error() 函数已在重构中移除
// 错误响应现在由全局 ErrorHandler 统一处理

// BenchmarkSuccessWithMessage 测试带自定义消息的成功响应性能
func BenchmarkSuccessWithMessage(b *testing.B) {
	app := fiber.New()

	data := map[string]interface{}{
		"id":   "123",
		"name": "测试用户",
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
		_ = SuccessWithMessage(ctx, data, "操作成功")
		app.ReleaseCtx(ctx)
	}
}
