import { request } from '@/service/request';

// 查询定时任务调度列表
export function listJob(query: Api.SystemManage.JobSearchParams) {
  return request<Api.SystemManage.JobList>({
    url: '/monitor/job/list',
    method: 'get',
    params: query
  });
}

// 查询定时任务调度详细
export function getJob(jobId: Api.SystemManage.Job['jobId']) {
  return request<Api.SystemManage.Job>({
    url: `/monitor/job/${jobId}`,
    method: 'get'
  });
}

// 新增定时任务调度
export function addJob(data: Api.SystemManage.Job) {
  return request({
    url: '/monitor/job',
    method: 'post',
    data
  });
}

// 修改定时任务调度
export function updateJob(data: Api.SystemManage.Job) {
  return request({
    url: '/monitor/job',
    method: 'put',
    data
  });
}

// 删除定时任务调度
export function delJob(jobIds: Api.SystemManage.Job['jobId'][]) {
  return request({
    url: `/monitor/job/${jobIds}`,
    method: 'delete'
  });
}

// 任务状态修改
export function changeJobStatus(jobId: Api.SystemManage.Job['jobId'], status: Api.SystemManage.Job['status']) {
  const data = {
    jobId,
    status
  };
  return request({
    url: '/monitor/job/changeStatus',
    method: 'put',
    data
  });
}

// 定时任务立即执行一次
export function runJob(jobId: Api.SystemManage.Job['jobId'], jobGroup: Api.SystemManage.Job['jobGroup']) {
  const data = {
    jobId,
    jobGroup
  };
  return request({
    url: '/monitor/job/run',
    method: 'put',
    data
  });
}
