import { apiClient } from "./client";

export interface RegisterPayload {
  username: string;
  email: string;
  password: string;
  tenantName?: string;
}

export interface LoginPayload {
  email: string;
  password: string;
}

export interface UserInfo {
  id: number;
  tenantId: number;
  username: string;
  email: string;
  role: string;
  avatarUrl?: string;
}

export interface LoginResponse {
  token: string;
  tokenType: string;
  user: UserInfo;
}

export const authApi = {
  register: (payload: RegisterPayload) =>
    apiClient.post<{ data: LoginResponse }>("/auth/register", payload).then((r) => r.data.data),

  login: (payload: LoginPayload) =>
    apiClient.post<{ data: LoginResponse }>("/auth/login", payload).then((r) => r.data.data),

  logout: () => apiClient.post("/auth/logout"),

  me: () => apiClient.get<{ data: UserInfo }>("/auth/me").then((r) => r.data.data),
};
