import { defHttp } from '/@/utils/http/axios';
import { ReportModel, ReportQueryParam } from './model/schedueModel';

enum ReportManagerApi {
  GET_REPORT_API = '/monitor/job/page',
  POST_REPORT_API = '/monitor/job/add',
  DELETE_REPORT_API = '/monitor/job',
  PUT_REPORT_API = '/monitor/job/update',
  PUTID_REPORT_API = '/monitor/job',
  RUN_REPORT_API = '/monitor/job/run',
  JOB_LOG_DETAIL_API = '/monitor/job_log/get/',
  JOB_LOG_PAGE_API = '/monitor/job_log/page',
  DELETE_LOG_API = '/monitor/job_log',
  POST_LOG_CLEAN_API = '/monitor/job_log/clean',
  QUERY_CORN_API = '/monitor/job/query_cron_expression/',
  CHECK_CORN_API = '/monitor/job/check_cron/',
}

//分页
export const scheduePage = (params: ReportQueryParam) => {
  return defHttp.get<ReportQueryParam>({
    url: ReportManagerApi.GET_REPORT_API,
    params,
  });
};

//删除
export const deleteSchedueManage = (ids: string[]) => {
  return defHttp.delete({
    url: ReportManagerApi.DELETE_REPORT_API,
    data: {
      ids: ids,
    },
  });
};

// 创建
export const createOrEditSchedueManage = (data) => {
  return defHttp.post<ReportModel>({
    url: ReportManagerApi.POST_REPORT_API,
    data,
  });
};

// 编辑
export const putSchedueConfigManage = (data) => {
  return defHttp.post<ReportModel>({
    url: ReportManagerApi.PUT_REPORT_API,
    data,
  });
};

// 修改状态 id status
export const putSchedueByidAndStatusManage = (id, status) => {
  return defHttp.put<ReportModel>({
    url: ReportManagerApi.PUTID_REPORT_API + '/change_status/' + id + '/' + status,
  });
};
//执行一次
export const postRunSchedueConfigManage = (id) => {
  return defHttp.post<ReportModel>({
    url: ReportManagerApi.RUN_REPORT_API + '/' + id,
  });
};

// 查询cron表达式近5次的执行时间
export const schedueQueryCornTimeApi = (corn) => {
  return defHttp.get({
    url: ReportManagerApi.QUERY_CORN_API + corn,
  });
};

// 检查cron表达式是否有效
export const schedueCheckCornApi = (corn) => {
  return defHttp.get({
    url: ReportManagerApi.CHECK_CORN_API + corn,
  });
};

/**
 * 调度日志
 */

//分页
export const schedueLogPage = (params: ReportQueryParam) => {
  return defHttp.get<ReportQueryParam>({
    url: ReportManagerApi.JOB_LOG_PAGE_API,
    params,
  });
};

//删除
export const deleteSchedueLogManage = (ids: string[]) => {
  return defHttp.delete({
    url: ReportManagerApi.DELETE_LOG_API,
    data: {
      ids: ids,
    },
  });
};

// 清空
export const schedueLogCleanPage = () => {
  return defHttp.post<ReportModel>({
    url: ReportManagerApi.POST_LOG_CLEAN_API,
  });
};

//详情
export const schedueLogDetailPage = (jobId, id) => {
  return defHttp.get<ReportQueryParam>({
    url: ReportManagerApi.JOB_LOG_DETAIL_API + '/' + jobId + '/' + id,
  });
};
