import Content from '@/sheep/layouts/content.vue';
import { request } from '@/sheep/request';
import { CRUD } from '@/sheep/request/crud';
import $storage from '@/sheep/utils/storage';

const route = {
  path: 'data',
  name: 'shop.admin.data',
  component: Content,
  meta: {
    title: '数据',
  },
  children: [
    {
      path: 'report',
      name: 'shop.admin.data.report',
      component: () => import('@/app/shop/admin/data/report/index.vue'),
      meta: {
        title: '数据报表',
      },
    },
  ],
};
const userInfo = $storage.get('userInfo');

const api = {
  // 数据报表模块API - 基于OpenAPI定义，添加report前缀
  report: {
    // 看板管理相关API
    spectaculars: {
      // 新增看板
      add: (data) =>
        request({
          url: '/operating/spectaculars/add',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 删除看板
      delete: (id) =>
        request({
          url: '/operating/spectaculars/delete',
          method: 'GET',
          params: { id },
        }),
      // 获取看板列表
      list: (data) =>
        request({
          url: '/operating/spectaculars/list',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 更新看板
      update: (data) =>
        request({
          url: '/operating/spectaculars/update',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 看板详情
      detail: (data) =>
        request({
          url: '/operating/spectaculars/detail',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 获取昨日数据
      yesterdayData: () =>
        request({
          url: '/operating/spectaculars/yesterdayData',
          method: 'GET',
          params: { userId: userInfo?.id },
        }),

      // 新增维度视图
      addView: (spectId) =>
        request({
          url: '/operating/spectaculars/addDimensionView',
          method: 'GET',
          params: { spectId, userId: userInfo?.id },
        }),
    },

    // 维度管理相关API
    dimensions: {
      ...CRUD('operating/spectaculars', ['report']),
      // 新增维度
      add: (data) =>
        request({
          url: '/operating/spectaculars/addDimension',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 删除维度
      delete: (id) =>
        request({
          url: '/operating/spectaculars/deleteDimension',
          method: 'GET',
          params: { id, userId: userInfo?.id },
        }),

      // 更新维度
      update: (data) =>
        request({
          url: '/operating/spectaculars/updateDimension',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 获取维度详情
      detail: (data) =>
        request({
          url: '/operating/spectaculars/dimensionDetail',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),
    },

    // 图表管理相关API
    charts: {
      // 新增图表
      add: (data) =>
        request({
          url: '/operating/charts/add',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 删除图表
      delete: (id) =>
        request({
          url: '/operating/charts/delete',
          method: 'GET',
          params: { id, userId: userInfo?.id },
        }),

      // 获取图表列表
      list: (data) =>
        request({
          url: '/operating/charts/list',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 更新图表
      update: (data) =>
        request({
          url: '/operating/charts/update',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),

      // 图表详情
      detail: (data) =>
        request({
          url: '/operating/charts/detail',
          method: 'POST',
          data: { ...data, userId: userInfo?.id },
        }),
    },
  },
};

export { route, api };
