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

module.exports = (sequelize) => {
  const ProcurementTrackerStatus = sequelize.define(
    "procurmenttrackerstatuse",
    {
      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 },
      status_name: { type: DataTypes.STRING(250), allowNull: true },
      status_date: { type: DataTypes.DATE, allowNull: true },
      note: { type: DataTypes.STRING(250), allowNull: true },
    },
    {
      tableName: "procurmenttrackerstatuses",
      freezeTableName: true,
    }
  );

  /**
   * Associates the ProcurementTrackerStatus model with other models.
   * @param {object} models - The models to associate with.
   */
  ProcurementTrackerStatus.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.
     */
    ProcurementTrackerStatus.belongsTo(models.ProcurementTracker, {
      foreignKey: "procurementtracker_id",
      onDelete: "CASCADE",
    });
  };

  return ProcurementTrackerStatus;
};
