/**
 * 查询订单支付状态 API
 * 基于 Universal_Payment_Module v4.0 设计
 * 
 * GET /api/payment/status/{orderSn}
 */

import { type NextRequest, NextResponse } from "next/server"

export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ orderSn: string }> }
) {
  try {
    const { orderSn } = await params

    if (!orderSn) {
      return NextResponse.json(
        { code: 400, message: "缺少订单号", data: null },
        { status: 400 }
      )
    }

    // TODO: 从数据库查询订单状态
    // const order = await OrderService.getByOrderSn(orderSn)
    
    // 模拟返回数据（开发测试用）
    const mockOrder = {
      orderSn,
      status: "created", // created | paying | paid | closed | refunded
      paidAmount: null,
      paidAt: null,
      paymentMethod: null,
      tradeSn: null,
    }

    return NextResponse.json({
      code: 200,
      message: "success",
      data: mockOrder,
    })
  } catch (error) {
    console.error("[Payment] Query status error:", error)
    return NextResponse.json(
      {
        code: 500,
        message: error instanceof Error ? error.message : "服务器错误",
        data: null,
      },
      { status: 500 }
    )
  }
}
