/**
 * 订单管理相关 API
 */

import { BaseService } from '../BaseService'
import type {
  Order,
  OrderQueryParams,
  OrderListResponse,
  CreateOrderRequest,
  CreateOrderResponse,
  BaseResponse
} from '@/types/api'

export class OrderService extends BaseService {
  /**
   * 获取订单列表
   * @param params 查询参数
   */
  static getOrders(params?: OrderQueryParams): Promise<BaseResponse<OrderListResponse>> {
    return this.get<BaseResponse<OrderListResponse>>('/api/admin/orders', params)
  }

  /**
   * 获取订单详情
   * @param id 订单ID
   */
  static getOrderById(id: number): Promise<BaseResponse<Order>> {
    return this.getOne<Order>(`/api/admin/orders/${id}`)
  }

  /**
   * 创建订单
   * @param data 创建订单请求参数
   */
  static createOrder(data: CreateOrderRequest): Promise<BaseResponse<CreateOrderResponse>> {
    return this.post<BaseResponse<CreateOrderResponse>>('/api/admin/orders', data)
  }

  /**
   * 取消订单
   * @param id 订单ID
   */
  static cancelOrder(id: number): Promise<BaseResponse> {
    return this.post<BaseResponse>(`/api/admin/orders/${id}/cancel`, {})
  }
}
