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

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

      procurementtracker_id: { type: DataTypes.INTEGER, allowNull: true },
      document_no: { type: DataTypes.STRING(255), allowNull: true },
      category: { type: DataTypes.STRING(250), allowNull: true },
      type: { type: DataTypes.STRING(250), allowNull: true },
      agency: { type: DataTypes.STRING(250), allowNull: true },
      nationality: { type: DataTypes.STRING(250), allowNull: true },
      file_name: { type: DataTypes.STRING(250), allowNull: true },
      file_path: { type: DataTypes.STRING(250), allowNull: true },
      file_size: { type: DataTypes.STRING(250), allowNull: true },
      file_type: { type: DataTypes.STRING(250), allowNull: true },
      note: { type: DataTypes.STRING(250), allowNull: true },
      document_date: { type: DataTypes.DATEONLY, allowNull: true },
    },
    {
      tableName: "procurmenttrackerfiles",
      freezeTableName: true,
    }
  );

  /**
   * Associates the ProcurementTrackerFile model with other models.
   * @param {object} models - The models to associate with.
   */
  ProcurementTrackerFile.associate = (models) => {
    /**
     * Associates the Province model with the City model.
     * Defines a one-to-many relationship between Province and City.
     * @param {object} models - The models to associate with.
     */
    ProcurementTrackerFile.belongsTo(models.ProcurementTracker, {
      foreignKey: "procurementtracker_id",
      onDelete: "CASCADE",
    });
  };

  return ProcurementTrackerFile;
};
