import { defHttp } from '/@/utils/http/axios';
import { ScriptParam, ScriptQueryParam, ScriptRecord } from './model/scriptModel';
import { PaginationResult } from '/#/axios';

enum ScriptManagerApi {
  SCRIPT_POST_URL = '/js',
  SCRIPT_GET_URL = '/js',
  SCRIPT_DELETE_URL = '/js',
  SCRIPT_MELIST_URL = '/js/me/list',
  SCRIPT_TEST_URL = '/js/test',
  SCRIPT_STATUS = '/js',
}

export const ScriptPage = (params: ScriptQueryParam) => {
  return defHttp.get<PaginationResult<ScriptRecord>>({
    url: ScriptManagerApi.SCRIPT_GET_URL,
    params,
  });
};

/**
 * 改变转换函数状态
 * @param params id status
 */
export const scriptPagePutApi = (id, status) =>
  defHttp.post({
    url: ScriptManagerApi.SCRIPT_STATUS + '/' + id + '/' + status,
  });

//删除脚本
export const deleteScriptManage = (ids: string[]) => {
  return defHttp.delete({
    url: ScriptManagerApi.SCRIPT_DELETE_URL,
    data: {
      ids: ids,
    },
  });
};

// 创建或编辑脚本
export const createOrEditScriptManage = (data) => {
  return defHttp.post<ScriptParam>({
    url: ScriptManagerApi.SCRIPT_POST_URL,
    data,
  });
};

// 查询脚本详情
export const getScriptManageDetail = (id: string) => {
  return defHttp.get({
    url: ScriptManagerApi.SCRIPT_GET_URL + `/${id}`,
  });
};

// 获取脚本选项列表
export const getScriptManageMeList = () => {
  return defHttp.get<ScriptRecord[]>({
    url: ScriptManagerApi.SCRIPT_MELIST_URL,
  });
};

// 测试脚本执行结果
export const testScriptManage = (data) => {
  return defHttp.post<ScriptParam>({
    url: ScriptManagerApi.SCRIPT_TEST_URL,
    data,
  });
};
