import type { Song, PlaylistNode } from '../types/interfaces'; const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000/api'; class Api { async getSongs(): Promise { const response = await fetch(`${API_BASE_URL}/songs`); if (!response.ok) throw new Error('Failed to fetch songs'); return response.json(); } async saveSongs(songs: Song[]): Promise { const response = await fetch(`${API_BASE_URL}/songs/batch`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(songs), }); if (!response.ok) throw new Error('Failed to save songs'); return response.json(); } async getPlaylists(): Promise { const response = await fetch(`${API_BASE_URL}/playlists`); if (!response.ok) throw new Error('Failed to fetch playlists'); return response.json(); } async savePlaylists(playlists: PlaylistNode[]): Promise { const response = await fetch(`${API_BASE_URL}/playlists/batch`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(playlists), }); if (!response.ok) throw new Error('Failed to save playlists'); return response.json(); } async resetDatabase(): Promise { try { const response = await fetch(`${API_BASE_URL}/reset`, { method: 'POST', }); if (!response.ok) { throw new Error('Failed to reset database'); } return true; } catch (error) { console.error('Error resetting database:', error); throw error; } } } export const api = new Api();