package card_info_apple

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

	"kami/api/card_info_apple/v1"
)

func (c *ControllerV1) RechargeSubmitQuery(ctx context.Context, req *v1.RechargeSubmitQueryReq) (res *v1.RechargeSubmitQueryRes, err error) {
	appleRechargeService := service.AppleOrder()
	status, err := appleRechargeService.GetRechargeStatusByOrderNo(ctx, req.OrderNo)
	if err != nil {
		return &v1.RechargeSubmitQueryRes{
			Status:  0,
			Message: "订单查询失败",
		}, nil
	}
	switch consts.AppleRechargeOrderStatus(status) {
	case consts.AppleRechargeOrderSuccess:
		return &v1.RechargeSubmitQueryRes{
			Status:  consts.AppleRechargeOrderSuccess,
			Message: "充值成功",
		}, nil
	case consts.AppleRechargeOrderFail:
		return &v1.RechargeSubmitQueryRes{
			Status:  consts.AppleRechargeOrderFail,
			Message: "充值失败或订单不存在",
		}, nil
	default:
		return &v1.RechargeSubmitQueryRes{
			Status:  consts.AppleRechargeOrderSuccess,
			Message: "订单正在处理中，具体状态请查看订单详情",
		}, nil
	}
}
