require("dotenv").config();
const connectDB = require("./config/db");
const Service = require("./model/Service");
const User = require("./model/User");

const bcrypt = require("bcrypt");

const defaultServices = [
  { serviceCode: "SRV-001", serviceName: "Engine repair", servicePrice: 150000 },
  { serviceCode: "SRV-002", serviceName: "Transmission repair", servicePrice: 80000 },
  { serviceCode: "SRV-003", serviceName: "Oil Change", servicePrice: 60000 },
  { serviceCode: "SRV-004", serviceName: "Chain replacement", servicePrice: 40000 },
  { serviceCode: "SRV-005", serviceName: "Disc replacement", servicePrice: 400000 },
  { serviceCode: "SRV-006", serviceName: "Wheel alignment", servicePrice: 5000 },
];

const seed = async () => {
  await connectDB();

  for (const service of defaultServices) {
    await Service.updateOne({ serviceCode: service.serviceCode }, service, { upsert: true });
  }

  const hashedPassword = await bcrypt.hash("chief123", Number(process.env.BCRYPT_SALT_ROUNDS) || 10);

  await User.updateOne(
    { username: "chief" },
    { username: "chief", password: hashedPassword, fullName: "Chief Mechanic" },
    { upsert: true }
  );

  console.log("Seed complete: services + default user");
  process.exit(0);
};

seed();

