import client from '../client';

export interface User {
  id: string;
  username: string;
  role: string;
  first_name?: string;
  last_name?: string;
  email?: string;
  mfa_enabled?: boolean;
}

export interface LoginResponse {
  token?: string;
  user?: User;
  mfa_required?: boolean;
  mfa_setup?: boolean;
  totp_uri?: string;
}

export const authApi = {
  login: (username: string, password: string, totp_code?: string) =>
    client.post<never, LoginResponse>('/auth/login', { username, password, ...(totp_code && { totp_code }) }),

  logout: () => client.post('/auth/logout'),

  me: () => client.get<never, User>('/users/me'),

  changePassword: (current_password: string, new_password: string) =>
    client.post('/auth/change-password', { current_password, new_password }),
};
