const router = require('express').Router();
const ctrl = require('../controllers/product.controller');
const { authenticate } = require('../middlewares/auth');
const upload = require('../middlewares/upload')('products');
const { validate } = require('../middlewares/validate');
const { productSchemas, paramsSchemas } = require('../validators');

router.use(authenticate);

router.get('/low-stock', ctrl.getLowStock);
router.get('/', ctrl.getAll);
router.get('/:id', ctrl.getById);
router.post(
	'/',
	upload.single('image'),
	validate({ body: productSchemas.create }),
	ctrl.create
);
router.put(
	'/:id',
	upload.single('image'),
	validate({ params: paramsSchemas.idParam, body: productSchemas.update }),
	ctrl.update
);
router.patch(
	'/:id/stock',
	validate({ params: paramsSchemas.idParam, body: productSchemas.adjustStock }),
	ctrl.adjustStock
);
router.delete('/:id', validate({ params: paramsSchemas.idParam }), ctrl.remove);

module.exports = router;
