import request from '@/utils/request';
import { JobGroupForm, JobGroupQuery, JobGroupVO, ExecutorRegistry, ExecutorStatus } from './types';
import { AxiosPromise } from 'axios';

// 查询执行器列表
export function listJobGroup(query: JobGroupQuery): AxiosPromise<JobGroupVO[]> {
  return request({
    url: '/xxl-job/jobgroup/pageList',
    method: 'get',
    params: query
  });
}

// 查询执行器详细
export function getJobGroup(id: string | number): AxiosPromise<JobGroupVO> {
  return request({
    url: '/xxl-job/jobgroup/' + id,
    method: 'get'
  });
}

// 新增执行器
export function addJobGroup(data: JobGroupForm) {
  return request({
    url: '/xxl-job/jobgroup/save',
    method: 'post',
    data: data
  });
}

// 修改执行器
export function updateJobGroup(data: JobGroupForm) {
  return request({
    url: '/xxl-job/jobgroup/update',
    method: 'post',
    data: data
  });
}

// 删除执行器
export function delJobGroup(id: string | number | (string | number)[]) {
  return request({
    url: '/xxl-job/jobgroup/remove',
    method: 'post',
    data: { id }
  });
}

// 获取执行器注册信息
export function getExecutorRegistry(appname: string): AxiosPromise<ExecutorRegistry[]> {
  return request({
    url: '/xxl-job/jobgroup/loadById',
    method: 'get',
    params: { id: appname }
  });
}

// 检查执行器状态
export function checkExecutorStatus(addresses: string[]): AxiosPromise<ExecutorStatus[]> {
  return request({
    url: '/xxl-job/jobgroup/checkExecutor',
    method: 'post',
    data: { addresses }
  });
}

// 获取所有执行器列表（下拉框用）
export function getAllJobGroups(): AxiosPromise<JobGroupVO[]> {
  return request({
    url: '/xxl-job/jobgroup/list',
    method: 'get'
  });
}
