package jd_cookie

import (
	"context"
	"kami/api/jd_cookie/v1"
	"kami/internal/errHandler"
	"kami/internal/service"

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

// GetPaymentUrl 获取支付链接
func (c *ControllerV1) GetPaymentUrl(ctx context.Context, req *v1.GetPaymentUrlReq) (res *v1.GetPaymentUrlRes, err error) {
	_, err = service.SysAuth().LoginOnlyIFrame(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}

	result, err := service.JdCookie().GetPaymentUrl(ctx, "", req.OrderId)
	if err != nil {
		return nil, gerror.WrapCode(gcode.CodeInternalError, err, "获取支付链接失败")
	}

	res = &v1.GetPaymentUrlRes{
		WxPayUrl:  result.WxPayUrl,
		JdOrderId: result.JdOrderId,
		OrderId:   result.OrderId,
	}
	return
}
