package card_info_walmart

import (
	"context"
	"kami/internal/consts"
	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/service"

	"github.com/gogf/gf/v2/os/glog"

	v1 "kami/api/card_info_walmart/v1"

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

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