package card_info_apple

import (
	"context"
	"kami/api/commonApi"
	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/model/entity"
	"kami/internal/service"

	"kami/api/card_info_apple/v1"

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

func (c *ControllerV1) RechargeList(ctx context.Context, req *v1.RechargeListReq) (res *v1.RechargeListRes, err error) {
	userInfo, err := service.SysAuth().LoginWithIFrameAndLogin(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}
	rechargeOrderService := service.AppleOrder()
	total, list, err := rechargeOrderService.List(ctx, model.AppleCardRechargeParamsInput{
		RechargeListReq: *req,
		UserId:          userInfo.Id,
	})
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeDbOperationError, err, "")
		return
	}
	res = &v1.RechargeListRes{
		CommonPageRes: commonApi.CommonPageRes[entity.V1CardAppleRechargeInfo]{
			Total: total,
			CommonDataRes: commonApi.CommonDataRes[entity.V1CardAppleRechargeInfo]{
				List: list,
			},
		},
	}
	return
}
