package router

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/user-management-system/internal/api/handler"
)

// TestRouter_NewRouter 测试 router 创建
func TestRouter_NewRouter(t *testing.T) {
	// 创建不带 avatar handler 的 router
	router1 := NewRouter(
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil,
	)
	assert.NotNil(t, router1)
	assert.Nil(t, router1.avatarHandler)

	// 创建带 avatar handler 的 router
	avatarHandler := &handler.AvatarHandler{}
	router2 := NewRouter(
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil,
		avatarHandler,
	)
	assert.NotNil(t, router2)
	assert.NotNil(t, router2.avatarHandler)
}

// TestRouter_StructFields 测试 router 结构体字段
func TestRouter_StructFields(t *testing.T) {
	router := NewRouter(
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil, nil, nil,
		nil, nil, nil, nil,
	)

	// 验证所有字段都被正确设置（即使为 nil）
	assert.NotNil(t, router.engine)
	assert.Nil(t, router.authHandler)
	assert.Nil(t, router.userHandler)
	assert.Nil(t, router.roleHandler)
	assert.Nil(t, router.permissionHandler)
	assert.Nil(t, router.deviceHandler)
	assert.Nil(t, router.logHandler)
	assert.Nil(t, router.authMiddleware)
	assert.Nil(t, router.rateLimitMiddleware)
	assert.Nil(t, router.opLogMiddleware)
	assert.Nil(t, router.ipFilterMiddleware)
}
