const fs = require('fs');

function patchFile(filename) {
    let content = fs.readFileSync(filename, 'utf8');
    content = content.replace(/\.find\(\s*([a-zA-Z0-9_]+)\s*=>\s*\1\.id\s*===\s*([a-zA-Z0-9_]+)\s*\)/g, 
        ".find($1 => String($1.id) === String($2))");
    
    // Also patch == just in case some use == instead of === (though the previous regex catches ===, let's catch == too)
    content = content.replace(/\.find\(\s*([a-zA-Z0-9_]+)\s*=>\s*\1\.id\s*==\s*([a-zA-Z0-9_]+)\s*\)/g, 
        ".find($1 => String($1.id) === String($2))");
    
    fs.writeFileSync(filename, content, 'utf8');
}

try {
    patchFile('app_final.js');
    patchFile('vouchers_returns.js');
    console.log("Patched ID equality checks.");
} catch(e) {
    console.error(e);
}
