/**
 * 项目：-
 * @Author: xiongwei
 * @Date: 2022-06-28 11:50:00
 */

import { defHttp } from '/@/utils/http/axios';
import { User, UserParams, UserPageResult } from '../model/user';

const baseApi = '/v1/system/user';

/**
 * 新增
 */
export const add = (entity: User) => defHttp.post<User>({ url: `${baseApi}/`, data: entity });

/**
 * 更新
 */
export const update = (entity: User) => defHttp.put<User>({ url: `${baseApi}/`, data: entity });

/**
 * 删除
 */
export const remove = (id: any) => defHttp.delete<Number>({ url: `${baseApi}/${id}` });

/**
 * 分页查询
 */
export const search = (params?: UserParams) => defHttp.get<UserPageResult>({ url: `${baseApi}/search`, params });

/**
 * 列表查询
 */
export const all = (params?: UserParams) => defHttp.get<UserPageResult>({ url: `${baseApi}/all`, params });

/**
 * 通过主键查询
 */
export const getById = (id: any) => defHttp.get<User>({ url: `${baseApi}/${id}` });

/**
 * 单个查询
 */
export const getOne = (params?: UserParams) => defHttp.get<User>({ url: `${baseApi}/one`, params });

/**
 * 批量删除
 */
export const batchRemove = (idList: Array<any>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-delete`, data: idList });

/**
 * 批量新增
 */
export const batchAdd = (entityList: Array<User>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-save`, data: entityList });

/**
 * 批量更新
 */
export const batchUpdate = (entityList: Array<User>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-update`, data: entityList });

/**
 * 查询数量
 */
export const count = (params?: UserParams) => defHttp.get<Number>({ url: `${baseApi}/count`, params });

/**
 * 用户登录
 */
export const login = (loginInfo: { username: string; password: string }) =>
  defHttp.post<{ userInfo: User; token: string }>(
    { url: `${baseApi}/login`, data: loginInfo },
    { errorMessageMode: 'none' },
  );

/**
 * 用户登出
 */
export const logout = () => defHttp.post<any>({ url: `${baseApi}/logout` }, { errorMessageMode: 'none' });

/**
 * 用户注册
 */
export const register = (user: User) => defHttp.post<User>({ url: `${baseApi}/register`, data: user });

/**
 * 当前用户信息
 */
export const info = () => defHttp.get<User>({ url: `${baseApi}/info` }, { errorMessageMode: 'none' });

/**
 * 修改密码
 */
export const changePassword = (passwordInfo: any) =>
  defHttp.post<User>({ url: `${baseApi}/change-password`, data: passwordInfo });

/**
 * 审核
 */
export const batchVerify = (data: any) => defHttp.post<User>({ url: `${baseApi}/batch/verify`, data });
