import request from '@/assets/js/utils/request'
import getUrl from '@/assets/js/utils/get-url'

// 获取知识库列表
export function docManageDataset(data) {
  return request({
    url: getUrl('/datasets/list'),
    method: 'post',
    data
  })
}
//单一知识库详情
export function getDatasetById(params) {
  return request({
    url: getUrl('/datasets/query'),
    method: 'get',
    params: params
  })
}
// 知识库内容修改
export function datasetUpdate(data) {
  return request({
    url: getUrl('/datasets/update'),
    method: 'post',
    data
  })
}
// 知识库新增
export function datasetCreate(data) {
  return request({
    url: getUrl('/datasetsEx/create'),
    method: 'post',
    data
  })
}
// 知识库删除
export function datasetDelete(data) {
  return request({
    url: getUrl(`/datasetsEx/delete?id=${data.id}`),
    method: 'delete'
  })
}
export function datasetsExPages(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/page`),
    method: 'post',
    data
  })
}

export function datasetsExTaskPages(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/taskPage`),
    method: 'post',
    data
  })
}

//minerU  获取bbox
export function minerUBbox(params) {
  return request({
    url: getUrl('/document/mineru/bbox_json'),
    method: 'get',
    params: params
  })
}
//minerU  重试
export function minerURetry(params) {
  return request({
    url: getUrl('/document/mineru/retry'),
    method: 'get',
    params: params,
    noLoading: true
  })
}
//minerU  获取文档处理状态
export function minerUQuery(params) {
  return request({
    url: getUrl('/dataset/document/query'),
    method: 'get',
    params: params,
    noLoading: true
  })
}
//minerU 获取markdown
export function minerUMarkDown(params) {
  return getUrl(`/document/mineru/md?documentId=${params.documentId}`)
}

// minerU 获取pdf
export function getPdfUrl(params) {
  return getUrl(`/datasetDocumentEx/preview?id=${params.documentId}`)
}

export function minerUMarkDownUpdate(data) {
  return request({
    url: getUrl(`/document/mineru/md/update`),
    method: 'post',
    data
  })
}
// 规则分页
export function getRulesPage(data) {
  return request({
    url: getUrl(`/rules/page`),
    method: 'post',
    data
  })
}
export function getRulesList(data) {
  return request({
    url: getUrl(`/rules/list`),
    method: 'post',
    data
  })
}
// 拆分规则-新增
export function addRuleSplit(data) {
  return request({
    url: getUrl(`/ruleDocSplitEx/create`),
    method: 'post',
    data
  })
}
// 拆分规则-详情
export function getRuleDetail(id) {
  return request({
    url: getUrl(`/rulesEx/query?id=${id}`),
    method: 'get'
  })
}
// 拆分规则-编辑
export function updateRuleSplit(data) {
  return request({
    url: getUrl(`/ruleDocSplitEx/update`),
    method: 'post',
    data
  })
}
// 拆分规则-下一步校验
export function execSplit(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/execSplit`),
    method: 'post',
    data
  })
}
// 拆分结果预览
export function splitResultPreview(params) {
  return request({
    url: getUrl(`/datasetDocumentEx/split/preview`),
    method: 'get',
    params: params
  })
}
// 题词-新增
export function addRuleExtract(data) {
  return request({
    url: getUrl(`/ruleAttributeExtractEx/create`),
    method: 'post',
    data
  })
}
// 题词-编辑
export function updateRuleExtractSplit(data) {
  return request({
    url: getUrl(`/ruleAttributeExtractEx/update`),
    method: 'post',
    data
  })
}
// 题词-下一步校验
export function execExtract(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/execExtract`),
    method: 'post',
    data
  })
}

// 题词-查询题词结果详情
export function getExtractResultList(data) {
  return request({
    url: getUrl(`/document/attribute/extract/result/list`),
    method: 'post',
    data
  })
}

// 题词-保存
export function saveContentToDocument(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/saveContentToDocument`),
    method: 'post',
    data
  })
}
//知识库文件上传-自定义
export function uploadFileByCustom(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/uploadFileByCustom`),
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
//知识库文件上传-通用
export function uploadFileByTemplate(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/uploadFileByTemplate`),
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 知识库文件详情
export function datasetQuerySegments(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/querySegments`),
    method: 'get',
    params: data
  })
}
// 知识文档详情查询（包含json的题词和拆分规则）
export function datasetDocumentEx(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/query`),
    method: 'get',
    params: data
  })
}
// 任务轨迹查看详情
export function getTaskDetail(params) {
  return request({
    url: getUrl(`/datasetDocumentEx/query`),
    method: 'get',
    params
  })
}
// 知识库文件删除
export function datasetQueryDelete(data) {
  return request({
    url: getUrl(`/datasetDocumentEx/delete?documentId=${data.id}`),
    method: 'delete'
  })
}

export function queryTask(params) {
  return request({
    url: getUrl(`/datasetDocumentEx/queryTask`),
    method: 'get',
    params
  })
}

// 识别页面表格

export function imageRetry(data) {
  return request({
    url: getUrl(`/document/mineru/img/retry`),
    method: 'post',
    data,
    noLoading: true
  })
}

export function getMd_info(params) {
  return request({
    url: getUrl(`/document/mineru/md_info`),
    method: 'get',
    params,
    noLoading: true
  })
}
export function mdIndex(params) {
  return request({
    url: getUrl(`/document/mineru/md`),
    method: 'get',
    params,
    noLoading: true,
    back: true
  })
}
