package card_info_apple

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

	v1 "kami/api/card_info_apple/v1"

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

func (c *ControllerV1) RechargeDuplicatedCardPass(ctx context.Context, req *v1.RechargeDuplicatedCardPassReq) (res *v1.RechargeDuplicatedCardPassRes, err error) {
	orderService := service.AppleOrder()
	data, err := orderService.GetOneByOrderNo(ctx, req.OrderNo, nil)
	if err != nil || data.OrderNo == "" {
		return nil, gerror.NewCode(gcode.CodeNotFound, "当前订单不存在")
	}
	if data.Status != int(consts.AppleRechargeOrderCardNoOrCardPassDuplicated) {
		return nil, gerror.NewCode(gcode.CodeNotFound, "当前订单状态不正确")
	}
	t := consts.AppleRechargeOrderAmountDifferent
	previousOrder, err := orderService.QueryOneByCardPass(ctx, data.CardPass, &t)
	if err != nil || previousOrder.OrderNo == "" {
		return nil, gerror.NewCode(gcode.CodeNotFound, "金额异议订单不存在")
	}
	//err = orderService.UpdateActualAmountAndHistory(ctx, &model.UpdateAmountAndHistoryRecord{
	//	OrderInfo: &model.UpdateAmountRecord{
	//		OrderNo: data.OrderNo,
	//		Amount:  previousOrder.ActualAmount,
	//		Status:  consts.AppleRechargeOrderSuccess,
	//		Remark:  "金额异议订单二次回调",
	//	},
	//	HistoryOperation: consts.AppleRechargeOperationHandleActualAmountSuccess,
	//	HistoryRemark:    "手动修改订单成功",
	//}, nil)
	//if err != nil {
	//	return nil, errHandler.WrapError(ctx, gcode.CodeInternalError, err, "修改订单失败")
	//}
	// _ = orderService.CallBackOrderToUpstream(ctx, req.OrderNo)
	return
}
