import { api } from "./axiosInstance";
import type { LoginRequest, RegisterRequest, TokenResponse, UserInfo } from "@/types/auth.types";

export async function register(payload: RegisterRequest): Promise<TokenResponse> {
  const { data } = await api.post<TokenResponse>("/auth/register", payload);
  return data;
}

export async function login(payload: LoginRequest): Promise<TokenResponse> {
  const { data } = await api.post<TokenResponse>("/auth/login", payload);
  return data;
}

export async function logout(refreshToken: string): Promise<void> {
  await api.post("/auth/logout", { refreshToken });
}

export async function fetchCurrentUser(): Promise<UserInfo> {
  const { data } = await api.get<UserInfo>("/auth/me");
  return data;
}
