import request from "@/utils/request";

// 查询报表定义列表（分页）
export function listReportDefinition(query) {
  return request({
    url: "/erp/report/definition/list",
    method: "get",
    params: query
  });
}

// 查询报表定义详情
export function getReportDefinition(id) {
  return request({
    url: `/erp/report/definition/${id}`,
    method: "get"
  });
}

// 新增报表定义
export function addReportDefinition(data) {
  return request({
    url: "/erp/report/definition",
    method: "post",
    data
  });
}

// 修改报表定义
export function updateReportDefinition(data) {
  return request({
    url: "/erp/report/definition",
    method: "put",
    data
  });
}

// 发布报表定义
export function publishReportDefinition(id) {
  return request({
    url: `/erp/report/definition/${id}/publish`,
    method: "post"
  });
}

// 重建已发布报表菜单
export function rebuildPublishedReportMenus() {
  return request({
    url: "/erp/report/definition/rebuildMenus",
    method: "post"
  });
}

// 删除报表定义
export function deleteReportDefinition(id) {
  return request({
    url: `/erp/report/definition/${id}`,
    method: "delete"
  });
}

// 查询报表设计配置
export function getReportDesign(reportId) {
  return request({
    url: `/erp/report/design/${reportId}`,
    method: "get"
  });
}

// 保存报表设计配置
export function saveReportDesign(reportId, data) {
  return request({
    url: `/erp/report/design/${reportId}`,
    method: "post",
    data
  });
}

// 手动补算报表聚合
export function rebuildReportAggregate(reportId, data) {
  return request({
    url: `/erp/report/aggregate/${reportId}/rebuild`,
    method: "post",
    data
  });
}

// 查询低代码可选业务表（白名单）
export function listReportMetaTables() {
  return request({
    url: "/erp/report/meta/tables",
    method: "get"
  });
}

// 查询指定业务表可选字段（白名单）
export function listReportMetaFields(tableName) {
  return request({
    url: "/erp/report/meta/fields",
    method: "get",
    params: { table: tableName }
  });
}

// 资产中心模板列表
export function listReportAssetTemplates() {
  return request({
    url: "/erp/report/meta/assets/templates",
    method: "get"
  });
}

// 资产中心指标列表
export function listReportAssetMetrics() {
  return request({
    url: "/erp/report/meta/assets/metrics",
    method: "get"
  });
}

// 按报表诊断并补建菜单
export function menuDiagnosticByReportId(id) {
  return request({
    url: `/erp/report/definition/${id}/menuDiagnostic`,
    method: "get"
  });
}
