import axios from 'axios';

// Point this at your Spring Boot backend
const API_BASE_URL = 'http://localhost:8080/api/files';

export function fetchFiles() {
  return axios.get(API_BASE_URL).then(res => res.data);
}

export function uploadFile(file, onUploadProgress) {
  const formData = new FormData();
  formData.append('file', file);

  return axios
    .post(API_BASE_URL, formData, {
      headers: { 'Content-Type': 'multipart/form-data' },
      onUploadProgress,
    })
    .then(res => res.data);
}

export function getDownloadUrl(id) {
  return `${API_BASE_URL}/${id}/download`;
}

export function getPreviewUrl(id) {
  return `${API_BASE_URL}/${id}/preview`;
}

export function deleteFile(id) {
  return axios.delete(`${API_BASE_URL}/${id}`);
}
