package jd_cookie

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

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

// CreateOrder 创建订单
func (c *ControllerV1) CreateOrder(ctx context.Context, req *v1.CreateOrderReq) (res *v1.CreateOrderRes, err error) {
	createOrderReq := &model.CreateOrderReq{
		UserOrderId: req.UserOrderId,
		Amount:      req.Amount,
		Category:    req.Category,
	}
	result, err := service.JdCookie().CreateOrder(ctx, createOrderReq)
	if err != nil {
		return nil, gerror.WrapCode(gcode.CodeInternalError, err, "创建订单失败")
	}

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