import {
  AccountParams,
  DelAccountParams,
  DeptListItem,
  MenuParams,
  RoleParams,
  RolePageParams,
  CheckUserParams,
  MenuListGetResultModel,
  DeptListGetResultModel,
  AccountListGetResultModel,
  RolePageListGetResultModel,
  RoleListGetResultModel,
  SaveRoleParams,
  RoleIdParams,
  deleteRoleParams,
} from './model/systemModel';
import { Result } from '/#/axios';
import { defHttp } from '/@/utils/http/axios';
import { TreeMenuNode } from '/@/utils/treeUtils';
  // import { ContentTypeEnum } from '/@/enums/httpEnum';
// sys/user/list
// /sys/role/list
// sys/menu/queryAll
// sys/menu/update
enum Api {
  // MenuList = '/service/manage/sysMenu/getByRoleId',
  getMenuIdsByRoleId = '/service/manage/sysMenu/getMenuIdsByRoleId',
  MenuList = '/service/manage/sysMenu/list',
  saveMenu = '/service/manage/sysMenu/add',
  updateMenu = '/service/manage/sysMenu/update',
  deleteMenu = '/service/manage/sysMenu/delete',
  MenuUser = '/zfb-api/zfb/shop/sys/menu/delete',
  getByRoleId = '/service/manage/sysMenu/getByRoleId',

  AccountList = '/zfb-api/zfb/shop/sys/user/list',
  saveAccount = '/zfb-api/zfb/shop/sys/user/save',
  updateAccount = '/zfb-api/zfb/shop/sys/user/update',
  IsAccountExist = '/basic-api/system/accountExist',
  deleteAccountUser = '/zfb-api/zfb/shop/sys/user/preDeleteStaff',

  RolePageList = '/service/manage/sysRole/list',
  setRoleStatus = '/basic-api/system/setRoleStatus',
  saveRole = '/service/manage/sysRole/add',
  deleteRole = '/service/manage/sysRole/delete',
  updateRole = '/service/manage/sysRole/update',
  GetAllRoleList = '/service/manage/sysRole/allList',
  roleSelectList = '/zfb-api/zfb/shop/sys/role/select',
  giveMenu = '/service/manage/sysRole/giveMenu',

  DeptList = '/zfb-api/zfb/shop/sys/dept/list',

  checkUser = '/zfb-api/zfb/user/checkUserExists',
}

export const getAccountList = (params: AccountParams) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.AccountList, params });

export const deleteAccountUserApi = (params: DelAccountParams) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.deleteAccountUser, params });

export const saveAccountUserApi = (params: AccountParams) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.saveAccount, params });

export const updateAccountUserApi = (params: AccountParams) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.updateAccount, params });

//decpored

export const getDeptList = (params?: DeptListItem) =>
  defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });

export const getByRoleId = (params: RoleIdParams) =>
  defHttp.get<TreeMenuNode>({ url: Api.getByRoleId, params });

export const giveMenu = (params) =>
  defHttp.post<MenuListGetResultModel>({ url: Api.giveMenu, params });

export const getMenuIdsByRoleId = (params?: RoleIdParams) =>
  defHttp.get<MenuListGetResultModel>({
    url: Api.getMenuIdsByRoleId,
    params,
});
export const getMenuList = (params?: RoleIdParams) =>
  defHttp.post<MenuListGetResultModel>({
    url: Api.MenuList,
    params: {
      pageNum:1,
      pageSize:100,
    },
  });
//menu
export const saveMenuApi = (params?: MenuParams) =>
  defHttp.post<MenuListGetResultModel>({ url: Api.saveMenu, params });

export const updateMenuApi = (params?: MenuParams) =>
  defHttp.post<MenuListGetResultModel>({ url: Api.updateMenu, params });

export const deleteMenuApi = (params: deleteRoleParams) =>
  defHttp.post<MenuListGetResultModel>({ url: Api.deleteMenu, params });

//roles
export const getRoleListByPage = (params?: RolePageParams) =>
  defHttp.post<RolePageListGetResultModel>({ url: Api.RolePageList, params });

export const getAllRoleList = (params?: RoleParams) =>
  defHttp.post<RoleListGetResultModel>({ url: Api.GetAllRoleList, params });

export const roleSelectListApi = (params?: RoleParams) =>
  defHttp.post<RoleListGetResultModel>({ url: Api.roleSelectList, params });

export const setRoleStatus = (id: number, status: string) =>
  defHttp.post({ url: Api.setRoleStatus, params: { id, status } });

export const saveRoleApi = (params: SaveRoleParams) =>
  //TODO 临时加deptId调试
  defHttp.post({ url: Api.saveRole, params: params });
//TODO 临时d加eptId调试
export const updateRoleApi = (params: SaveRoleParams) =>
  defHttp.post({ url: Api.updateRole, params: params });

export const deleteRoleApi = (params: deleteRoleParams) =>
  defHttp.post({ url: Api.deleteRole, params: params });

export const isAccountExist = (account: string) =>
  defHttp.post({ url: Api.IsAccountExist, params: { account } }, { errorMessageMode: 'none' });

export const deptListApi = (params?: RolePageParams) =>
  defHttp.post<RolePageListGetResultModel>({ url: Api.DeptList, params });

export const checkUserApi = (params?: CheckUserParams) =>
  defHttp.post<Result>({ url: Api.checkUser, params });
