import { Router } from 'express';
import * as searchService from '../services/search.js';
import * as fileService from '../services/file.js';
const router = Router({ mergeParams: true });
router.get('/code', async (req, res) => {
    const ws = fileService.getWorkspace(req.params.id);
    if (!ws) {
        res.status(404).json({ error: 'Workspace not found' });
        return;
    }
    const q = req.query.q;
    if (!q) {
        res.status(400).json({ error: 'q is required' });
        return;
    }
    const results = await searchService.searchCode(ws, {
        query: q,
        regex: req.query.regex === 'true',
        caseSensitive: req.query.caseSensitive === 'true',
        filePattern: req.query.filePattern || undefined,
        maxResults: parseInt(req.query.maxResults) || 200,
    });
    res.json({ results, total: results.length });
});
router.get('/files', async (req, res) => {
    const ws = fileService.getWorkspace(req.params.id);
    if (!ws) {
        res.status(404).json({ error: 'Workspace not found' });
        return;
    }
    const q = req.query.q;
    if (!q) {
        res.status(400).json({ error: 'q is required' });
        return;
    }
    const results = await searchService.searchFiles(ws, q);
    res.json({ results, total: results.length });
});
export default router;
//# sourceMappingURL=search.js.map