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"

	"kami/api/card_info_walmart/v1"
)

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