module.exports = (pool) => {
  const router = require('express').Router();

  // Get all tasks
  router.get('/', async (req, res) => {
    const [tasks] = await pool.query('SELECT * FROM tasks');
    res.json(tasks);
  });

  // Create a task
  router.post('/', async (req, res) => {
    const { title, budget, location } = req.body;
    await pool.query(
      'INSERT INTO tasks (title, budget, location) VALUES (?, ?, POINT(?, ?))',
      [title, budget, location.lng, location.lat]
    );
    res.status(201).json({ success: true });
  });

  return router;
};