import http from '@/utils/request'

const metadata = {
  metadataAdd: params => http.post('/meta/node/add', params),
  metadataUpdate: params => http.post('/meta/node/update', params),
  deleteMetadata: params => http.post('/meta/node/delete', params),
  getMetadataDetails: params => http.post('/meta/node/edit', params),
  getMetaDataList: params => http.post('/meta/node/list', params),
  getMetaDataGraph: params => http.post('/meta/node/graph', params),
  createAuditRecord: params => http.post('/meta/review/create', params)
}

const dataLabel = {
  dataLabelList: params => http.post('/interface/data/label/list', params),
  dataLabelAdd: params => http.post('/interface/data/label/add', params),
  dataLabelDetails: params => http.post('/interface/data/label/detail', params),
  dataLabelGraph: params => http.post('/interface/data/label/graph/all', params),
  dataLabelIdentifyGroup: params => http.post('/interface/data/label/dynamic/identify', params),
  deleteDataLabel: params => http.post('/interface/data/label/delete', params)
}

const dataStandard = {
  dataStandardList: params => http.post('/interface/data/standard/list', params),
  dataStandardAdd: params => http.post('/interface/data/standard/add', params),
  dataStandardDetails: params => http.post('/interface/data/standard/detail', params),
  dataStandardCodeGenerate: params => http.post('/interface/data/standard/code', params),
  dataStandardGraph: params => http.post('/interface/data/standard/graph/all', params)
}

// DataFlow 只负责定义、关系、脚本元信息和血缘；执行由 n8n Workflow 承担。
const dataFlow = {
  getDataFlowList: params => http.get('/dataflow/get-dataflows-list', params),
  getDataFlowDetails: id => http.get(`/dataflow/get-dataflow/${id}`),
  addDataFlow: params => http.post('/dataflow/add-dataflow', params),
  updateDataFlow: (id, params) => http.put(`/dataflow/update-dataflow/${id}`, params),
  deleteDataFlow: id => http.del(`/dataflow/delete-dataflow/${id}`),
  getDataFlowScriptContent: dataflowId => http.get(`/dataflow/get-script/${dataflowId}`)
}

const businessDomain = {
  getBusinessDomainList: params => http.post('/bd/list', params),
  getBusinessDomainDetail: params => http.post('/bd/detail', params),
  deleteBusinessDomain: params => http.post('/bd/delete', params),
  saveBusinessDomain: params => http.post('/bd/save', params),
  updateBusinessDomain: params => http.post('/bd/update', params),
  uploadFile: params => http.upload('/bd/upload', params),
  downloadFile: params => http.getDownload('/bd/download', params),
  getBusinessDomainGraph: params => http.post('/bd/graphall', params),
  parseDDLFile: params => http.upload('/bd/ddlparse', params),
  searchAssociatedMetadata: params => http.post('/bd/search', params),
  combinationCreateBusinessDomain: params => http.post('/bd/compose', params)
}

const shared = {
  graphDataDelete: params => http.post('/interface/metric/label/standard/delete', params),
  getBusinessDomainList2: () => http.get('/dataflow/get-BD-list'),
  getLabelList: params => http.post('/interface/labellist', params),
  getGraphAll: params => http.post('/interface/graphall', params)
}

export const api = {
  ...metadata,
  ...dataLabel,
  ...dataStandard,
  ...dataFlow,
  ...businessDomain,
  ...shared
}
