import {
  AddUserParams,
  BaseListResult,
  BaseResult,
  EditUserParams,
  GetUserListParams,
  UserListData,
  UserLoginData,
} from '@models';
import {request} from './request';

const BASE_URL = '/user';

/** 用户登录 */
export function userLogin(userName: string, password: string): BaseResult<UserLoginData> {
  return request({
    method: 'POST',
    url: BASE_URL + '/login',
    data: {userName, password},
  });
}

/** 获取用户列表 */
export function getUserList(data: GetUserListParams): BaseListResult<UserListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getAllUser`,
    data,
  });
}

/** 获取指定用户信息 */
export function getUserInfo(id: string): BaseListResult<UserListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getAllUser`,
    data: {id, page: '1', limit: '1'},
  });
}

/** 导出用户 */
export function exportUser(data: GetUserListParams): any {
  return request({
    method: 'GET',
    url: `${BASE_URL}/userExport`,
    data,
    skipError: true,
  });
}

/** 新增用户 */
export function addUser(data: AddUserParams): BaseResult {
  return request({
    method: 'POST',
    data,
    url: `${BASE_URL}/addUser`,
  });
}

/** 修改用户 */
export function editUser(data: EditUserParams): BaseResult {
  return request({
    method: 'PUT',
    data,
    url: `${BASE_URL}/updateUser`,
  });
}

/** 删除用户 */
export function deleteUser(id: string): BaseResult {
  return request({
    method: 'DELETE',
    data: {id},
    url: `${BASE_URL}/delUser`,
  });
}
