import axios from 'axios';

const request = axios.create({
  // 腾讯云测试环境
  baseURL: 'http://aihub-dag-test.digitalyili.com',
  // 本地开发
  // baseURL: 'http://192.168.199.110:18082',
  // 电信云测试环境
  // baseURL: 'http://aihub-dag-idctest.digitalyili.com',
  // sxkj
  // baseURL: 'http://aihub-dag.sxkj.com',
  timeout: 1200000,
  headers: {
    'Content-Type': 'application/json;charset=UTF-8',
    Accept: 'application/json'
  }
});

// 请求拦截器
request.interceptors.request.use((config: any) => {
  config.headers['user-token'] = localStorage.getItem('user_token');
  config.headers['item-token'] = localStorage.getItem('project_token');
  config.headers.Authorization = localStorage.getItem('AI.jpt_token');
  return config;
});

// 获取调试数据表
export const getDebugTable = (params: any) =>
  request({
    url: `/jpt/datamanagement/`,
    method: 'get',
    params
  });

export const getLocalDebugTable = () =>
  request({
    url: `/jpt/datasource/ailab_table`,
    method: 'get'
  });

// 获取中间数据列表
export const getIntermediate = (params: any) =>
  request({
    url: `/jpt/intermediate/get_intermediate`,
    method: 'get',
    params
  });

// 获取文件信息
export const getFileData = (params: any) =>
  request({
    url: `/jpt/files`,
    method: 'get',
    params
  });

// 代码校验
export const codeCheck = (params: any) =>
  request({
    url: `/jpt/code_check`,
    method: 'post',
    params
  });

// 执行代码
export const executeDag = (params: any) =>
  request({
    url: `/jpt/dag/execute`,
    method: 'post',
    data: params
  });

// 节点状态
export const debugStatus = (uuid: string) =>
  request({
    url: `/jpt/dag/debug_status?dag_uuid=${uuid}`,
    method: 'get'
  });

// 节点日志
export const getNodeLog = (params: any) =>
  request({
    url: `/jpt/dag/node_log?dag_uuid=${params.dag_uuid}&node_id=${params.node_id}`,
    method: 'get'
  });

// 节点中间结果
export const getNodeResult = (params: any) =>
  request({
    url: `/jpt/dag/node_result?dag_uuid=${params.dag_uuid}&node_id=${params.node_id}&out_pin=${params.out_pin}`,
    method: 'get'
  });

// 节点中间结果
export const uploadFile = (params: any) =>
  request({
    url: '/jpt/files/upload_file',
    method: 'post',
    data: params
  });

//中间结果另存为
export const saveNodeTable = (params: any) =>
  request({
    url: '/jpt/datamanagement/',
    method: 'post',
    data: params
  });

//中间结果另存为
export const getSchema = (table_name: string) =>
  request({
    url: `/jpt/datamanagement/table_schema?table_name=${table_name}`,
    method: 'get'
  });

// sql数据源表预览
export const getSqlDsTable = (table_name: string) =>
  request({
    url: `/jpt/datamanagement/table_content?table_name=${table_name}&page=${1}&size=${100}`,
    method: 'get'
  });

export const postRequirements = (params: any) =>
  request({
    url: `/jpt/dag/install_requirements`,
    method: 'post',
    data: params
  });

export const getRequirementsStatus = (id: string) =>
  request({
    url: `/jpt/dag/requirements_status?dag_uuid=${id}`,
    method: 'get'
  });
