const admin = require("firebase-admin"); // required
const { faker } = require("@faker-js/faker");
const fs = require("fs");
// initialization
const projectId = "halodoctor-a1660";
process.env.FIRESTORE_EMULATOR_HOST = "127.0.0.1:8080";
admin.initializeApp({ projectId });

const db = admin.firestore();

// seed function
async function getSeedData() {
  try {
    // [...Array(10).keys()].map(() =>
    //   db.collection("User").add({
    //     author_name: faker.name.firstName() + "" + faker.name.lastName(),
    //     author_profile_pic: faker.image.imageUrl(),
    //     title: faker.commerce.productName(),
    //     description: faker.commerce.productDescription(),
    //     address: {
    //       addr_1: faker.address.streetAddress(),
    //       addr_2: faker.address.secondaryAddress(),
    //       city: faker.address.city(),
    //       state: faker.address.state(),
    //       zipCode: faker.address.zipCode(),
    //     },
    //   })
    // );

    let rawdata = fs.readFileSync(
      `${__dirname}/../../db_seed/DoctorCategory.json`
    );
    // const rawData = fs.readFileSync(
    //   "/functions/db_seed/DoctorCategory.json",
    //   "utf8"
    // );
    const data = JSON.parse(rawdata);
    for (const item of data) {
      const docRef = db.collection("DoctorCategory").doc(); // Replace "YourCollectionName" with your desired collection name
      await docRef.set(item);
    }
    console.log("database seed was successful");
  } catch (error) {
    console.log(error, "database seed failed");
  }
}

getSeedData();
