const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const TenderItem = sequelize.define(
    "tenderitem",
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      creation: { type: DataTypes.DATE, allowNull: false },
      modified: { type: DataTypes.DATE, allowNull: false },
      modified_by: { type: DataTypes.INTEGER, allowNull: false },
      owner: { type: DataTypes.INTEGER, allowNull: false },
      enabled: { type: DataTypes.BOOLEAN, allowNull: false },

      display_name: { type: DataTypes.STRING(100), allowNull: true },
      specification: { type: DataTypes.TEXT, allowNull: true },
      unit: { type: DataTypes.STRING(50), allowNull: true },
      quantity: { type: DataTypes.INTEGER, allowNull: true },

      tender_id: { type: DataTypes.INTEGER, allowNull: false },
       
    },
    {
      tableName: "tenderitems",
      freezeTableName: true,
    }
  );

  /**
   * Associates the Province model with other models.
   * @param {object} models - The models to associate with.
   */
  TenderItem.associate = (models) => {
    TenderItem.belongsTo(models.Tender, { foreignKey: "tender_id" });
  };

  return TenderItem;
};
