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

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

export const userService = {
  getAll: (params?: Record<string, unknown>) => api.get(BASE, { params }),
  getById: (id: number) => api.get(`${BASE}/${id}`),
  update: (id: number, data: unknown) => api.put(`${BASE}/${id}`, data),
  updateRoles: (id: number, roles: string[]) => api.put(`${BASE}/${id}/roles`, { roles }),
  uploadInternal: (file: File) => {
    const fd = new FormData();
    fd.append('file', file);
    return api.post(`${BASE}/upload/internal`, fd, { headers: { 'Content-Type': 'multipart/form-data' } });
  },
  uploadSubcontractor: (file: File) => {
    const fd = new FormData();
    fd.append('file', file);
    return api.post(`${BASE}/upload/subcontractor`, fd, { headers: { 'Content-Type': 'multipart/form-data' } });
  },
  downloadTemplate: () => api.get(`${BASE}/template`, { responseType: 'blob' }),
};
