package card_info_walmart

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

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

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

	"kami/api/card_info_walmart/v1"
)

func (c *ControllerV1) OrderStatusReset(ctx context.Context, req *v1.OrderStatusResetReq) (res *v1.OrderStatusResetRes, err error) {
	orderEntity, err := service.CardRedeemOrder().GetOrderOneByOrderNo(ctx, req.ID, nil)
	if err != nil {
		err = gerror.Wrap(err, "获取账户信息失败")
		return
	}
	if consts.RedeemOrderStatus(orderEntity.Status) != consts.RedeemOrderForbiddenByMaxLimit {
		return res, errHandler.WrapError(ctx, gcode.CodeOperationFailed, gerror.New("订单状态不是最大限制状态"), "订单状态不是最大限制状态")
	}
	_ = service.CardRedeemOrder().UpdateStatus(ctx, orderEntity.OrderNo, consts.RedeemOrderPending, "手动修正订单状态", nil)
	_ = service.CardRedeemOrder().UpdateOrderStatus(ctx, orderEntity.OrderNo, consts.RedeemOrderPending, nil)
	_ = service.CardRedeemOrder().SetCallBackCount(ctx, orderEntity.OrderNo, 0, nil)
	return
}
