/**
 * 退款管理相关 API
 */

import { BaseService } from '../BaseService'
import type {
  Refund,
  RefundQueryParams,
  RefundListResponse,
  CreateRefundRequest,
  ApproveRefundRequest,
  RejectRefundRequest,
  ResubmitRefundRequest,
  ReturnRefundRequest,
  BaseResponse
} from '@/types/api'

export class RefundService extends BaseService {
  /**
   * 获取退款申请列表
   * @param params 查询参数
   */
  static getRefunds(params?: RefundQueryParams): Promise<BaseResponse<RefundListResponse>> {
    return this.get<BaseResponse<RefundListResponse>>('/api/admin/refunds', params)
  }

  /**
   * 获取退款申请详情
   * @param id 退款申请ID
   */
  static getRefundById(id: number): Promise<BaseResponse<Refund>> {
    return this.getOne<Refund>(`/api/admin/refunds/${id}`)
  }

  /**
   * 创建退款申请
   * @param data 创建退款申请请求参数
   */
  static createRefund(data: CreateRefundRequest): Promise<BaseResponse<Refund>> {
    return this.post<BaseResponse<Refund>>('/api/admin/refunds', data)
  }

  /**
   * 审批通过退款申请
   * @param id 退款申请ID
   * @param data 审批通过请求参数
   */
  static approveRefund(id: number, data: ApproveRefundRequest): Promise<BaseResponse<void>> {
    return this.post<BaseResponse<void>>(`/api/admin/refunds/${id}/approve`, data)
  }

  /**
   * 审批拒绝退款申请
   * @param id 退款申请ID
   * @param data 审批拒绝请求参数
   */
  static rejectRefund(id: number, data: RejectRefundRequest): Promise<BaseResponse<void>> {
    return this.post<BaseResponse<void>>(`/api/admin/refunds/${id}/reject`, data)
  }

  /**
   * 重新提交退款申请
   * @param id 退款申请ID
   * @param data 重新提交请求参数
   */
  static resubmitRefund(id: number, data: ResubmitRefundRequest): Promise<BaseResponse<void>> {
    return this.post<BaseResponse<void>>(`/api/admin/refunds/${id}/resubmit`, data)
  }

  /**
   * 退回退款申请
   * @param id 退款申请ID
   * @param data 退回请求参数
   */
  static returnRefund(id: number, data: ReturnRefundRequest): Promise<BaseResponse<void>> {
    return this.post<BaseResponse<void>>(`/api/admin/refunds/${id}/return`, data)
  }
}
