const Sequelize = require("sequelize");
const sequelizeConnect = require("../connection/db");

const SellerModules = sequelizeConnect.define(
  "seller_modules",
  {
    id: {
      type: Sequelize.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
    },
    name: {
      type: Sequelize.STRING(150),
      allowNull: false,
    },
    status: {
      type: Sequelize.BOOLEAN,
      allowNull: false,
      defaultValue: true
    }
  },
  {
    tableName: "seller_modules",
    timestamps: false,
  }
);



const seedSellerModules = async () => {
  const modulesToInsert = [
    { name: "Dashboard", status: true },
    { name: "Orders", status: true },
    { name: "Products", status: true },
    { name: "Vouchers", status: true },
    { name: "Messages", status: true },
    { name: "Settings", status: true },
  ];

  try {
    for (const module of modulesToInsert) {
      const [record, created] = await SellerModules.findOrCreate({
        where: { name: module.name },
        defaults: module,
      });

      if (created) {
        console.log(`Inserted: ${module.name}`);
      } else {
        console.log(`Already exists: ${module.name}`);
      }
    }

    console.log("Seeding complete.");
  } catch (error) {
    console.error("Error during seeding:", error);
  }
}

seedSellerModules();

module.exports = SellerModules;
