/**
 * 手动触发相关 API
 */

import { BaseService } from '../BaseService'
import type {
  ManualTriggerLog,
  BatchManualTriggerRequest,
  ConditionManualTriggerRequest,
  SingleManualTriggerRequest,
  CancelManualTriggerRequest,
  ManualTriggerHistoryQueryParams,
  ManualTriggerHistoryResponse,
  ManualTriggerStatusResponse,
  BaseResponse
} from '@/types/api'

export class ManualTriggerService extends BaseService {
  /**
   * 批量手动触发
   * POST /api/admin/polling-manual-trigger/batch
   */
  static batchTrigger(data: BatchManualTriggerRequest): Promise<BaseResponse<ManualTriggerLog>> {
    return this.post<BaseResponse<ManualTriggerLog>>(
      '/api/admin/polling-manual-trigger/batch',
      data
    )
  }

  /**
   * 条件筛选触发
   * POST /api/admin/polling-manual-trigger/by-condition
   */
  static conditionTrigger(
    data: ConditionManualTriggerRequest
  ): Promise<BaseResponse<ManualTriggerLog>> {
    return this.post<BaseResponse<ManualTriggerLog>>(
      '/api/admin/polling-manual-trigger/by-condition',
      data
    )
  }

  /**
   * 单卡手动触发
   * POST /api/admin/polling-manual-trigger/single
   */
  static singleTrigger(data: SingleManualTriggerRequest): Promise<BaseResponse<ManualTriggerLog>> {
    return this.post<BaseResponse<ManualTriggerLog>>(
      '/api/admin/polling-manual-trigger/single',
      data
    )
  }

  /**
   * 取消手动触发任务
   * POST /api/admin/polling-manual-trigger/cancel
   */
  static cancelTrigger(data: CancelManualTriggerRequest): Promise<BaseResponse<void>> {
    return this.post<BaseResponse<void>>('/api/admin/polling-manual-trigger/cancel', data)
  }

  /**
   * 获取手动触发历史
   * GET /api/admin/polling-manual-trigger/history
   */
  static getHistory(
    params?: ManualTriggerHistoryQueryParams
  ): Promise<BaseResponse<ManualTriggerHistoryResponse>> {
    return this.get<BaseResponse<ManualTriggerHistoryResponse>>(
      '/api/admin/polling-manual-trigger/history',
      params
    )
  }

  /**
   * 获取手动触发状态
   * GET /api/admin/polling-manual-trigger/status
   */
  static getStatus(): Promise<BaseResponse<ManualTriggerStatusResponse>> {
    return this.get<BaseResponse<ManualTriggerStatusResponse>>(
      '/api/admin/polling-manual-trigger/status'
    )
  }
}
