import api from '@/core/api/axios';

const BASE = '/api/wtm/timesheets';

export const timesheetService = {
  getWeekly: (weekStart: string) => api.get(`${BASE}/week`, { params: { weekStart } }),
  saveEntry: (tsId: number, entry: unknown) => api.post(`${BASE}/${tsId}/entries`, entry),
  saveBatch: (tsId: number, entries: unknown[]) => api.put(`${BASE}/${tsId}/entries/batch`, entries),
  deleteEntry: (tsId: number, entryId: number) => api.delete(`${BASE}/${tsId}/entries/${entryId}`),
  submit: (tsId: number) => api.post(`${BASE}/${tsId}/submit`),
  getHistory: (params: Record<string, unknown>) => api.get(`${BASE}/history`, { params }),
  upload: (file: File) => {
    const formData = new FormData();
    formData.append('file', file);
    return api.post(`${BASE}/upload`, formData, { headers: { 'Content-Type': 'multipart/form-data' } });
  },
  downloadTemplate: () => api.get(`${BASE}/template`, { responseType: 'blob' }),
};
