const fs = require('fs');
const file = 'c:/Users/kde/Desktop/wassili_V2/routes/orders.js';
let content = fs.readFileSync(file, 'utf8');

const findBlock = `        const settings = await getCachedSettings();\n        const commissionRate = settings.commissionRate ?? 0.15; // null-safe fallback only`;

const replaceBlock = `        const settings = await getCachedSettings();\n        const commissionRate = settings.commissionRate ?? 0.15; // null-safe fallback only\n\n        // ✅ Server-Side Security: Prevent clients from sending an abnormally low price\n        const base = settings.baseFare || 1000;\n        if (price < base) {\n            return res.status(400).json({ message: \`عذراً، السعر المطلوب (\${price}) أقل من الحد الأدنى لتسعيرة النظام (\${base})\` });\n        }`;

if (content.includes(findBlock)) {
    content = content.replace(findBlock, replaceBlock);
    fs.writeFileSync(file, content);
    console.log("Fixed price in orders.js successfully.");
} else {
    console.log("NOT FOUND");
}
