import { Router } from 'express';
import auth from '../middleware/auth.js';
import upload from '../middleware/upload.js';
import { getAll, getByCategory, getOne, create, update, remove } from '../controllers/productsController.js';

const router = Router();
const images = upload.fields([{ name: 'image1', maxCount: 1 }, { name: 'image2', maxCount: 1 }]);

router.get('/', getAll);
router.get('/category/:slug', getByCategory);
router.get('/:id', getOne);
router.post('/', auth, images, create);
router.put('/:id', auth, images, update);
router.delete('/:id', auth, remove);

export default router;