package gamemanagement

import (
	"context"

	"hyapp-admin-server/internal/integration/userclient"
)

func (h *Handler) enrichDiceRobotProfiles(ctx context.Context, requestID string, items []diceRobotDTO) error {
	if h.user == nil || len(items) == 0 {
		return nil
	}
	userIDs := make([]int64, 0, len(items))
	for _, item := range items {
		if item.UserIDNumber > 0 {
			userIDs = append(userIDs, item.UserIDNumber)
		}
	}
	if len(userIDs) == 0 {
		return nil
	}

	// 机器人登记表只拥有游戏侧启停事实；头像、昵称和短 ID 仍以 user-service 用户主数据为准。
	users, err := h.user.BatchGetUsers(ctx, userclient.BatchGetUsersRequest{
		RequestID: requestID,
		Caller:    "admin-server",
		UserIDs:   userIDs,
	})
	if err != nil {
		return err
	}
	for index := range items {
		user := users[items[index].UserIDNumber]
		if user == nil {
			continue
		}
		items[index].ShortID = user.DisplayUserID
		items[index].Nickname = user.Username
		items[index].Avatar = user.Avatar
	}
	return nil
}
