const { Sequelize, DataTypes } = require('sequelize');
const { sequelize } = require('./model');

const Item = sequelize.define(
  'Items',
  {
    item_id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
    pid: { type: DataTypes.INTEGER },
    description: { type: DataTypes.STRING, allowNull: false },
    sold: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
  },
  { timestamps: false },
);

(async () => {
  try {
    await sequelize.authenticate();
    console.log('Connection has been established successfully.');

    await Item.drop();

    await sequelize.sync();
    for (var j = 1; j <= 25; j++) {
      for (var i = 0; i < 10; i++) {
        await Item.create({
          // get remainder of i divided by 3
          // pid: (i % 25) + 1,
          pid: j,
          description: `test item ${i}`,
        });
      }
    }

    // await sequelize.close();
  } catch (error) {
    console.error('Unable to connect to the database:', error);
  }
})();
