import axios from 'axios';
import { UserState } from '@/store/modules/user/types';
import type {
  LoginData,
  UpdatePwdData,
  UserListPageParam,
  UserListPageRes,
  UserUpdateParam,
  ResetPasswordParam,
  EnableUserParam,
  BatchCreateUserParam,
} from './types/user';

// 登录
export function login(data: LoginData): Promise<UserState> {
  return axios.post('/api/user/login', data);
}
// 修改密码
export function updatePwd(datas: UpdatePwdData): Promise<UserState> {
  return axios.post('/api/user/password/modify', {}, { params: datas });
}
// 退出登录
export function userLogout() {
  return axios.post('/api/user/logout', {});
}

// 用户管理
// 获取用户列表 (分页)
export function userListPage(
  params: UserListPageParam
): Promise<UserListPageRes> {
  return axios.get('/api/user/list', { params });
}
// 新增或编辑用户
export function updateUser(data: UserUpdateParam): Promise<any> {
  return axios.post('/api/user/update', data);
}
// 批量新增用户
export function batchAddUser(datas: BatchCreateUserParam[]): Promise<any> {
  return axios.post('/api/user/addList', datas);
}
// 删除用户
export function deleteUser(id: number): Promise<any> {
  return axios.post(`/api/user/delete/${id}`);
}
// 重置用户密码
export function resetUserPassword(data: ResetPasswordParam): Promise<any> {
  return axios.post('/api/user/resetPassword', data);
}
// 启用禁用用户
export function enableUser(datas: EnableUserParam): Promise<any> {
  return axios.post(`/api/user/enable`, datas);
}
