import { http } from '@/utils/http/axios';

export interface UserType {
  userId?: number;
  password?: string;
  deptId?: number | null;
  username?: string;
  staffNo?: string;
  mobile?: string;
  isEnable?: boolean;
  nickname?: string;
  roleIds?: number[];
  passwordRe?: string;
  /** 租户id */
  tenantId?: number;
}

interface AdminUserType {
  /** 昵称 */
  nickname: string;
  /** 登录用户名 */
  username: string;
  /** 部门id */
  deptId?: number;
  /** 员工编号 */
  staffNo?: string;
  /** 密码 */
  password: string;
  /** 所属租户id */
  tenantId: number;
}

/** root用户给某个租户添加管理员 */
export function addAdminUser(params: AdminUserType) {
  return http.request({
    url: '/user/adds',
    method: 'POST',
    params,
  });
}

//添加用户
export function addSingleUser(params: UserType) {
  return http.request(
    {
      url: '/user/add',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    },
  );
}

//添加批量用户
export function addMultipleUser(params: File) {
  return http.request({
    url: '/user/import',
    method: 'POST',
    params,
  });
}

export interface UserTypeDel {
  deleteStatus?: string;
  deptId?: number;
  email?: string;
  isEnable?: boolean;
  mobile?: string;
  nickname?: string;
  opertor?: string;
  password?: string;
  postId?: string;
  remark?: string;
  roleIds?: string[];
  sex?: string;
  staffNo?: string;
  userId?: number;
  username?: string;
  updateTime?: string;
  createTime?: string;
  certify?: string;
}

//删除用户
export function delUser(params: UserTypeDel) {
  return http.request({
    url: '/user/delete',
    method: 'POST',
    params,
  });
}

//修改用户
export function updateUser(params: UserType) {
  return http.request(
    {
      url: '/user/update',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    },
  );
}

//获取单个用户信息
// export function getUser(params: string): Promise<UserType> {
//   return http.request({
//     url: '/user/info',
//     method: 'get',
//     params,
//   });
// }

export interface UserList {
  pageNumber: number;
  totalPage: number;
  pageSize: number;
  page: number;
  list: UserTypeDel[];
  totalCount: number;
  pageNum: number;
}

export interface QueryUser {
  staffNo?: string; //工号
  nickname?: string; //姓名
  mobile?: string; //手机号
  roleName?: string; //角色
  deptName?: string; //组织
  page?: number; //当前页数
  pageRow?: number; //每页个数
  deptId?: string;
}

//获取单个用户信息
export function getUserList(params: QueryUser | null): Promise<UserList> {
  return http.request({
    url: '/user/list',
    method: 'get',
    params,
  });
}

interface ResetCodeType {
  password?: string;
  userId?: string;
}

// 修改密码
export function resetCode(params: ResetCodeType) {
  return http.request({
    url: '/user/changePassword',
    method: 'POST',
    params,
  });
}
