package card_info_apple

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

	"github.com/jinzhu/copier"

	"kami/api/card_info_apple/v1"

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

func (c *ControllerV1) CardHistoryInfoList(ctx context.Context, req *v1.CardHistoryInfoListReq) (res *v1.CardHistoryInfoListRes, err error) {
	userInfo, err := service.SysAuth().LoginWithIFrameAndLogin(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}
	appleCardService := service.AppleAccount()
	total, data, err := appleCardService.GetWalletHistory(ctx, model.CardAppleAccountHistoryQueryInput{
		CardHistoryInfoListReq: req,
		UserId:                 userInfo.Id,
	})
	res = &v1.CardHistoryInfoListRes{
		CommonPageRes: commonApi.CommonPageRes[v1.CardHistoryModel]{
			Total: total,
			CommonDataRes: commonApi.CommonDataRes[v1.CardHistoryModel]{
				List: make([]v1.CardHistoryModel, 0),
			},
		},
	}
	_ = copier.CopyWithOption(&res.List, &data, copier.Option{IgnoreEmpty: true, DeepCopy: true})
	return
}
