package card_info_jd

import (
	"context"
	"kami/api/card_info_jd/v1"
	"kami/internal/consts"
	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/service"

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

func (c *ControllerV1) Submit(ctx context.Context, req *v1.SubmitReq) (res *v1.SubmitRes, err error) {
	orderService := service.CardRedeemOrder()
	if _, err = orderService.AddOne(ctx, &model.RedeemCardSubmitInput{
		CardNo:      req.CardNo,
		GiftCardPwd: req.GiftCardPwd,
		NotifyUrl:   req.NotifyUrl,
		Amount:      req.Amount,
		MerchantId:  req.MerchantId,
		Attach:      req.Attach,
		Category:    consts.CardRedeemAccountCategoryJD,
	}); err == nil {
		_ = orderService.TriggerValidateAndConsume()
	}
	err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "添加账号失败")
	return
}
