import api from './api';
import type { Album, AlbumWithTracks } from '../types';

export interface ListAlbumsParams {
  limit?: number;
  offset?: number;
}

export const albumService = {
  // GET /api/albums
  async listAlbums(params?: ListAlbumsParams): Promise<Album[]> {
    const res = await api.get<Album[]>('/albums', { params });
    return res.data;
  },

  // GET /api/albums/:id  (returns album + tracks)
  async getAlbum(id: string): Promise<AlbumWithTracks> {
    const res = await api.get<AlbumWithTracks>(`/albums/${id}`);
    return res.data;
  },

  // POST /api/albums
  async createAlbum(data: Partial<Album>): Promise<Album> {
    const res = await api.post<Album>('/albums', data);
    return res.data;
  },

  // PUT /api/albums/:id
  async updateAlbum(id: string, data: Partial<Album>): Promise<Album> {
    const res = await api.put<Album>(`/albums/${id}`, data);
    return res.data;
  },

  // DELETE /api/albums/:id
  async deleteAlbum(id: string): Promise<{ status: string }> {
    const res = await api.delete<{ status: string }>(`/albums/${id}`);
    return res.data;
  },
};
