package card_info_walmart

import (
	"context"
	"kami/internal/consts"
	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/service"

	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"

	v1 "kami/api/card_info_walmart/v1"
)

func (c *ControllerV1) GroupList(ctx context.Context, req *v1.GroupListReq) (res *v1.GroupListRes, err error) {
	userInfo, err := service.SysAuth().LoginWithIFrameAndLogin(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}
	if req.UserId != "" && userInfo.Id == "" {
		userInfo.Id = req.UserId
	}
	total, data, err := service.CardRedeemAccount().GroupList(ctx, &model.RedeemAccountGroupList{
		Category:      consts.CardRedeemAccountCategoryWalMart,
		CreatedUserId: userInfo.Id,
		GroupListReq:  req,
	}, nil)
	if err != nil {
		err = gerror.WrapCode(gcode.CodeInternalPanic, err, "获取失败")
		return
	}
	res = &v1.GroupListRes{}
	res.Total = total
	res.List = data
	return
}
