package sys_payment

import (
	"context"

	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/service"

	"kami/api/sys_payment/v1"

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

func (c *ControllerV1) SysPaymentRecordsGetStatistics(ctx context.Context, req *v1.SysPaymentRecordsGetStatisticsReq) (res *v1.SysPaymentRecordsGetStatisticsRes, err error) {
	currentUserId := ""
	userInfo, err := service.SysAuth().LoginWithIFrameAndLogin(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}
	currentUserId = userInfo.Id
	data, err := service.SysUserPayment().GetDetailById(ctx, &model.SysUserPaymentGetOneInput{
		UserId: currentUserId,
	})
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "获取用户信息失败")
		return
	}
	total, _, err := service.AppleAccount().List(ctx, &model.CardInfoParamsInput{
		UploadUserId: currentUserId,
	})
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "获取用户信息失败")
		return
	}
	res = &v1.SysPaymentRecordsGetStatisticsRes{
		Payment:           data,
		AppleAccountCount: total,
	}
	return
}
