import express from 'express';
import { requireAuth } from '../middleware/auth.js';
import { addTree, getTreeDetailsById, getAllTreeLocations, getNearByTreeLocations, getTreeClusters, getTreeStats, getTreesCount, getAllClusterDetails,masterData, getAllTreeById } from '../controllers/treesController.js';
import { uploadMultipleFields } from '../middleware/multerConfig.js';

const router = express.Router();

const uploadFields = [
    { name: 'image', maxCount: 1 },
    { name: 'image_leaves', maxCount: 1 },
    { name: 'image3', maxCount: 1 },
    { name: 'image4', maxCount: 1 },
];


import multer from 'multer';

const upload = multer();
router.post('/', getAllTreeLocations)
router.post('/getAllTreeById', getAllTreeById)

// router.post('/add-tree', upload.none(), addTree)

// // Use the middleware
router.post('/add-tree', uploadMultipleFields(uploadFields), addTree);



// router.post('/add-tree', upload.any(), (req, res) => {
//   console.log('📝 req.body:', req.body);
//   console.log('📂 req.files:', req.files);
//   res.send('Received');
// });


// router.post('/add-tree', (req, res) => {
//     res.send('✅ Route hit');
// });



router.get('/get-tree/', getTreeDetailsById)
router.post('/get-trees/', getAllClusterDetails)
// router.get('/get-nearby-tree-loc/', getNearByTreeLocations)
router.post('/get-nearby-tree-loc/', upload.none(), getNearByTreeLocations)

// In your routes file
router.post('/trees/clusters', getTreeClusters);
router.post('/trees/stats', getTreeStats);
router.get('/tree-count', requireAuth, getTreesCount);
router.post('/masterData', masterData);
// router.post('/create-db', createAndApplySchema);


export default router;
