import api, { getBaseUrl } from './api';
export { getBaseUrl };
import type { TechnicalDataSheet } from '../types';

export const getDataSheets = async () => {
    return api.get<TechnicalDataSheet[]>('/datasheets');
};

export const createDataSheet = async (formData: FormData) => {
    return api.post<TechnicalDataSheet>('/datasheets', formData, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
};

export const updateDataSheet = async (id: string, formData: FormData) => {
    return api.put<TechnicalDataSheet>(`/datasheets/${id}`, formData, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
};

export const deleteDataSheet = async (id: string) => {
    return api.delete(`/datasheets/${id}`);
};

export const extractDataSheet = async (file: File) => {
    const formData = new FormData();
    formData.append('file', file);
    return api.post('/datasheets/extract', formData, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
};
