var MongoClient = require("mongodb").MongoClient;

var topic_name = ["www", "html", "css", "javascript", "nodejs", "jquery", "louiscklaw1", "louiscklaw2", "louiscklaw3"];
var topic_status = ["no", "no", "no", "no", "no", "no", "no", "no", "no"];
var topic_hour = [2, 4, 4, 6, 10, 6, 1, 2, 3];

MongoClient.connect("mongodb://mongo:27017/", function (err, result) {
  if (!err) {
    console.log("We are connected");
    var db = result.db("assignment2");

    // db.collection("topicList").remove({});

    // for (let i = 0; i < topic_name.length; i++) {
    //   db.collection("topicList").insert({
    //     name: topic_name[i],
    //     hour: topic_hour[i],
    //     status: topic_status[i],
    //   });
    // }

    // for (let i = 0; i < 100; i++) {
    //   db.collection("topicList").insert({
    //     name: `topic_name_${i}`,
    //     hour: `topic_hour${i}`,
    //     status: i % 2 ? "yes" : "no",
    //   });
    // }

    db.collection("users").remove({});
    db.collection("users").insert({ _id: "u9999", name: `andy`, password: "123456", icon: "icons/andy.jpg" });
    for (let i = 0; i < 10; i++) {
      db.collection("users").insert({ _id: i, name: `Andy_${i}`, password: "123456", icon: "icons/andy.jpg" });
    }

    db.collection("noteList").remove({});
    db.collection("noteList").insert({
      userId: "u9999",
      lastsavedtime: Date.now() + 1 * 10000,
      title: "assigment2",
      content: "an iNotes app based on react",
    });

    for (let i = 0; i < 10; i++) {
      db.collection("noteList").insert({
        userId: "u9999",
        lastsavedtime: Date.now() + i * 10000,
        title: `assigment2_${i}`,
        content: `an iNotes app based on react_${i}`,
      });
    }
  }
});
