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

module.exports = (sequelize) => {
  const TenderVendorFile = sequelize.define(
    "tendervendorfile",
    {
      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 },

      tendervendor_id: { type: DataTypes.INTEGER, allowNull: false },
      nib_file: { type: DataTypes.TEXT, allowNull: true },
      npwp_file: { type: DataTypes.TEXT, allowNull: true },
      siup_file: { type: DataTypes.TEXT, allowNull: true },
      sertifikat_file: { type: DataTypes.TEXT, allowNull: true },
    },
    {
      tableName: "tendervendorsfiles",
      freezeTableName: true,
    }
  );

  /**
   * Associates the Province model with other models.
   * @param {object} models - The models to associate with.
   */
  TenderVendorFile.associate = (models) => {
    TenderVendorFile.belongsTo(models.TenderVendor, { foreignKey: "tendervendor_id", as: "tendervendorfile", onDelete: "CASCADE"});
  };

  return TenderVendorFile;
};
