import httpClient from '@/utils/http';

import { SchedulerSchedulerStatus, SchedulerTask, SchedulerTaskResult } from './data-contracts';
export default {
  /**
   * @description 创建一些示例定时任务
   */
  sampleTasksCreate: () => {
    return httpClient.post<Record<string, any>>(`/scheduler/sample-tasks`);
  },
  /**
   * @description 启动定时任务调度器
   */
  startCreate: () => {
    return httpClient.post<Record<string, any>>(`/scheduler/start`);
  },
  /**
   * @description 获取定时任务调度器的运行状态
   */
  statusList: () => {
    return httpClient.get<SchedulerSchedulerStatus>(`/scheduler/status`);
  },
  /**
   * @description 停止定时任务调度器
   */
  stopCreate: () => {
    return httpClient.post<Record<string, any>>(`/scheduler/stop`);
  },
  /**
   * @description 创建新的定时任务
   */
  tasksCreate: (task: SchedulerTask) => {
    return httpClient.post<Record<string, any>>(`/scheduler/tasks`, { params: task });
  },
  /**
   * @description 获取所有定时任务
   */
  tasksList: () => {
    return httpClient.get<SchedulerTask[]>(`/scheduler/tasks`);
  },
  /**
   * @description 根据任务ID获取任务详细信息
   */
  tasksDetail: (id: string) => {
    return httpClient.get<SchedulerTask>(`/scheduler/tasks/${id}`);
  },
  /**
   * @description 更新定时任务信息
   */
  tasksUpdate: (id: string, task: SchedulerTask) => {
    return httpClient.put<Record<string, any>>(`/scheduler/tasks/${id}`, { params: task });
  },
  /**
   * @description 删除指定的定时任务
   */
  tasksDelete: (id: string) => {
    return httpClient.delete<Record<string, any>>(`/scheduler/tasks/${id}`);
  },
  /**
   * @description 获取指定任务的执行结果
   */
  tasksResultsDetail: (
    id: string,
    query: {
      /** 结果数量限制 */
      page_size?: number;
    }
  ) => {
    return httpClient.get<SchedulerTaskResult[]>(`/scheduler/tasks/${id}/results`, {
      query: query
    });
  },
  /**
   * @description 立即执行指定的定时任务
   */
  tasksRunCreate: (id: string) => {
    return httpClient.post<Record<string, any>>(`/scheduler/tasks/${id}/run`);
  },
  /**
   * @description 启动指定的定时任务
   */
  tasksStartCreate: (id: string) => {
    return httpClient.post<Record<string, any>>(`/scheduler/tasks/${id}/start`);
  },
  /**
   * @description 停止指定的定时任务
   */
  tasksStopCreate: (id: string) => {
    return httpClient.post<Record<string, any>>(`/scheduler/tasks/${id}/stop`);
  }
};
