const fs = require('fs');
let code = fs.readFileSync('/home/ubuntu/loopuman-backend/enterprise-api.js', 'utf8');

const broken = `    if (budget < 10 || budget > 100000) {
      return res.status(400).json({ error: 'Budget must be between Ⓥ10 ($0.10) and Ⓥ100,000 ($1,000)' });
    // Estimated time + minimum hourly rate enforcement
    const estimatedSeconds = parseInt(req.body.estimated_seconds) || null;`;

const fixed = `    if (budget < 10 || budget > 100000) {
      return res.status(400).json({ error: 'Budget must be between Ⓥ10 ($0.10) and Ⓥ100,000 ($1,000)' });
    }

    // Estimated time + minimum hourly rate enforcement
    const estimatedSeconds = parseInt(req.body.estimated_seconds) || null;`;

if (code.includes(broken)) {
  code = code.replace(broken, fixed);
  // Also remove the extra closing brace
  code = code.replace("    }\n    }\n\n    const workers", "    }\n\n    const workers");
  fs.writeFileSync('/home/ubuntu/loopuman-backend/enterprise-api.js', code);
  console.log('Fixed scope');
} else {
  console.log('Pattern not found');
}
