import { Router } from 'express';
import multer from 'multer';
import path from 'path';
import { v4 as uuidv4 } from 'uuid';
import * as dataSheetController from '../controllers/dataSheetController.js';
import os from 'os';

const router = Router();

const storage = multer.diskStorage({
    destination: (req, file, cb) => cb(null, os.tmpdir()),
    filename: (req, file, cb) => cb(null, `${Date.now()}-${uuidv4()}${path.extname(file.originalname)}`)
});

const upload = multer({ storage, limits: { fileSize: 10 * 1024 * 1024 } });

router.get('/', dataSheetController.getAllDataSheets);
router.get('/file/:id', dataSheetController.getFile);
router.post('/', upload.single('file'), dataSheetController.createDataSheet);
router.post('/extract', upload.single('file'), dataSheetController.extractData);
router.put('/:id', upload.single('file'), dataSheetController.updateDataSheet);
router.delete('/:id', dataSheetController.deleteDataSheet);

export default router;