import axiosInstance from '../../utils/axios';
import { UserVO } from '../../types';

// 分页参数类型
export interface PageParam {
  pageNo?: number;
  pageSize?: number;
  [key: string]: any;
}

// 分页响应类型
export interface PageResponse<T> {
  list: T[];
  total: number;
}

// 用户管理基础 API
export const userApi = {
  // 查询用户管理列表
  getUserPage: (params: PageParam): Promise<PageResponse<UserVO>> => {
    return axiosInstance.get('/system/user/page', { params });
  },

  // 查询用户详情
  getUser: (id: number): Promise<UserVO> => {
    return axiosInstance.get(`/system/user/get?id=${id}`);
  },

  // 根据角色代码查询用户
  getRoleUser: (code: string): Promise<UserVO[]> => {
    return axiosInstance.get(`/system/user/getUserByRoleCode?roleCode=${code}`);
  },

  // 新增用户
  createUser: (data: UserVO): Promise<void> => {
    return axiosInstance.post('/system/user/create', data);
  },

  // 修改用户
  updateUser: (data: UserVO): Promise<void> => {
    return axiosInstance.put('/system/user/update', data);
  },

  // 删除用户
  deleteUser: (id: number): Promise<void> => {
    return axiosInstance.delete(`/system/user/delete?id=${id}`);
  },

  // 用户密码重置
  resetUserPassword: (id: number, password: string): Promise<void> => {
    return axiosInstance.put('/system/user/update-password', { id, password });
  },

  // 用户状态修改
  updateUserStatus: (id: number, status: number): Promise<void> => {
    return axiosInstance.put('/system/user/update-status', { id, status });
  },

  // 获取用户精简信息列表
  getSimpleUserList: (): Promise<UserVO[]> => {
    return axiosInstance.get('/system/user/simple-list');
  },
};

