package card_info_c_trip

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

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

func (c *ControllerV1) Submit(ctx context.Context, req *v1.SubmitReq) (res *v1.SubmitRes, err error) {
	orderService := service.CardRedeemOrder()
	glog.Info(ctx, "接收到的请求", req)
	if _, err2 := 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.CardRedeemAccountCategoryCTrip,
	}); err2 == nil {
		_ = orderService.TriggerValidateAndConsume()
	}
	err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "添加账号失败")
	return
}
