package shared

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/gin-gonic/gin"
	"hyapp-admin-server/internal/model"
)

func TestListOptionsParsesTeamID(t *testing.T) {
	gin.SetMode(gin.TestMode)
	req := httptest.NewRequest(http.MethodGet, "/users?page=2&page_size=20&team_id=2", nil)
	ctx, _ := gin.CreateTestContext(httptest.NewRecorder())
	ctx.Request = req

	options := ListOptions(ctx)
	if options.Page != 2 || options.PageSize != 20 || options.TeamID != model.TeamOperationsID {
		t.Fatalf("list options mismatch: %+v", options)
	}
}

func TestUserDTOUsesTeamRecordName(t *testing.T) {
	teamID := model.TeamOperationsID
	dto := UserDTO(model.User{
		ID:       7,
		Username: "ops",
		Name:     "Ops",
		Team:     "平台运营",
		TeamID:   &teamID,
		TeamRecord: model.Team{
			ID:   model.TeamOperationsID,
			Name: "运营团队",
		},
		Status: model.UserStatusActive,
	})

	if dto["team"] != "运营团队" || dto["teamName"] != "运营团队" {
		t.Fatalf("team display mismatch: %+v", dto)
	}
	if got, ok := dto["teamId"].(*uint); !ok || got == nil || *got != model.TeamOperationsID {
		t.Fatalf("team id mismatch: %#v", dto["teamId"])
	}
}
