import bcrypt from "bcrypt";
import mongoose from "mongoose";
import { userModel } from "../schemas/user.schema.js";
import { jobModel } from "../schemas/job.schema.js";
import { dbConnect } from "../mongo/index.js";

async function seedDB() {
  dbConnect();
  const salt = await bcrypt.genSalt(10);
  const hashPassword = await bcrypt.hash("secret", salt);

  const user = {
    _id: new mongoose.Types.ObjectId(1),
    name: "Admin",
    email: "admin@jsonapi.com",
    password: hashPassword,
    createdAt: new Date(),
    profile_image: "../../images/admin.jpg",
  };

  const admin = new userModel(user);
  await admin.save();
  
  const job = {
    _id: new mongoose.Types.ObjectId(1),
    status : {
      type: "Queued"
    },
    createdAt: new Date(),
    updatedAt: new Date(),
    started_at: new Date(),
  };
  
  const newJob = new jobModel(job);
  await newJob.save();

  console.log("DB seeded");
}

seedDB().then(() => {
  mongoose.connection.close();
});
