import { http } from "@/utils/http";

export type LoginResult = {
  code: number;
  message: string;
  data: {
    token: string;
    userInfo: {
      id: number;
      nickname: string;
      avatar: string | null;
      phone: string;
      roles: string[];
      permissions: string[];
    };
  };
};

export type UserInfoResult = {
  code: number;
  message: string;
  data: {
    id: number;
    username: string;
    realName: string;
    phone: string;
    email: string;
    avatar: string;
    department: string;
    roleIds: string;
    permissions: string[];
  };
};

export const login = (data: { username: string; password: string }) => {
  return http.request<LoginResult>("post", "/login", { data });
};

export const logout = () => {
  return http.request("post", "/login/logout");
};

export const getUserInfo = () => {
  return http.request<UserInfoResult>("get", "/login/info");
};
