/**
 * 代理充值相关 API
 */

import { BaseService } from '../BaseService'
import type {
  AgentRecharge,
  AgentRechargeQueryParams,
  AgentRechargeListResponse,
  CreateAgentRechargeRequest,
  ConfirmOfflinePaymentRequest,
  RejectAgentRechargeRequest,
  BaseResponse
} from '@/types/api'

export class AgentRechargeService extends BaseService {
  /**
   * 获取代理充值订单列表
   * @param params 查询参数
   */
  static getAgentRecharges(
    params?: AgentRechargeQueryParams
  ): Promise<BaseResponse<AgentRechargeListResponse>> {
    return this.get<BaseResponse<AgentRechargeListResponse>>('/api/admin/agent-recharges', params)
  }

  /**
   * 获取代理充值订单详情
   * @param id 充值订单ID
   */
  static getAgentRechargeById(id: number): Promise<BaseResponse<AgentRecharge>> {
    return this.getOne<AgentRecharge>(`/api/admin/agent-recharges/${id}`)
  }

  /**
   * 创建代理充值订单
   * @param data 创建充值订单请求参数
   */
  static createAgentRecharge(
    data: CreateAgentRechargeRequest
  ): Promise<BaseResponse<AgentRecharge>> {
    return this.post<BaseResponse<AgentRecharge>>('/api/admin/agent-recharges', data)
  }

  /**
   * 确认线下充值
   * @param id 充值订单ID
   * @param data 确认线下充值请求参数
   */
  static confirmOfflinePayment(
    id: number,
    data: ConfirmOfflinePaymentRequest
  ): Promise<BaseResponse<AgentRecharge>> {
    return this.post<BaseResponse<AgentRecharge>>(
      `/api/admin/agent-recharges/${id}/offline-pay`,
      data
    )
  }

  /**
   * 拒绝代理充值订单
   * @param id 充值订单ID
   * @param data 拒绝请求参数
   */
  static rejectAgentRecharge(
    id: number,
    data: RejectAgentRechargeRequest
  ): Promise<BaseResponse<void>> {
    return this.post<BaseResponse<void>>(`/api/admin/agent-recharges/${id}/reject`, data)
  }
}
