const fs = require("fs");
let content = fs.readFileSync("models/User.js", "utf8");

// Replace Number with String
content = content.replace("type: Number,", "type: String,");

// Update validation regex to handle + prefix
content = content.replace(
  /\/\\^\\d\{10,15\}\$\/\.test\(v\.toString\(\)\)/,
  "/^\\+?[1-9]\\d{9,14}$/.test(v)"
);

// Update validation message
content = content.replace(
  "Mobile number must be a valid number with 10-15 digits",
  "Mobile number must be a valid format (e.g., +1234567890 or 1234567890)"
);

// Add trim option
content = content.replace(
  "unique: true,",
  "unique: true,\n        trim: true,"
);

fs.writeFileSync("models/User.js", content);
console.log("Fixed User model - changed mobile field from Number to String");
