import request from '@/utils/request';
import { getUserInfos } from './user';
export function getList(data) {
  return request({
    url: '/sysMenu/select',
    method: 'get',
    data,
  });
}

export function doEdit(data) {
  return request({
    url: '/sysMenu/update',
    method: 'post',
    data,
  });
}

export function doDelete(data) {
  return request({
    url: '/sysMenu/remove?menuId=' + data.menuId,
    method: 'post',
    data,
  });
}

export function doAdd(data) {
  return request({
    url: '/sysMenu/insert',
    method: 'post',
    data,
  });
}

export function getCustom(data) {
  return request({
    url: '/sysMenu/selectCustom',
    method: 'get',
    data,
  });
}

//小程序菜单查询
export function miniMenuSelect(data) {
  return request({
    url: '/miniMenu/select',
    method: 'get',
    data,
  });
}

//小程序菜单添加
export function miniMenuInsert(data) {
  return request({
    url: '/miniMenu/insert',
    method: 'post',
    data,
  });
}

//小程序菜单修改
export function miniMenuUpdate(data) {
  return request({
    url: '/miniMenu/update',
    method: 'post',
    data,
  });
}

//小程序菜单删除
export function miniMenuRemove(data) {
  return request({
    url: '/miniMenu/remove?menuId=' + data.menuId,
    method: 'post',
    data,
  });
}
export function fetchProjectList(data = {}) {
  return request({
    url: '/iot/project/select?page=1&size=100',
    method: 'get',
    data,
  });

  // const mock = [
  //   {
  //     id: 1,
  //     name: '力鼎环保智慧云系统',
  //   },
  //   {
  //     id: 2,
  //     name: '力鼎环保智慧云系统2',
  //   },
  //   {
  //     id: 3,
  //     name: '力鼎环保智慧云系统3',
  //   },
  // ];
  //
  // return Promise.resolve(mock);
}
// 查询当前用户的项目列表
export function getCurrentUserProjects(data) {
  return request({
    url: '/system/getCurrentUserProjects',
    method: 'get',
    data,
  });
}
export async function fetchMenuByProject(project) {
  const { data = [] } = await getUserInfos();
  const menus = data?.menus || [];
  return Promise.resolve(
    project.len === 0
      ? menus
      : menus.slice(menus.length - project.len, menus.length)
  );
}
