import { request } from '@/api/request'
import { LoginRequest, UserItem } from '../types'

/** 登录 */
export const login = (data: LoginRequest) => request.post('/rbac2/v1/login', data)
/** 登出 */
export const logout = () => request.post('/rbac2/v1/logout')
/** 获取菜单列表 */
export const getMenuList = () => request.post('/rbac2/v1/user/menu')
/** 创建用户 */
export const createUser = (data: UserItem) => request.post('/rbac2/v1/user/create', data, { needWorkspace: true })
/** 获取用户详情 */
export const getUserDetail = (data: UserItem) => request.post('/rbac2/v1/user/detail', data)
/** 获取用户列表 */
export const fetchUserList = (data: { page: number; size: number; keyword?: string }) => request.post('/rbac2/v1/user/fetch', data)
/** 修改用户 */
export const modifyUser = (data: UserItem) => request.post('/rbac2/v1/user/modify', data)
/** 删除用户 */
export const deleteUser = (data: { id: UserItem['id'] }) => request.post('/rbac2/v1/user/del', data)
/** 获取所有权限【树形】 */
export const getUserPmnTree = (data: { id: UserItem['id']; workspace: string }) => request.post('/rbac2/v1/user/pmn_tree', data)

/** 用户-获取所有权限【平面】 */
export const userPmn = (data: { id: UserItem['id']; workspace: string }) =>
  request.post('/rbac2/v1/user/pmn', data, { needWorkspace: true })
/** 用户-给指定用户设置权限 */
export const userSetPmn = (data: { list: { id: number; pmn_id: number }[] }) =>
  request.post('/rbac2/v1/user/set_pmn', data, { needWorkspace: true })

/** 用户-给指定用户编辑权限 */
export const userModifyPmn = (data: { id: UserItem['id']; list: number[] }) =>
  request.post('/rbac2/v1/user/modify_pmn', data, { needWorkspace: true })

/** 重置密码(短信) */
export const resetUserPassword = (data: {
  /** 账号 */
  account: string
  /** 验证码 */
  code: string
  /** 密码 */
  password: string
  /** 手机号 */
  phone: string
}) => request.post('/rbac2/v1/reset', data)

/** 管理员重置用户密码 */
export const adminResetUserPassword = (data: {
  /** 用户ID */
  id: number
  /** 新密码 */
  password: string
}) => request.post('/rbac2/v1/user/reset_password', data)
