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

module.exports = (sequelize) => {
  const ProcurementTrackerPackingList = sequelize.define(
    "procurementtrackerpackinglist",
    {
      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 },
      packinglist_number: { type: DataTypes.STRING(250), allowNull: true },
      packinglist_date: { type: DataTypes.DATE, allowNull: true },
    },
    {
      tableName: "procurementtrackerpackinglists",
      freezeTableName: true,
    }
  );

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

  return ProcurementTrackerPackingList;
};
