/**
 * 队列任务管理 API（业务/基础设施共用，靠 category 区分）
 */
import { requestClient } from '#/api/request';

const prefix = 'queue-job/';

export async function getQueueJobList(data: any) {
  return requestClient.get<any>(`${prefix}list`, { params: data });
}

export async function getQueueJobDetail(id: number) {
  return requestClient.get<any>(`${prefix}detail`, { params: { id } });
}

/**
 * 某任务的取消/重跑操作记录
 */
export async function getQueueJobOpLogList(id: number) {
  return requestClient.get<any>(`${prefix}op-log-list`, { params: { id } });
}

export async function getQueueJobStatusOption() {
  return requestClient.get<{ value: number; label: string }[]>(
    `${prefix}status-option`,
  );
}

export async function getQueueJobNameOption(category: number) {
  return requestClient.get<{ value: string; label: string }[]>(
    `${prefix}job-name-option`,
    { params: { category } },
  );
}

/**
 * 取消排队中任务
 */
export async function cancelQueueJob(id: number) {
  return requestClient.post<any>(`${prefix}cancel`, { id });
}

/**
 * 失败/取消后重跑
 */
export async function retryQueueJob(id: number) {
  return requestClient.post<any>(`${prefix}retry`, { id });
}
