import { post, get } from './client.js';

/**
 * Authentication API endpoints
 */

/**
 * Login user
 * @param {string} email
 * @param {string} password
 * @returns {Promise<{token: string, user: Object}>}
 */
export async function login(username, password) {
  return post('/api/auth/login', { username, password });
}

/**
 * Logout user (client-side only, server may also invalidate token)
 * @returns {Promise<void>}
 */
export async function logout() {
  // Optionally notify server to invalidate token
  try {
    await post('/api/auth/logout', {});
  } catch (error) {
    // Ignore server errors on logout
    console.log('Server logout error (ignored):', error);
  }
}

/**
 * Get current user profile
 * @returns {Promise<Object>}
 */
export async function getCurrentUser() {
  return get('/api/auth/check');
}
