import { requestClient } from '../request';

export namespace SystemUserApi {
  export interface SystemUser {
    [key: string]: any;
    ID: string;
    Name: string;
    Nickname: string;
    Password: string;
    Salt: string;
    Status: 0 | 1;
    OrgID: string;
    Sex: 0 | 1;
    Email: string;
    Avatar: string;
    Mobile: string;
    Address: string;
    Describe: string;
    IsAdmin: 0;
    OpenID: string;
    LastLoginIp: string;
    LastLoginTime: string;
    CreatedAt: string;
    UpdatedAt: string;
    DeletedAt: string;
    dept: {
      CreatedAt: string;
      Email: string;
      ID: string;
      ManagerID: string;
      ManagerName: string;
      Name: string;
      Phone: string;
      Status: 0 | 1;
      UpdatedAt: string;
    };
    roleInfo: [
      {
        name: string;
        roleId: 0;
      },
    ];
    post: [
      {
        postId: 0;
        postName: string;
      },
    ];
  }
  export interface getUserList {
    currentPage: number;
    userList: SystemUser[];
    total: number;
  }
}
export const getUserList = async (org_id: string) => {
  return requestClient.get<SystemUserApi.getUserList>(
    '/identify-service/user',
    { params: { org_id } },
  );
};

export const deleteUser = async (id: string) => {
  return requestClient.delete('/identify-service/user', {
    params: {
      ids: [id],
    },
  });
};

export const updateUser = async (
  id: string,
  data: SystemUserApi.SystemUser,
) => {
  return requestClient.put(`/identify-service/user/${id}/personalInfo`, data);
};

export const registerUser = async (data: SystemUserApi.SystemUser) => {
  return requestClient.post('/identify-service/user/register', data);
};
/**
 * 新增用户
 */
export const createUser = async (data: SystemUserApi.SystemUser) => {
  return requestClient.post('/identify-service/user', data);
};
