import request from "@/utils/request";
import type { LoginForm, LoginResponse, User } from "@/types/auth";

export const authApi = {
  login: async (data: LoginForm): Promise<LoginResponse> => {
    const response = await request.post("/api/auth/login", data);
    return response as unknown as LoginResponse;
  },

  logout: async (): Promise<void> => {
    await request.post("/api/auth/logout");
  },

  getUserInfo: async (): Promise<User> => {
    const response = await request.get("/api/auth/user-info");
    return response as unknown as User;
  },

  refreshToken: async (): Promise<{ token: string }> => {
    const response = await request.post("/api/auth/refresh-token");
    return response as unknown as { token: string };
  },
};
